Author: jmorliaguet
Date: Sat Feb  4 14:11:08 2006
New Revision: 2283

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
Log:

- moved read / write / merge to the storage



Modified: cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js (original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js Sat Feb  4 
14:11:08 2006
@@ -626,7 +626,7 @@
   // high-level I/O
   getData: function() {
     this.storage.requestData(); /* asynchronous call */
-    return this.read();
+    return this.storage.read();
   },
 
   setData: function(data) {
@@ -640,31 +640,6 @@
     this.setData(new_data);
   },
 
-  // low-level I/O
-  read: function() {
-    return this.def.data;
-  },
-
-  write: function(data) {
-    // filter out fields with the wrong data type
-    var schema = this.schema;
-    var filtered_data = new Object();
-    this.schema.each(function(f) {
-      var field = f[0];
-      var value = data[field];
-      if (value != null && typeof value == f[1]) {
-        filtered_data[field] = value;
-      }
-    });
-    this.def.data = filtered_data;
-  },
-
-  merge: function(data) {
-    var current_data = this.read();
-    var new_data = $H(current_data).merge(data);
-    this.write(new_data);
-  },
-
   addObserver: function(view) {
     var model = this;
     // observers subscribes to events on the model
@@ -733,7 +708,32 @@
 
   storeData: function(data) {
     /* to be overriden */
-  }
+  },
+
+  // low-level I/O
+  read: function() {
+    return this.model.def.data;
+  },
+
+  write: function(data) {
+    // filter out fields with the wrong data type
+    var schema = this.model.schema;
+    var filtered_data = new Object();
+    schema.each(function(f) {
+      var field = f[0];
+      var value = data[field];
+      if (value != null && typeof value == f[1]) {
+        filtered_data[field] = value;
+      }
+    });
+    this.model.def.data = filtered_data;
+  },
+
+  merge: function(data) {
+    var current_data = this.read();
+    var new_data = $H(current_data).merge(data);
+    this.write(new_data);
+  },
 
 }
 
@@ -770,9 +770,12 @@
     });
     this.models = models;
 
-    // TODO: add a handler that will data from the different storages.
-    //  var data = m.read();
-    //  model.merge(data);
+    CPSSkins.registerEventHandler('stored', storage, function(event) {
+      var target = event.target;
+      var subscriber = event.subscriber;
+      var model = subscriber.model;
+      storage.merge(target.model.def.data);
+    });
 
   },
 
@@ -797,11 +800,12 @@
 
   requestData: function() {
     /* nothing to do since the data is already there */
+    CPSSkins.notify('stored', this);
   },
 
   storeData: function(data) {
     /* Store the data directly */
-    this.model.write(data);
+    this.write(data);
     CPSSkins.notify('stored', this);
   }
 
@@ -819,7 +823,7 @@
     new Ajax.Request(url, {
       onComplete: function(req) {
         var data = JSON.parse(req.responseText);
-        model.write(data);
+        this.write(data);
         CPSSkins.notify('stored', storage);
       }
     });
@@ -827,7 +831,6 @@
 
   storeData: function(data) {
     var model = this.model;
-    model.def.data = data;
     var storage = this;
 
     var url = model.def.storage.accessors.set;
@@ -838,7 +841,7 @@
         }).toQueryString(),
       onComplete: function(req) {
         var data = JSON.parse(req.responseText);
-        model.write(data);
+        this.write(data);
         CPSSkins.notify('stored', storage);
       }
     });
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to