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/07/01 18:03:50 UTC
git commit: updated refs/heads/1828-duplicate-doc to d819094
Updated Branches:
refs/heads/1828-duplicate-doc be85e3e67 -> d819094f9
Fauxton: Duplicate document
Duplicates the current document using Couchdb's COPY api.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/d819094f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/d819094f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/d819094f
Branch: refs/heads/1828-duplicate-doc
Commit: d819094f9f787c9bffe7b2a6f3a138ff163e8931
Parents: be85e3e
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Jul 1 18:02:43 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Jul 1 18:02:43 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/modules/documents/resources.js | 8 +++++++
src/fauxton/app/modules/documents/routes.js | 23 +++++++++------------
src/fauxton/app/modules/documents/views.js | 10 ---------
3 files changed, 18 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/d819094f/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 8f66755..bece386 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -164,6 +164,14 @@ function(app, FauxtonAPI) {
var data = this.get("doc") ? this.get("doc") : this;
return JSON.stringify(data, null, " ");
+ },
+
+ copy: function (copyId) {
+ return $.ajax({
+ type: 'COPY',
+ url: '/' + this.database.id + '/' + this.id,
+ headers: {Destination: copyId}
+ });
}
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/d819094f/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 5c039c3..f85b8b5 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -84,7 +84,10 @@ function(app, FauxtonAPI, Documents, Databases) {
},
duplicateDoc: function () {
- var currentDoc = this.docView.getDocFromEditor();
+ var currentDoc = this.docView.getDocFromEditor(),
+ uuid = new FauxtonAPI.UUID(),
+ docView = this.docView,
+ database = this.database;
if (!currentDoc) {
return FauxtonAPI.addNotification({
@@ -94,20 +97,14 @@ function(app, FauxtonAPI, Documents, Databases) {
});
}
- 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});
+ uuid.fetch().then(function() {
+ var docId = uuid.next();
+ currentDoc.copy(docId).then(function () {
+ currentDoc.set({_id: docId});
+ docView.forceRender();
+ FauxtonAPI.navigate('/database/' + database.id + '/' + docId, {trigger: true});
});
});
-
},
apiUrl: function() {
http://git-wip-us.apache.org/repos/asf/couchdb/blob/d819094f/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 dcdfd9a..c0480dd 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -261,16 +261,6 @@ function(app, FauxtonAPI, Documents, pouchdb, Codemirror, JSHint) {
duplicate: function(event) {
event.preventDefault();
-
- if (this.model.hasAttachments()) {
- FauxtonAPI.addNotification({
- type: "error",
- msg: "Cannot duplicate a document with attachments."
- });
-
- return;
- }
-
FauxtonAPI.triggerRouteEvent('duplicateDoc');
},