couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [02/50] jquery-couch commit: updated refs/heads/import-master to 66dbcbf
Date Tue, 01 Apr 2014 08:52:07 GMT
Add support for COPY (copyDoc) to jquery.couch.js.

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@820603 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/commit/4902e38b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/tree/4902e38b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/diff/4902e38b

Branch: refs/heads/import-master
Commit: 4902e38b9c54ea3ebf5e594ea667b16778a997a0
Parents: ec1fff9
Author: Jason David Davies <jasondavies@apache.org>
Authored: Thu Oct 1 10:56:15 2009 +0000
Committer: Alexander Shorin <kxepal@gmail.com>
Committed: Thu Oct 1 10:56:15 2009 +0000

----------------------------------------------------------------------
 jquery.couch.js | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/blob/4902e38b/jquery.couch.js
----------------------------------------------------------------------
diff --git a/jquery.couch.js b/jquery.couch.js
index 5d189b2..e106b17 100644
--- a/jquery.couch.js
+++ b/jquery.couch.js
@@ -187,7 +187,7 @@
             var uri = this.uri;
           } else {
             var method = "PUT";
-            var uri = this.uri  + encodeDocId(doc._id);
+            var uri = this.uri + encodeDocId(doc._id);
           }
           $.ajax({
             type: method, url: uri + encodeOptions(options),
@@ -228,6 +228,32 @@
             "The document could not be deleted"
           );
         },
+        copyDoc: function(doc, options, ajaxOptions) {
+          ajaxOptions = $.extend(ajaxOptions, {
+            complete: function(req) {
+              var resp = $.httpData(req, "json");
+              if (req.status == 201) {
+                doc._id = resp.id;
+                doc._rev = resp.rev;
+                if (options.success) options.success(resp);
+              } else if (options.error) {
+                options.error(req.status, resp.error, resp.reason);
+              } else {
+                alert("The document could not be copied: " + resp.reason);
+              }
+            }
+          });
+          ajax({
+              type: "COPY",
+              url: this.uri +
+                   encodeDocId(doc._id) +
+                   encodeOptions({rev: doc._rev})
+            },
+            options,
+            "The document could not be copied",
+            ajaxOptions
+          );
+        },
         query: function(mapFun, reduceFun, language, options) {
           language = language || "javascript";
           if (typeof(mapFun) !== "string") {
@@ -315,7 +341,7 @@
     options = $.extend({successStatus: 200}, options);
     errorMessage = errorMessage || "Unknown error";
 
-    $.ajax($.extend({
+    $.ajax($.extend($.extend({
       type: "GET", dataType: "json",
       complete: function(req) {
         var resp = $.httpData(req, "json");
@@ -327,7 +353,7 @@
           alert(errorMessage + ": " + resp.reason);
         }
       }
-    }, obj), ajaxOptions);
+    }, obj), ajaxOptions));
   }
 
   // Convert a options object to an url query string.


Mime
View raw message