[the-board/tracker: 10/14] [model] Initial work on porting PageModel to Tracker



commit 8a75bd5e24f8fe99ce808e57f67e7b45f207af79
Author: Lucas Rocha <lucasr lucasr org>
Date:   Wed May 11 23:03:20 2011 +0100

    [model] Initial work on porting PageModel to Tracker

 src/js/model/pageModel.js |   46 ++++++++++++++++++++------------------------
 1 files changed, 21 insertions(+), 25 deletions(-)
---
diff --git a/src/js/model/pageModel.js b/src/js/model/pageModel.js
index 14b473b..23a39f0 100644
--- a/src/js/model/pageModel.js
+++ b/src/js/model/pageModel.js
@@ -70,41 +70,26 @@ PageModel.prototype = {
         this._setDirty(true);
     },
 
-    _loadContentFromPath : function() {
+    _loadContentFromTracker : function() {
         if (this._state == State.LOADING) {
             return;
         }
 
         this._setState(State.LOADING);
 
-        let file = GIO.file_new_for_path(this._path);
-
         this._contentLoadingCancellable = new GIO.Cancellable();
 
-        log('PageModel: file.load_contents_async()');
-        file.load_contents_async(this._contentLoadingCancellable,
-                                 Lang.bind(this, this._onLoadContentsAsync),
-                                 null);
+        // Load content from Tracker asynchronously here
     },
 
-    _saveContentToPath : function(onResult) {
+    _saveContentToTracker : function(onResult) {
         if (this._state != State.LOADED) {
             return;
         }
 
-        let file = GIO.file_new_for_path(this._path);
-        let contentStr = JSON.JSON.stringify(this._content, null, 4);
-        let contentBytes = ByteArray.fromString(contentStr);
-
         this._contentSavingCancellable = new GIO.Cancellable();
 
-        log('PageModel: file.replace_contents_async()');
-        TheBoard.g_file_replace_contents_async(file,
-                                               contentBytes,
-                                               this._contentSavingCancellable,
-                                               Lang.bind(this,
-                                                         this._onReplaceContentsAsync,
-                                                         onResult));
+        // Save content to Tracker asynchronously here
     },
 
     _onLoadContentsAsync : function(file, result, data) {
@@ -190,6 +175,15 @@ PageModel.prototype = {
         this.emit("dirty-changed");
     },
 
+    _findThingById : function(id) {
+        let filterById = function(thing) {
+            return (id == thing.id);
+        };
+
+        let found = this._content.things.filter(filterById);
+        return found || null;
+    },
+
     setBackground : function(background) {
         if (this._content.background == background) {
             return;
@@ -206,16 +200,18 @@ PageModel.prototype = {
         return this._content.things.indexOf(thing);
     },
 
-    removeThing : function(index) {
-        if (!(index in this._content.things)) {
+    removeThing : function(id) {
+
+        if (found.length > 0) {
+            let index = this._content.things.indexOf(found[0]);
+            this._content.things.splice(index, 1);
+            this._setDirty(true);
+        } else {
             throw new Error("Removing undefined thing in PageModel");
         }
-
-        this._content.things.splice(index, 1);
-        this._setDirty(true);
     },
 
-    updateThing : function(index, thing) {
+    updateThing : function(thing) {
         if (!(index in this._content.things)) {
             throw new Error("Updating undefined thing in PageModel");
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]