couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasondav...@apache.org
Subject svn commit: r820603 - /couchdb/trunk/share/www/script/jquery.couch.js
Date Thu, 01 Oct 2009 10:56:15 GMT
Author: jasondavies
Date: Thu Oct  1 10:56:15 2009
New Revision: 820603

URL: http://svn.apache.org/viewvc?rev=820603&view=rev
Log:
Add support for COPY (copyDoc) to jquery.couch.js.

Modified:
    couchdb/trunk/share/www/script/jquery.couch.js

Modified: couchdb/trunk/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.couch.js?rev=820603&r1=820602&r2=820603&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/jquery.couch.js [utf-8] Thu Oct  1 10:56:15 2009
@@ -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