From 90ee8c2e6c88ad6aa94e8e6f651d562c6d5a14bc Mon Sep 17 00:00:00 2001
From: Tristan Cavelier <tristan.cavelier@tiolive.com>
Date: Mon, 24 Dec 2012 14:56:54 +0100
Subject: [PATCH] localstorage.js get method redesigned

---
 src/jio.storage/localstorage.js | 44 ++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/src/jio.storage/localstorage.js b/src/jio.storage/localstorage.js
index f0acc3d..498b7b5 100644
--- a/src/jio.storage/localstorage.js
+++ b/src/jio.storage/localstorage.js
@@ -176,19 +176,45 @@ var newLocalStorage = function (spec, my) {
 
     /**
      * Get a document or attachment
-     * @method  get
+     * @method get
      * @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._get = function (command) {
+    that.get = function (command) {
         setTimeout (function () {
-            that.success( priv.getDocument(command) );
+            var doc;
+            if (typeof command.getAttachmentId() === "string") {
+                // seeking for an attachment
+                doc = localstorage.getItem(
+                    priv.localpath + "/" + command.getDocId() + "/" +
+                        command.getAttachmentId());
+                if (typeof doc !== "undefined") {
+                    that.success(doc);
+                } else {
+                    that.error({
+                        "status": 404,
+                        "statusText": "Not Found",
+                        "error": "not_found",
+                        "message": "Cannot find the attachment ",
+                        "reason": "attachment does not exists"
+                    });
+                }
+            } else {
+                // seeking for a document
+                doc = localstorage.getItem(
+                    priv.localpath + "/" + command.getDocId());
+                if (typeof doc !== "undefined") {
+                    that.success(doc);
+                } else {
+                    that.error({
+                        "status": 404,
+                        "statusText": "Not Found",
+                        "error": "not_found",
+                        "message": "Cannot find the document",
+                        "reason": "Document does not exists"
+                    });
+                }
+            }
         });
-
     };
 
     /**
-- 
2.30.9