diff options
author | Jason David Davies <jasondavies@apache.org> | 2009-10-01 10:56:15 +0000 |
---|---|---|
committer | Jason David Davies <jasondavies@apache.org> | 2009-10-01 10:56:15 +0000 |
commit | c2d8ffd2069ac35beb0ecf0938f277bffeb0f193 (patch) | |
tree | 6d403f5110bbf63b8f21289d5d07b1240a9fa8c9 | |
parent | 6521c6ba57db9cd5c6ddb8fd1641b8c936008cb8 (diff) |
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
-rw-r--r-- | share/www/script/jquery.couch.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index 8c5848bc..ab1a7a00 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/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. |