You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/06/12 09:52:03 UTC
git commit: updated refs/heads/1828-duplicate-doc to be85e3e
Updated Branches:
refs/heads/1828-duplicate-doc [created] be85e3e67
Fauxton Duplicate Document
Able to duplicate a document as a starting point for a new document
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/be85e3e6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/be85e3e6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/be85e3e6
Branch: refs/heads/1828-duplicate-doc
Commit: be85e3e67260f736488ca21874251647fb1184e2
Parents: 785a342
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Jun 11 16:39:35 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Jun 12 09:51:33 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/modules/documents/resources.js | 5 ++-
src/fauxton/app/modules/documents/routes.js | 31 +++++++++++++++-
src/fauxton/app/modules/documents/views.js | 41 ++++++++++++++++-----
3 files changed, 65 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/be85e3e6/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index 8fc384e..8f66755 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -67,6 +67,10 @@ function(app, FauxtonAPI) {
return views && _.keys(views).length > 0;
},
+ hasAttachments: function () {
+ return !!this.get('_attachments');
+ },
+
getDdocView: function(view) {
if (!this.isDdoc() || !this.hasViews()) return false;
@@ -109,7 +113,6 @@ function(app, FauxtonAPI) {
var doc = this.get('doc');
if (doc) {
- console.log('DOC', doc);
return new Documents.Doc(doc, {database: this.database});
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/be85e3e6/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index a49fa91..5c039c3 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -52,7 +52,8 @@ function(app, FauxtonAPI, Documents, Databases) {
},
events: {
- "route:reRenderDoc": "reRenderDoc"
+ "route:reRenderDoc": "reRenderDoc",
+ "route:duplicateDoc": "duplicateDoc"
},
crumbs: function() {
@@ -73,7 +74,6 @@ function(app, FauxtonAPI, Documents, Databases) {
reRenderDoc: function () {
this.docView.forceRender();
- console.log('rerender');
},
field_editor: function(events) {
@@ -83,6 +83,33 @@ function(app, FauxtonAPI, Documents, Databases) {
}));
},
+ duplicateDoc: function () {
+ var currentDoc = this.docView.getDocFromEditor();
+
+ if (!currentDoc) {
+ return FauxtonAPI.addNotification({
+ msg: "Please fix the JSON errors and try again.",
+ type: "error",
+ selector: "#doc .errors-container"
+ });
+ }
+
+ var duplicateAttrs = currentDoc.toJSON();
+
+ delete duplicateAttrs._id;
+ delete duplicateAttrs._rev;
+
+ var database = this.database;
+ doc = this.doc = new Documents.NewDoc(duplicateAttrs, {database: this.database});
+
+ doc.fetch().then(function () {
+ doc.save().then(function () {
+ FauxtonAPI.navigate('/database/' + database.id + '/' + doc.id, {trigger: true});
+ });
+ });
+
+ },
+
apiUrl: function() {
return this.doc.url();
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/be85e3e6/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 59e3b7d..dcdfd9a 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -260,10 +260,18 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
},
duplicate: function(event) {
- FauxtonAPI.addNotification({
- type: "warning",
- msg: "Duplicate functionality coming soon."
- });
+ event.preventDefault();
+
+ if (this.model.hasAttachments()) {
+ FauxtonAPI.addNotification({
+ type: "error",
+ msg: "Cannot duplicate a document with attachments."
+ });
+
+ return;
+ }
+
+ FauxtonAPI.triggerRouteEvent('duplicateDoc');
},
updateSelected: function (selected) {
@@ -507,12 +515,15 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
},
saveDoc: function(event) {
- var json, notification, that = this;
- if (this.hasValidCode()) {
- json = JSON.parse(this.editor.getValue());
- this.model.clear({silent:true});
- this.model.set(json);
+ var json, notification,
+ that = this,
+ validDoc = this.getDocFromEditor();
+
+ if (validDoc) {
+ this.getDocFromEditor();
+
notification = FauxtonAPI.addNotification({msg: "Saving document."});
+
this.model.save().then(function () {
FauxtonAPI.navigate('/database/' + that.database.id + '/' + that.model.id);
}).fail(function(xhr) {
@@ -532,6 +543,18 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
}
},
+ getDocFromEditor: function () {
+ if (!this.hasValidCode()) {
+ return false;
+ }
+
+ json = JSON.parse(this.editor.getValue());
+ this.model.clear({silent:true});
+ this.model.set(json);
+
+ return this.model;
+ },
+
hasValidCode: function() {
return JSHINT(this.editor.getValue()) !== false;
},