summaryrefslogtreecommitdiff
path: root/share/www/script/jquery.couch.js
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2010-06-02 17:45:56 +0000
committerJan Lehnardt <jan@apache.org>2010-06-02 17:45:56 +0000
commitbaf25cefa01d305a47087686becef7de7147321a (patch)
tree4325283b8e57064be26daf421d8ded8930b36c9c /share/www/script/jquery.couch.js
parent7fe84eba9982ebb3bcaa48b7aa28fdd2e130422d (diff)
Add tests for couch.js and jquery.couch.js
Patch by Lena Herrmann. Closes COUCHDB-783. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@950689 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script/jquery.couch.js')
-rw-r--r--share/www/script/jquery.couch.js50
1 files changed, 36 insertions, 14 deletions
diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js
index 4923dafe..cf29525c 100644
--- a/share/www/script/jquery.couch.js
+++ b/share/www/script/jquery.couch.js
@@ -1,4 +1,4 @@
-// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+a// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
@@ -276,7 +276,7 @@
}
});
} else {
- alert("please provide an eachApp function for allApps()");
+ alert("Please provide an eachApp function for allApps()");
}
},
openDoc: function(docId, options, ajaxOptions) {
@@ -327,7 +327,7 @@
beforeSend : beforeSend,
complete: function(req) {
var resp = $.httpData(req, "json");
- if (req.status == 201) {
+ if (req.status == 201 || req.status == 202) {
doc._id = resp.id;
doc._rev = resp.rev;
if (versioned) {
@@ -372,13 +372,27 @@
"The document could not be deleted"
);
},
- copyDoc: function(doc, options, ajaxOptions) {
+ bulkRemove: function(docs, options){
+ docs.docs = $.each(
+ docs.docs, function(i, doc){
+ doc._deleted = true;
+ }
+ );
+ $.extend(options, {successStatus: 201});
+ ajax({
+ type: "POST",
+ url: this.uri + "_bulk_docs" + encodeOptions(options),
+ data: toJSON(docs)
+ },
+ options,
+ "The documents could not be deleted"
+ );
+ },
+ copyDoc: function(docId, 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);
@@ -389,9 +403,7 @@
});
ajax({
type: "COPY",
- url: this.uri +
- encodeDocId(doc._id) +
- encodeOptions({rev: doc._rev})
+ url: this.uri + encodeDocId(docId)
},
options,
"The document could not be copied",
@@ -490,13 +502,14 @@
);
},
- replicate: function(source, target, options) {
+ replicate: function(source, target, ajaxOptions, replicationOptions) {
+ replicationOptions = $.extend({source: source, target: target}, replicationOptions);
ajax({
type: "POST", url: this.urlPrefix + "/_replicate",
- data: JSON.stringify({source: source, target: target}),
+ data: JSON.stringify(replicationOptions),
contentType: "application/json"
},
- options,
+ ajaxOptions,
"Replication failed"
);
},
@@ -516,7 +529,6 @@
}
return uuidCache.shift();
}
-
});
function ajax(obj, options, errorMessage, ajaxOptions) {
@@ -525,8 +537,18 @@
$.ajax($.extend($.extend({
type: "GET", dataType: "json",
+ beforeSend: function(xhr){
+ if(ajaxOptions && ajaxOptions.headers){
+ for (var header in ajaxOptions.headers){
+ xhr.setRequestHeader(header, ajaxOptions.headers[header]);
+ }
+ }
+ },
complete: function(req) {
var resp = $.httpData(req, "json");
+ if (options.ajaxStart) {
+ options.ajaxStart(resp);
+ }
if (req.status == options.successStatus) {
if (options.beforeSuccess) options.beforeSuccess(req, resp);
if (options.success) options.success(resp);
@@ -556,7 +578,7 @@
var buf = [];
if (typeof(options) === "object" && options !== null) {
for (var name in options) {
- if ($.inArray(name, ["error", "success"]) >= 0)
+ if ($.inArray(name, ["error", "success", "ajaxStart"]) >= 0)
continue;
var value = options[name];
if ($.inArray(name, ["key", "startkey", "endkey"]) >= 0) {