Author: jmorliaguet
Date: Thu Mar  2 16:03:36 2006
New Revision: 2510

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

- added a new class (CPSSkins.Set) to manage arrays with unique entries.



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 Thu Mar  2 
16:03:36 2006
@@ -211,7 +211,7 @@
       var def = this._jsonParse(el);
       var id = def.id;
       if (!id) {
-        CPSSkins.warn("Component of type '" + classid + "' has no id: <pre>" 
+        CPSSkins.warn("Component of type '" + classid + "' has no id: <pre>"
                       + el.innerHTML + "</pre>", el);
       }
       // store the component's id on the node
@@ -313,6 +313,39 @@
 
 Event.observe(window, "load", CPSSkins.init);
 
+CPSSkins.Set = Class.create();
+CPSSkins.Set.prototype = {
+
+  initialize: function(x) {
+    this._elements = $H({});
+    $A(x).each(function(e) {
+      this.add(e);
+    }.bind(this));
+  },
+
+  add: function(x) {
+    $A(x).each(function(e) {
+      this._elements[e] = true;
+    }.bind(this));
+  },
+
+  remove: function(x) {
+    $A(x).each(function(e) {
+      delete this._elements[e];
+    }.bind(this));
+  },
+
+  contains: function(x) {
+    return x in this._elements;
+  },
+
+  entries: function() {
+    return this._elements.keys();
+  }
+
+}
+
+
 // Controller
 
 CPSSkins.Controller = Class.create();
@@ -531,7 +564,7 @@
       if (Position.within(d, x, y)) { inTarget = true; }
     });
 
-    if (inTarget) { 
+    if (inTarget) {
       /* TODO: handle action */
     }
   }
@@ -651,7 +684,7 @@
 });
 
 
-if (!CPSSkins.Canvas) { 
+if (!CPSSkins.Canvas) {
   CPSSkins.Canvas = {
     _styles: {},
     _scripts: {}
@@ -919,7 +952,7 @@
   },
 
   writeData: function(data) {
-    this._data = data; 
+    this._data = data;
   },
 
   hasData: function() {

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   
    Thu Mar  2 16:03:36 2006
@@ -241,6 +241,47 @@
     },
 
     /* CPSSkins */
+
+    testSetCreate: function() { with(this) {
+      var s = new CPSSkins.Set(["1", "2", "3"]);
+      assertEqual(inspect(["1", "2", "3"]), inspect(s.entries()));
+    }},
+
+    testSetAdd: function() { with(this) {
+      var s = new CPSSkins.Set(["1", "2"]);
+      s.add("4");
+      assertEqual(inspect(["1", "2", "4"]), inspect(s.entries()));
+      s.add("4");
+      assertEqual(inspect(["1", "2", "4"]), inspect(s.entries()));
+      s.add("1");
+      assertEqual(inspect(["1", "2", "4"]), inspect(s.entries()));
+      s.add(["5", "6"]);
+      assertEqual(inspect(["1", "2", "4", "5", "6"]), inspect(s.entries()));
+    }},
+
+    testSetRemove: function() { with(this) {
+      var s = new CPSSkins.Set(["1", "2", "4", "5"]);
+      s.remove("4");
+      assertEqual(inspect(["1", "2", "5"]), inspect(s.entries()));
+      s.remove("4");
+      assertEqual(inspect(["1", "2", "5"]), inspect(s.entries()));
+      s.remove("2");
+      assertEqual(inspect(["1", "5"]), inspect(s.entries()));
+      s.remove(["5", "6"]);
+      assertEqual(inspect(["1"]), inspect(s.entries()));
+    }},
+
+    testSetContains: function() { with(this) {
+      var s = new CPSSkins.Set(["1", "2", "4", "5"]);
+      assert(s.contains("1"));
+      assert(s.contains("2"));
+      assert(!s.contains("3"));
+      assert(s.contains("4"));
+      assert(s.contains("5"));
+      assert(!s.contains("6"));
+    }},
+
+    /* MVC */
     testGetModelById: function() { with(this) {
       assertEqual("m_1", CPSSkins.getModelById("m_1").def.id);
       assertEqual("m_2", CPSSkins.getModelById("m_2").def.id);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to