Commit f1940cd1 authored by Tristan Cavelier's avatar Tristan Cavelier

localstorage.js post method improved

parent 447c8c4d
...@@ -95,9 +95,19 @@ var newLocalStorage = function (spec, my) { ...@@ -95,9 +95,19 @@ var newLocalStorage = function (spec, my) {
*/ */
that.post = function (command) { that.post = function (command) {
setTimeout (function () { setTimeout (function () {
var doc; var doc = command.getDocId();
if (!(typeof doc === "string" && doc !== "")) {
that.error({
"status": 405,
"statusText": "Method Not Allowed",
"error": "method_not_allowed",
"message": "Cannot create document which id is undefined",
"reason": "Document id is undefined"
});
return;
}
doc = localstorage.getItem( doc = localstorage.getItem(
priv.localpath + "/" + command.getDocId()); priv.localpath + "/" + doc);
if (doc === null) { if (doc === null) {
// the document does not exists // the document does not exists
localstorage.setItem( localstorage.setItem(
...@@ -247,7 +257,8 @@ var newLocalStorage = function (spec, my) { ...@@ -247,7 +257,8 @@ var newLocalStorage = function (spec, my) {
priv.localpath + "/" + command.getDocId() + "/" + priv.localpath + "/" + command.getDocId() + "/" +
command.getAttachmentId()); command.getAttachmentId());
// remove attachment from document // remove attachment from document
if (typeof doc["_attachments"] === "object") { if (doc !== null && typeof doc === "object" &&
typeof doc["_attachments"] === "object") {
delete doc["_attachments"][command.getAttachmentId()]; delete doc["_attachments"][command.getAttachmentId()];
if (priv.objectIsEmpty(doc["_attachments"])) { if (priv.objectIsEmpty(doc["_attachments"])) {
delete doc["_attachments"]; delete doc["_attachments"];
...@@ -263,7 +274,8 @@ var newLocalStorage = function (spec, my) { ...@@ -263,7 +274,8 @@ var newLocalStorage = function (spec, my) {
} else { } else {
// seeking for a document // seeking for a document
var attachment_list = [], i; var attachment_list = [], i;
if (typeof doc["_attachments"] === "object") { if (doc !== null && typeof doc === "object" &&
typeof doc["_attachments"] === "object") {
// prepare list of attachments // prepare list of attachments
for (i in doc["_attachments"]) { for (i in doc["_attachments"]) {
attachment_list.push(i); attachment_list.push(i);
......
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