Marco Mariani avatar Marco Mariani committed b2be5f0

loadDocument()

Comments (0)

Files changed (1)

OfficeJS/src/jio.mongostorage.js

 
 
         that.loadDocument = function (command) {
-            // Returns a document object containing all information of the
-            // document and its content.
-            debugger;
+            // XXX reads all the documents. slow and stupid
+            // TODO: query specified document by criteria
+
+            console.debug('Loading document...');
+            do_connect(function(command) {
+                $.ajax({
+                    url: priv.url_find,
+                    type: 'GET',
+                    async: true
+                }).done(function(msg, textStatus, jqXHR) {
+                    var results = msg.results,
+                        i, doc;
+
+                    for (i=0; i<results.length; i++) {
+                        var res = results[i];
+                        if (res.name === command.getPath()) {
+                            doc = {
+                                name: res.name,
+                                content: res.content,
+                                creation_date: new Date(res.creation_date),
+                                last_modified: new Date(res.creation_date)
+                            };
+                            that.success(doc);
+                        }
+                    }
+                }).fail(function(type) {
+                    console.debug('could not load document!');
+                    // XXX check if message is displayed?
+                    type.message = 'Cannot connect to db';
+                    that.retry(type);
+                });
+            }, this, [command]);
 
-            setTimeout(function () {
-                var doc = {
-                    'name': 'file',
-                    'content': 'content',
-                    'creation_date': 10000,
-                    'last_modified': 15000};
-                that.success (doc);
-            }, 100);
         }; // end loadDocument
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.