Author: jmorliaguet
Date: Mon Jan 16 01:49:11 2006
New Revision: 2224

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

- added a real CPSSkins.Model class to access the model



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 Mon Jan 16 
01:49:11 2006
@@ -19,6 +19,8 @@
 var CPSSkins = {
   Version: "0.4",
 
+  Models: $H({}),
+
   Controllers: $H({}),
 
   Observers: $H({}),
@@ -102,9 +104,9 @@
               CPSSkins.Perspectives[p].push(view);
             });
 
-            var model = def.model;
-            if (model) {
-              CPSSkins.addObserver(model, view)
+            var model_id = def.model;
+            if (model_id) {
+              CPSSkins.addObserver(new CPSSkins.Model(model_id), view)
             }
           }
           break;
@@ -114,7 +116,6 @@
   },
 
   addObserver: function(model, view) {
-    model = $(model);
     if (!(model in CPSSkins.Observers)) {
       CPSSkins.Observers[model] = $A([]);
     }
@@ -357,7 +358,8 @@
 
     // Update the views and controllers that are registered as observers
     // TODO: use notify() instead
-    var observers = CPSSkins.Observers[node];
+    var model = CPSSkins.Models[node];
+    var observers = CPSSkins.Observers[model];
     if (observers) {
       observers.each(function(o) {
         o.update();
@@ -549,6 +551,23 @@
 
 }
 
+// Model
+
+CPSSkins.Model = Class.create();
+CPSSkins.Model.prototype = {
+
+  initialize: function(node) {
+    this.node = $(node);
+    CPSSkins.Models[this.node] = this;
+  },
+
+  getData: function() {
+    return Canvas.getNodeData(this.node);
+  }
+
+}
+
+
 // View
 
 CPSSkins.View = function() {};
@@ -565,9 +584,9 @@
       this.controller = null;
     }
 
-    var model = def.model;
-    if (model) {
-      this.model = $(model);
+    var model_id = def.model;
+    if (model_id) {
+      this.model = new CPSSkins.Model(model_id);
     } else {
       this.model = null;
     }
@@ -612,7 +631,7 @@
 
   getData: function() {
     if (this.model) {
-      return Canvas.getNodeData(this.model);
+      return this.model.getData();
     }
     return null;
   },
@@ -627,7 +646,8 @@
     this.prepare();
 
     if (!this.def.model) {
-      CPSSkins.addObserver(this.selected, this);
+      var model = new CPSSkins.Model(this.selected);
+      CPSSkins.addObserver(model, this);
     }
 
     if (this.effect) {
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to