Author: jmorliaguet
Date: Sat Jan 28 23:12:54 2006
New Revision: 2230

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
Log:

- test / bug fixes



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 Jan 28 
23:12:54 2006
@@ -222,11 +222,20 @@
 
   isIdentifiable: function(node) {
     node = $(node);
-    if (node.nodeType == 1 && node.getAttribute("id")) {
-      return true;
-    } else {
+
+    if (node.nodeType != 1) {
       return false;
     }
+
+    if (node.tagName.toLowerCase() == "ins") {
+      return false;
+    }
+
+    if (node.getAttribute("id")) {
+      return true;
+    }
+
+    return false;
   },
 
   getOrder: function(node) {
@@ -293,6 +302,7 @@
 Object.extend(Canvas, {
 
   getModel: function(node) {
+    if (!node) return;
     var model_node = this.getModelNode(node);
     if (model_node) {
       var id = model_node.getAttribute("id");
@@ -302,11 +312,8 @@
   },
 
   getModelNode: function(node) {
-    node = $(node);
     while(node = node.previousSibling) {
       if (node.nodeType == 1) {
-        if (node && node.tagName.toLowerCase() == "ins") {
-        }
         if (node && node.tagName.toLowerCase() == "ins"
                  && Element.hasClassName(node, "model")) {
           return node;
@@ -529,7 +536,7 @@
 
   updateData: function(data) {
     var current = this.getData() || new Object();
-    Object.extend(current, data);
+    Object.extend(data, current);
     this.setData(data);
   },
 
@@ -716,10 +723,10 @@
     this.prepare();
 
     if (!this.def.model) {
-      var model_node = Canvas.getModelNode(this.selected);
-      if (!model_node) return;
-      var model = CPSSkins.Models[model_node.getAttribute("id")];
-      this.observe(model);
+      var model = Canvas.getModel(this.selected);
+      if (model) {
+        this.observe(model);
+      }
     }
 
     if (this.effect) {
@@ -824,6 +831,7 @@
     return '[CPSSkins Panel:' + this.url + ']';
   },
 
+  // TODO: use a model instead of return data directly
   getData: function() {
     return this.url;
   },

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html   
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html   
    Sat Jan 28 23:12:54 2006
@@ -200,45 +200,51 @@
       assertEqual(Identifiable.isEmpty(e6), true);
     }},
 
-    testGetModelNode: function() { with(this) {
-      assertEqual(Canvas._getModelNode(e0), null);
-      assertEqual(Canvas._getModelNode(e1), null);
-      assertNotEqual(Canvas._getModelNode(e2), null);
-      assertEqual(Canvas._getModelNode(e3), null);
-      assertEqual(Canvas._getModelNode(e4), null);
-      assertEqual(Canvas._getModelNode(e5), null);
-      assertNotEqual(Canvas._getModelNode(e6), null);
+    testGetModel: function() { with(this) {
+      assertEqual(Canvas.getModel(e0), null);
+      assertEqual(Canvas.getModel(e1), null);
+      assertNotEqual(Canvas.getModel(e2), null);
+      assertEqual(Canvas.getModel(e3), null);
+      assertEqual(Canvas.getModel(e4), null);
+      assertEqual(Canvas.getModel(e5), null);
+      assertNotEqual(Canvas.getModel(e6), null);
     }},
 
-    testGetNodeData: function() { with(this) {
-      // test twice to get the cached data
-      assertEqual(Canvas.getNodeData(e1), null);
-      assertEqual(Canvas.getNodeData(e1), null);
+    testGetData: function() { with(this) {
+      var model_e2 = Canvas.getModel(e2);
+      var model_e6 = Canvas.getModel(e6);
 
-      assertEqual($H(Canvas.getNodeData(e2)).inspect(),
+      assertEqual($H(model_e2.getData()).inspect(),
                   $H({a:"1", b:"2"}).inspect());
-      assertEqual($H(Canvas.getNodeData(e2)).inspect(),
-                  $H({a:"1", b:"2"}).inspect());
-
-      assertEqual(Canvas.getNodeData(e5), null);
-      assertEqual(Canvas.getNodeData(e5), null);
 
-      assertEqual($H(Canvas.getNodeData(e6)).inspect(),
-        $H({"a":["1","2","3"],"b":{"c":1,"d":2},"c":[[1],[2],[3]]}).inspect());
-      assertEqual($H(Canvas.getNodeData(e6)).inspect(),
+      assertEqual($H(model_e6.getData()).inspect(),
         $H({"a":["1","2","3"],"b":{"c":1,"d":2},"c":[[1],[2],[3]]}).inspect());
     }},
 
-    testSetNodeData: function() { with(this) {
-      Canvas.setNodeData(e1, {"new1":true});
-      assertEqual($H(Canvas.getNodeData(e1)).inspect(),
+    testSetData: function() { with(this) {
+      var model_e2 = Canvas.getModel(e2);
+
+      model_e2.setData({"new1":true});
+      assertEqual($H(model_e2.getData()).inspect(),
                   $H({"new1":true}).inspect());
 
-      Canvas.setNodeData(e2, {"new2":true});
-      assertEqual($H(Canvas.getNodeData(e2)).inspect(),
+      model_e2.setData({"new2":true});
+      assertEqual($H(model_e2.getData()).inspect(),
                   $H({"new2":true}).inspect());
     }},
 
+    testUpdateData: function() { with(this) {
+      var model_e2 = Canvas.getModel(e2);
+
+      model_e2.setData({"new1":true});
+      assertEqual($H(model_e2.getData()).inspect(),
+                  $H({"new1":true}).inspect());
+
+      model_e2.updateData({"new2":true});
+      assertEqual($H(model_e2.getData()).inspect(),
+                  $H({"new2":true,"new1":true}).inspect());
+    }},
+
     testSwitchPerspectives: function() { with(this) {
       var p1 = $("p1").parentNode;
       var p1_2 = $("p1_2").parentNode;
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to