From b71f475d9d42ca2b8a30465cee615d633ce47d55 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sat, 15 May 2010 05:08:25 +0000 Subject: jquery.couch.js option to force ensure_full_commit to true or false git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@944570 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/jquery.couch.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'share') diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index 71560181..5a9541ba 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/jquery.couch.js @@ -258,6 +258,7 @@ ); }, saveDoc: function(doc, options) { + var beforeSend = fullCommit(options); options = options || {}; if (doc._id === undefined) { var method = "POST"; @@ -270,6 +271,7 @@ type: method, url: uri + encodeOptions(options), contentType: "application/json", dataType: "json", data: toJSON(doc), + beforeSend : beforeSend, complete: function(req) { var resp = $.httpData(req, "json"); if (req.status == 201) { @@ -285,7 +287,8 @@ }); }, bulkSave: function(docs, options) { - $.extend(options, {successStatus: 201}); + var beforeSend = fullCommit(options); + $.extend(options, {successStatus: 201, beforeSend : beforeSend}); ajax({ type: "POST", url: this.uri + "_bulk_docs" + encodeOptions(options), @@ -472,6 +475,16 @@ }, obj), ajaxOptions)); } + function fullCommit(options) { + if (typeof options.ensure_full_commit !== "undefined") { + var commit = options.ensure_full_commit; + delete options.ensure_full_commit; + return function(xhr) { + xhr.setRequestHeader("X-Couch-Full-Commit", commit.toString()); + }; + } + }; + // Convert a options object to an url query string. // ex: {key:'value',key2:'value2'} becomes '?key="value"&key2="value2"' function encodeOptions(options) { -- cgit v1.2.3