Commit 0747228c authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js put method redesigned

parent 881a6994
...@@ -105,27 +105,26 @@ var newLocalStorage = function (spec, my) { ...@@ -105,27 +105,26 @@ var newLocalStorage = function (spec, my) {
/** /**
* Create or update a document in local storage. * Create or update a document in local storage.
* @method _put * @method put
* @param {object} command The JIO command * @param {object} command The JIO command
*
* Available options:
* - {boolean} conflicts Add a conflicts object to the response
* - {boolean} revs Add the revisions history of the document
* - {boolean} revs_info Add revisions informations
*
*/ */
that._put = function (command) { that.put = function (command) {
setTimeout(function () { setTimeout(function () {
var docid = command.getDocId(), var doc;
path = 'jio/local/'+priv.username+'/'+ doc = localstorage.getItem(
priv.applicationname+'/'+docid, priv.localpath + "/" + command.getDocId());
doc = localstorage.getItem(path); if (typeof doc === "undefined") {
// the document does not exists
if (!doc) { doc = command.cloneDoc();
that.success(priv.setDocument(command, 'post'));
} else { } else {
that.success(priv.documentUpdate(command, 'put')); // the document already exists
priv.documentObjectUpdate(doc, command.getDocId());
} }
// write
localstorage.setItem(
priv.localpath + "/" + command.getDocId(),
doc);
that.success({"ok":true,"id":command.getDocId()});
}); });
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment