You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by dc...@apache.org on 2014/08/14 01:26:04 UTC
[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 <ga...@gmail.com>
Authored: Wed May 28 15:09:23 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
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 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<div id="doc">
+ <div class="errors-container"></div>
+
+<div class="nav">
+ <div class="span3">
+ <button class="save-doc btn btn-success save" type="button"><i class="icon fonticon-circle-check"></i> Save</button>
+ <button class="btn cancel-button">Back to _all_docs</button>
+ </div>
+
+ <div class="span7">
+ <% if (attachments) { %>
+ <div class="btn-group">
+ <button class="dropdown-toggle btn" data-bypass="true" data-toggle="dropdown">
+ View Attachments
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu">
+ <%_.each(attachments, function (att) { %>
+ <li>
+ <a href="<%- att.url %>" target="_blank"> <strong> <%- att.fileName %> </strong> -
+ <span> <%- att.contentType %>, <%- formatSize(att.size)%> </span>
+ </a>
+ </li>
+ <% }) %>
+ </ul>
+ </div>
+ <% } %>
+ <button class="btn upload"><i class="icon icon-circle-arrow-up"></i> Upload Attachment</button>
+ <button class="btn duplicate"><i class="icon icon-repeat"></i> Clone document</button>
+ </div>
+
+ <button class="btn btn-danger delete"><i class="icon icon-trash"></i></button>
+ </ul>
+
+<div id="upload-modal"> </div>
+<div id="duplicate-modal"> </div>
+</div>
+
+ <div id="editor-container" class="doc-code"><%- JSON.stringify(doc.attributes, null, " ") %></div>
+
+</div>
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 @@
-<!--
-Licensed under the Apache License, Version 2.0 (the "License"); you may not
-use this file except in compliance with the License. You may obtain a copy of
-the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-License for the specific language governing permissions and limitations under
-the License.
--->
-
-<div id="doc">
- <div class="errors-container"></div>
-
-<div class="nav">
- <div class="span3">
- <button class="save-doc btn btn-success save" type="button"><i class="icon fonticon-circle-check"></i> Save</button>
- <button class="btn cancel-button">Back to _all_docs</button>
- </div>
-
- <div class="span7">
- <% if (attachments) { %>
- <div class="btn-group">
- <button class="dropdown-toggle btn" data-bypass="true" data-toggle="dropdown">
- View Attachments
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu">
- <%_.each(attachments, function (att) { %>
- <li>
- <a href="<%- att.url %>" target="_blank"> <strong> <%- att.fileName %> </strong> -
- <span> <%- att.contentType %>, <%- formatSize(att.size)%> </span>
- </a>
- </li>
- <% }) %>
- </ul>
- </div>
- <% } %>
- <button class="btn upload"><i class="icon icon-circle-arrow-up"></i> Upload Attachment</button>
- <button class="btn duplicate"><i class="icon icon-repeat"></i> Clone document</button>
- </div>
-
- <button class="btn btn-danger delete"><i class="icon icon-trash"></i></button>
- </ul>
-
-<div id="upload-modal"> </div>
-<div id="duplicate-modal"> </div>
-</div>
-
- <div id="editor-container" class="doc-code"><%- JSON.stringify(doc.attributes, null, " ") %></div>
-
-</div>
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 @@
-<!--
-Licensed under the Apache License, Version 2.0 (the "License"); you may not
-use this file except in compliance with the License. You may obtain a copy of
-the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-License for the specific language governing permissions and limitations under
-the License.
--->
-
-<div id="doc-field-editor">
- <div class="tools">
-
- <div class="btn-toolbar pull-left">
- <button class="btn btn-small all">✓ All</button>
- <button class="btn btn-small disabled delete"><i class="icon-trash"></i> Delete field</button>
- <button class="btn btn-small new" style="margin-left: 64px"><i class="icon-plus"></i> New field</button>
- </div>
- <div class="btn-toolbar pull-right">
- <button class="btn btn-small cancel cancel-button"><i class="icon fonticon-circle-x"></i> Cancel</button>
- <button class="btn btn-small btn-success save"><i class="icon fonticon-circle-check"></i> Save</button>
- </div>
- </div>
-
- <div class="clearfix"></div>
- <!-- <hr style="margin-top: 0"/> -->
-
- <table class="table table-striped table-condensed">
- <thead>
- <tr>
- <th class="select">
- </th>
- <th>Key</th>
- <th>Value</th>
- </tr>
- </thead>
- <tbody>
- <tr style="display:none">
- <td class="select"><input type="checkbox" /></td>
- <td class="key"><input type="text" class="input-large" value='' /></td>
- <td class="value"><input type="text" class="input-xxlarge" value='' /></td>
- </tr>
- <% _.each(doc, function(value, key) { %>
- <tr>
- <td class="select"><input type="checkbox" /></td>
- <td class="key">
- <input type="text" class="input-large" name="doc[<%= key %>]" value="<%= key %>" />
- </td>
- <td class="value"><input type="text" class="input-xxlarge" value='<%= JSON.stringify(value) %>' /></td>
- </tr>
- <% }); %>
- <tr>
- <th colspan="3">
- Attachments
- </th>
- </tr>
- <%_.each(attachments, function (att) { %>
- <tr>
- <td class="select"><input type="checkbox" /></td>
- <td colspan="2">
- <a href="<%= att.url %>" target="_blank"> <%= att.fileName %> </a>
- <span> <%= att.contentType %>, <%= formatSize(att.size)%> </span>
- </td>
- </tr>
- <% }) %>
- </tbody>
- </table>
- <a class="btn btn-small new" style="margin-left: 64px"><i class="icon-plus"></i> New field</a>
-
-</div>
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 @@
-<!--
-Licensed under the Apache License, Version 2.0 (the "License"); you may not
-use this file except in compliance with the License. You may obtain a copy of
-the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-License for the specific language governing permissions and limitations under
-the License.
--->
-
-<!--<ul class="nav nav-tabs">
- <li id="field_editor" class="<%= isSelectedClass('field_editor') %>"><a href="#<%= doc.url('app') %>/field_editor">Doc fields</a></li>
- <li id="code_editor" class="<%= isSelectedClass('code_editor') %>"><a href="#<%= doc.url('app') %>/code_editor"><i class="icon-pencil"> </i> Code editor</a>
- </li>
-</ul>-->
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",