Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8B551114B1 for ; Wed, 13 Aug 2014 23:25:57 +0000 (UTC) Received: (qmail 57003 invoked by uid 500); 13 Aug 2014 23:25:50 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 56844 invoked by uid 500); 13 Aug 2014 23:25:50 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 56340 invoked by uid 99); 13 Aug 2014 23:25:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Aug 2014 23:25:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A5068928823; Wed, 13 Aug 2014 23:25:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dch@apache.org To: commits@couchdb.apache.org Date: Wed, 13 Aug 2014 23:26:04 -0000 Message-Id: <282b950d44634817a5fef294537ce9d6@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [16/50] couchdb commit: updated refs/heads/1.6.x to eeb31cb Fauxton: Fix Id added to edit doc view When updating a document, after the save a "id" field is incorrectly added. This patch fixes that. Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/75fa89c6 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/75fa89c6 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/75fa89c6 Branch: refs/heads/1.6.x Commit: 75fa89c6fb1a4f996907d4c8a1bab6f90c92ce79 Parents: 31c7ce7 Author: Garren Smith Authored: Wed May 28 15:09:23 2014 +0200 Committer: Garren Smith Committed: Wed May 28 15:16:05 2014 +0200 ---------------------------------------------------------------------- src/Makefile.am | 4 +- src/fauxton/app/addons/documents/resources.js | 6 +- src/fauxton/app/addons/documents/routes.js | 24 +---- .../addons/documents/templates/code_editor.html | 55 ++++++++++ .../app/addons/documents/templates/doc.html | 55 ---------- .../documents/templates/doc_field_editor.html | 74 -------------- .../templates/doc_field_editor_tabs.html | 19 ---- src/fauxton/app/addons/documents/views.js | 101 +++---------------- 8 files changed, 74 insertions(+), 264 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index 240b4e0..dde0810 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -177,9 +177,7 @@ FAUXTON_FILES = \ fauxton/app/addons/documents/templates/ddoc_info.html \ fauxton/app/addons/documents/templates/delete_database_modal.html \ fauxton/app/addons/documents/templates/design_doc_selector.html \ - fauxton/app/addons/documents/templates/doc.html \ - fauxton/app/addons/documents/templates/doc_field_editor.html \ - fauxton/app/addons/documents/templates/doc_field_editor_tabs.html \ + fauxton/app/addons/documents/templates/code_editor.html \ fauxton/app/addons/documents/templates/duplicate_doc_modal.html \ fauxton/app/addons/documents/templates/edit_tools.html \ fauxton/app/addons/documents/templates/index_menu_item.html \ http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/resources.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js index 709d9a9..21ee55f 100644 --- a/src/fauxton/app/addons/documents/resources.js +++ b/src/fauxton/app/addons/documents/resources.js @@ -194,15 +194,19 @@ function(app, FauxtonAPI, PagingCollection) { if (typeof(this.id) === "undefined") { resp._id = resp.id; } + + delete resp.id; } + if (resp.ok) { delete resp.ok; } + return resp; }, prettyJSON: function() { - var data = this.get("doc") ? this.get("doc") : this; + var data = this.get("doc") ? this.get("doc") : this.attributes; return JSON.stringify(data, null, " "); }, http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/routes.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/routes.js b/src/fauxton/app/addons/documents/routes.js index b8b01fb..8f163a7 100644 --- a/src/fauxton/app/addons/documents/routes.js +++ b/src/fauxton/app/addons/documents/routes.js @@ -36,18 +36,9 @@ function(app, FauxtonAPI, Documents, Databases) { }, { database: this.database }); - - this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({ - disableLoader: true, - selected: "code_editor", - model: this.doc - })); - }, routes: { - // We are hiding the field_editor for this first release - // "database/:database/:doc/field_editor": "field_editor", "database/:database/:doc/code_editor": "code_editor", "database/:database/:doc": "code_editor" }, @@ -65,9 +56,8 @@ function(app, FauxtonAPI, Documents, Databases) { }, code_editor: function (database, doc) { - this.tabsView.updateSelected('code_editor'); - this.docView = this.setView("#dashboard-content", new Documents.Views.Doc({ + this.docView = this.setView("#dashboard-content", new Documents.Views.CodeEditor({ model: this.doc, database: this.database })); @@ -77,13 +67,6 @@ function(app, FauxtonAPI, Documents, Databases) { this.docView.forceRender(); }, - field_editor: function(events) { - this.tabsView.updateSelected('field_editor'); - this.docView = this.setView("#dashboard-content", new Documents.Views.DocFieldEditor({ - model: this.doc - })); - }, - duplicateDoc: function (newId) { var doc = this.doc, docView = this.docView, @@ -120,11 +103,6 @@ function(app, FauxtonAPI, Documents, Databases) { database: this.database }); - this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({ - selected: "code_editor", - model: this.doc - })); - }, crumbs: function() { return [ http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/templates/code_editor.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/templates/code_editor.html b/src/fauxton/app/addons/documents/templates/code_editor.html new file mode 100644 index 0000000..e9a46cf --- /dev/null +++ b/src/fauxton/app/addons/documents/templates/code_editor.html @@ -0,0 +1,55 @@ + + +
+
+ + + +
<%- JSON.stringify(doc.attributes, null, " ") %>
+ +
http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/templates/doc.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/templates/doc.html b/src/fauxton/app/addons/documents/templates/doc.html deleted file mode 100644 index e9a46cf..0000000 --- a/src/fauxton/app/addons/documents/templates/doc.html +++ /dev/null @@ -1,55 +0,0 @@ - - -
-
- - - -
<%- JSON.stringify(doc.attributes, null, " ") %>
- -
http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/templates/doc_field_editor.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/templates/doc_field_editor.html b/src/fauxton/app/addons/documents/templates/doc_field_editor.html deleted file mode 100644 index 3ad9484..0000000 --- a/src/fauxton/app/addons/documents/templates/doc_field_editor.html +++ /dev/null @@ -1,74 +0,0 @@ - - -
-
- -
- - - -
-
- - -
-
- -
- - - - - - - - - - - - - - - - - <% _.each(doc, function(value, key) { %> - - - - - - <% }); %> - - - - <%_.each(attachments, function (att) { %> - - - - - <% }) %> - -
- KeyValue
- -
- Attachments -
- <%= att.fileName %> - <%= att.contentType %>, <%= formatSize(att.size)%> -
- New field - -
http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/templates/doc_field_editor_tabs.html ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/templates/doc_field_editor_tabs.html b/src/fauxton/app/addons/documents/templates/doc_field_editor_tabs.html deleted file mode 100644 index 766647c..0000000 --- a/src/fauxton/app/addons/documents/templates/doc_field_editor_tabs.html +++ /dev/null @@ -1,19 +0,0 @@ - - - http://git-wip-us.apache.org/repos/asf/couchdb/blob/75fa89c6/src/fauxton/app/addons/documents/views.js ---------------------------------------------------------------------- diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js index c58241c..87bc7ae 100644 --- a/src/fauxton/app/addons/documents/views.js +++ b/src/fauxton/app/addons/documents/views.js @@ -238,37 +238,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, } }); - Views.FieldEditorTabs = FauxtonAPI.View.extend({ - template: "addons/documents/templates/doc_field_editor_tabs", - disableLoader: true, - initialize: function(options) { - this.selected = options.selected; - }, - - events: { - }, - updateSelected: function (selected) { - this.selected = selected; - this.$('.active').removeClass('active'); - this.$('#'+this.selected).addClass('active'); - }, - - serialize: function() { - var selected = this.selected; - return { - doc: this.model, - isNewDoc: this.model.isNewDoc(), - isSelectedClass: function(item) { - return item && item === selected ? "active" : ""; - } - }; - }, - - establish: function() { - return [this.model.fetch()]; - } - }); - Views.Document = FauxtonAPI.View.extend({ template: "addons/documents/templates/all_docs_item", tagName: "tr", @@ -723,8 +692,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, } }); - Views.Doc = FauxtonAPI.View.extend({ - template: "addons/documents/templates/doc", + Views.CodeEditor = FauxtonAPI.View.extend({ + template: "addons/documents/templates/code_editor", events: { "click button.save-doc": "saveDoc", "click button.delete": "destroy", @@ -732,14 +701,18 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, "click button.upload": "upload", "click button.cancel-button": "goback" }, + disableLoader: true, + initialize: function (options) { this.database = options.database; _.bindAll(this); }, + goback: function(){ FauxtonAPI.navigate(this.database.url("index") + "?limit=100"); }, + destroy: function(event) { if (this.model.isNewDoc()) { FauxtonAPI.addNotification({ @@ -806,9 +779,8 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, }, updateValues: function() { - var notification; if (this.model.changedAttributes()) { - notification = FauxtonAPI.addNotification({ + FauxtonAPI.addNotification({ msg: "Document saved successfully.", type: "success", clear: true @@ -841,7 +813,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, }, saveDoc: function(event) { - var json, notification, + var json, that = this, editor = this.editor, validDoc = this.getDocFromEditor(); @@ -849,15 +821,14 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, if (validDoc) { this.getDocFromEditor(); - notification = FauxtonAPI.addNotification({msg: "Saving document."}); + FauxtonAPI.addNotification({msg: "Saving document."}); this.model.save().then(function () { editor.editSaved(); FauxtonAPI.navigate('/database/' + that.database.safeID() + '/' + that.model.id); }).fail(function(xhr) { - var responseText = JSON.parse(xhr.responseText).reason; - notification = FauxtonAPI.addNotification({ + FauxtonAPI.addNotification({ msg: "Save failed: " + responseText, type: "error", fade: false, @@ -866,7 +837,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, }); }); } else if(this.model.validationError && this.model.validationError === 'Cannot change a documents id.') { - notification = FauxtonAPI.addNotification({ + FauxtonAPI.addNotification({ msg: "Cannot save: " + 'Cannot change a documents _id, try Duplicate doc instead!', type: "error", selector: "#doc .errors-container", @@ -874,7 +845,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, }); delete this.model.validationError; } else { - notification = FauxtonAPI.addNotification({ + FauxtonAPI.addNotification({ msg: "Please fix the JSON errors and try again.", type: "error", selector: "#doc .errors-container", @@ -983,54 +954,6 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, } }); - Views.DocFieldEditor = FauxtonAPI.View.extend({ - template: "addons/documents/templates/doc_field_editor", - disableLoader: true, - events: { - "click button.save": "saveDoc" - }, - - saveDoc: function(event) { - FauxtonAPI.addNotification({ - type: "warning", - msg: "Save functionality coming soon.", - clear: true - }); - }, - - serialize: function() { - return { - doc: this.getModelWithoutAttachments(), - attachments: this.getAttachments() - }; - }, - - getModelWithoutAttachments: function() { - var model = this.model.toJSON(); - delete model._attachments; - return model; - }, - - getAttachments: function () { - var attachments = this.model.get('_attachments'); - - if (!attachments) { return []; } - - return _.map(attachments, function (att, key) { - return { - fileName: key, - size: att.length, - contentType: att.content_type, - url: this.model.url() + '/' + key - }; - }, this); - }, - - establish: function() { - return [this.model.fetch()]; - } - }); - Views.AdvancedOptions = FauxtonAPI.View.extend({ template: "addons/documents/templates/advanced_options", className: "advanced-options well",