Author: jmorliaguet
Date: Thu Mar  2 11:03:44 2006
New Revision: 2506

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   cpsskins/branches/jmo-perspectives/ui/framework/doc/index.txt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/behaviour/cpsskins_behaviour_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_effects_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_progressive_enhancement.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_widget_template_test.html
   cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt
   cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/cpsskins_panel_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/panel5.html
   cpsskins/branches/jmo-perspectives/ui/framework/tests/unit/cpsskins_test.html
Log:

- all MVC components have an id. it simplifies registration and it makes it
  possible to keep track of registered components.



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 
11:03:44 2006
@@ -43,6 +43,7 @@
 
   _subscribers: $H({}),
   _models: $H({}),
+  _views: $H({}),
   _controllers: $H({}),
   _handlers: $H({}),
 
@@ -54,25 +55,15 @@
   },
 
   getModelById: function(id) {
-    var model = null;
-    this._models.each(function(m) {
-      var def = m.value.def;
-      if (def.id == id) {
-        model = m.value
-      };
-    });
-    return model;
+    return this._models[id];
   },
 
   getControllerById: function(id) {
-    var controller = null;
-    this._controllers.each(function(c) {
-      var def = c.value.def;
-      if (def.id == id) {
-        controller = c.value;
-      };
-    });
-    return controller;
+    return this._controllers[id];
+  },
+
+  getViewById: function(id) {
+    return this._views[id];
   },
 
   registerControllers: function(controllers) {
@@ -219,20 +210,28 @@
 
   _register: function(el, classid, index) {
       // make the element identifiable
-      var name = classid + index;
-      el.setAttribute("name", name);
       var def = this._jsonParse(el);
+      var id = def.id;
+      if (!id) {
+        CPSSkins.warn("Component of type '" + classid + "' has no id: <pre>" 
+                      + el.innerHTML + "</pre>", el);
+      }
+      var name = classid + id;
+      el.setAttribute("name", name);
       def.name = name;
 
       switch(classid) {
 
         case "controller": {
+          if (CPSSkins.getControllerById(id)) {
+            break;
+          }
           var controller_type = def.type || "command";
           var factory = this.Controllers[controller_type];
           if (factory) {
             var controller = factory(el, def);
             controller.setup();
-            this._controllers[name] = controller;
+            this._controllers[id] = controller;
             CPSSkins.notify("registered controller " + def.id,
                             {'publisher': controller});
           }
@@ -240,13 +239,19 @@
         }
 
         case "model": {
+          if (CPSSkins.getModelById(id)) {
+            break;
+          }
           var model = new CPSSkins.Model(el, def);
-          this._models[name] = model;
+          this._models[id] = model;
           CPSSkins.notify("registered model " + def.id, {'publisher': model});
           break;
         }
 
         case "view": {
+          if (CPSSkins.getViewById(id)) {
+            break;
+          }
           var view;
           var widget_type;
 
@@ -265,6 +270,7 @@
 
           factory = this.Widgets[widget_type];
           view = factory(def);
+          this._views[id] = view;
 
           /* create the view */
           if (view) {

Modified: cpsskins/branches/jmo-perspectives/ui/framework/doc/index.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/doc/index.txt       
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/doc/index.txt       Thu Mar 
 2 11:03:44 2006
@@ -304,6 +304,8 @@
 
   - getModelById(id)
 
+  - getViewById(id)
+
   - getControllerById(id)
 
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/behaviour/cpsskins_behaviour_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/behaviour/cpsskins_behaviour_test.html
     (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/behaviour/cpsskins_behaviour_test.html
     Thu Mar  2 11:03:44 2006
@@ -79,7 +79,8 @@
     </ins>
 
     <ins class="view">
-    {"model": "dummy",
+    {"id": "template",
+     "model": "dummy",
      "widget": {
        "template": "template.html"
      },

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
       (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
       Thu Mar  2 11:03:44 2006
@@ -38,7 +38,8 @@
 
     <!-- View: contextual actions widget -->
     <ins class="view">
-    {"widget": {
+    {"id": "menu",
+     "widget": {
        "type": "contextualactions",
        "items": [
          {"type": "item",
@@ -77,7 +78,8 @@
     </ins>
 
     <ins class="model">
-    {"data": {
+    {"id": "m1",
+     "data": {
       "copyable":true
     }}
     </ins>
@@ -86,21 +88,24 @@
     <div id="area2" class="pad">area2</div>
 
     <ins class="model">
-    {"data": {
+    {"id": "m2",
+     "data": {
       "editable":true
     }}
     </ins>
     <div id="area3" class="pad">area3</div>
 
     <ins class="model">
-    {"data": {
+    {"id": "m3",
+     "data": {
       "editable":true
     }}
     </ins>
     <div id="area4" class="pad">area4
 
       <ins class="model">
-      {"data": {
+      {"id": "m3",
+       "data": {
         "editable":true
       }}
       </ins>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  Thu Mar  2 11:03:44 2006
@@ -41,7 +41,8 @@
     <!-- View: contextual menu widget -->
 
     <ins class="view">
-    {"widget": {
+    {"id": "menu",
+     "widget": {
        "type": "contextmenu",
        "items": [
          {"type": "item",
@@ -116,14 +117,16 @@
     </ins>
 
     <ins class="model">
-    {"data": {
+    {"id": "m1",
+     "data": {
       "copyable":true
     }}
     </ins>
     <div id="area1" class="pad">area1</div>
 
     <ins class="model">
-    {"data": {
+    {"id": "m2",
+     "data": {
       "formattable":true,
       "formats":[
         {"choice":"style","label":"Style"}
@@ -133,14 +136,16 @@
     <div id="area2" class="pad">area2</div>
 
     <ins class="model">
-    {"data": {
+    {"id": "m3",
+     "data": {
       "editable":true
     }}
     </ins>
     <div id="area3" class="pad">area3</div>
 
     <ins class="model">
-    {"data": {
+    {"id": "m4",
+     "data": {
       "editable":true,
       "formattable":true,
       "formats":[
@@ -160,7 +165,8 @@
     <div id="area4" class="pad">area4
 
       <ins class="model">
-      {"data": {
+      {"id": "m5",
+       "data": {
         "editable":true
       }}
       </ins>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_dragdrop_test.html
        Thu Mar  2 11:03:44 2006
@@ -53,7 +53,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "d1",
+   "widget": {
      "template": "draggable.html"
    },
    "model": "dummy",

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_effects_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_effects_test.html
 (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_effects_test.html
 Thu Mar  2 11:03:44 2006
@@ -64,7 +64,8 @@
   <td valign="top">
 
   <ins class="view">
-  {"widget": {
+  {"id": "view1",
+   "widget": {
      "template": "effect_template.pt"
    },
    "model": "effect1",
@@ -79,7 +80,8 @@
   <td valign="top">
 
   <ins class="view">
-  {"widget": {
+  {"id": "view2",
+   "widget": {
      "template": "effect_template.pt"
    },
    "model": "effect2",
@@ -94,7 +96,8 @@
   <td valign="top">
 
   <ins class="view">
-  {"widget": {
+  {"id": "view3",
+   "widget": {
      "template": "effect_template.pt"
    },
    "model": "effect3",
@@ -109,7 +112,8 @@
   <td valign="top">
 
   <ins class="view">
-  {"widget": {
+  {"id": "view4",
+   "widget": {
      "template": "effect_template.pt"
    },
    "model": "effect4",

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
        Thu Mar  2 11:03:44 2006
@@ -152,7 +152,8 @@
 
     <!-- tooltip view -->
     <ins class="view">
-    {"widget": {
+    {"id": "tooltip",
+     "widget": {
        "type":"tooltip"
      },
      "controllers": ["show-hide-tooltip"],
@@ -164,7 +165,8 @@
 
     <!-- contextual menu view -->
     <ins class="view">
-    {"widget": {
+    {"id": "menu",
+     "widget": {
       "type": "contextmenu",
       "items": [
         {"type": "selection", "choices": "sizeinfo"}
@@ -178,7 +180,8 @@
 
   <h3>progress bar widget</h3>
   <ins class="view">
-  {"widget": {
+  {"id": "progressbar",
+   "widget": {
      "type": "progressbar"
    },
    "model": "data-provider"
@@ -187,7 +190,8 @@
 
   <h3>counter widget</h3>
   <ins class="view">
-  {"widget": {
+  {"id": "counter",
+   "widget": {
      "type": "counter"
    },
    "model": "data-provider"
@@ -199,7 +203,8 @@
     Info
     <!-- menu view observing the data provider -->
     <ins class="view">
-    {"widget": {
+    {"id": "menu2",
+     "widget": {
        "type": "contextmenu",
        "items": [
          {"type": "submenu",

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_progressive_enhancement.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_progressive_enhancement.html
      (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_progressive_enhancement.html
      Thu Mar  2 11:03:44 2006
@@ -51,7 +51,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "some-view",
+   "widget": {
      "template": "ajax_widget_template.pt",
      "replace": "htmlwidget"
    },

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
      (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
      Thu Mar  2 11:03:44 2006
@@ -60,28 +60,32 @@
     </ins>
 
     <ins class="model">
-    {"data": {
+    {"id": "m1",
+     "data": {
       "hint":"Click here to open the document."
     }}
     </ins>
     <a href="#">Open</a>
 
     <ins class="model">
-    {"data": {
+    {"id": "m2",
+     "data": {
       "hint":"Click here to save the document."
     }}
     </ins>
     <a href="#">Save</a>
 
     <ins class="model">
-    {"data": {
+    {"id": "m3",
+     "data": {
       "hint":"Click here to close the document."
     }}
     </ins>
     <a href="#">Close</a>
 
     <ins class="view">
-    {"widget": {
+    {"id": "tooltip1",
+     "widget": {
        "type": "tooltip"
      },
      "controllers": ["show-hide-tooltip"],
@@ -102,28 +106,32 @@
   <div id="area2">
 
     <ins class="model">
-    {"data": {
+    {"id": "m4",
+     "data": {
       "hint":"Click here to open the file."
     }}
     </ins>
     <a href="#">Open</a>
 
     <ins class="model">
-    {"data": {
+    {"id": "m5",
+     "data": {
       "hint":"Click here to save the file."
     }}
     </ins>
     <a href="#">Save</a>
 
     <ins class="model">
-    {"data": {
+    {"id": "m6",
+     "data": {
       "hint":"Click here to close the file."
     }}
     </ins>
     <a href="#">Close</a>
 
     <ins class="view">
-    {"widget": {
+    {"id": "tooltip2",
+     "widget": {
        "type": "tooltip"
      },
      "controllers": ["show-hide-tooltip"],

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_widget_template_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_widget_template_test.html
 (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_widget_template_test.html
 Thu Mar  2 11:03:44 2006
@@ -62,7 +62,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "some-template",
+   "widget": {
      "template": "template.pt"
    },
    "model": "template-data",

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt  
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt  
Thu Mar  2 11:03:44 2006
@@ -1,4 +1,5 @@
-{"data": {
+{"id": "m1",
+ "data": {
   "hint":"Click here to open the document."
   }
 }

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt  
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt  
Thu Mar  2 11:03:44 2006
@@ -1,5 +1,6 @@
 
-{"widget": {
+{"id": "tooltip",
+ "widget": {
    "type": "tooltip"
  },
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/cpsskins_panel_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/cpsskins_panel_test.html
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/cpsskins_panel_test.html
    Thu Mar  2 11:03:44 2006
@@ -95,7 +95,8 @@
         </ins>
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel1",
+         "widget": {
            "type": "panel"
          },
          "model": "panel1",
@@ -105,7 +106,8 @@
         </ins>
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel2",
+         "widget": {
            "type": "panel"
          },
          "model": "panel2",
@@ -121,7 +123,8 @@
       <td style="width: 20%">
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel2b",
+         "widget": {
            "type": "panel"
          },
          "model": "panel2",
@@ -131,7 +134,8 @@
         </ins>
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel2c",
+         "widget": {
            "type": "panel"
          },
          "model": "panel3",
@@ -144,7 +148,8 @@
       <td style="width: 60%">
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel3a",
+         "widget": {
            "type": "panel"
          },
          "model": "panel3",
@@ -154,7 +159,8 @@
         </ins>
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel4a",
+         "widget": {
            "type": "panel"
          },
          "model": "panel4",
@@ -165,7 +171,8 @@
 
         <!-- this panel contains sub-panels -->
         <ins class="view">
-        {"widget": {
+        {"id": "panel5",
+         "widget": {
            "type": "panel"
          },
          "model": "panel5",
@@ -179,7 +186,8 @@
       <td style="width: 20%">
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel4a",
+         "widget": {
            "type": "panel"
          },
          "model": "panel4",
@@ -189,7 +197,8 @@
         </ins>
 
         <ins class="view">
-        {"widget": {
+        {"id": "panel2c",
+         "widget": {
            "type": "panel"
          },
          "model": "panel2",
@@ -198,8 +207,6 @@
         }
         </ins>
 
-
-
       </td>
 
     </tr>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/panel5.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/panel5.html
 (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/panels/panel5.html
 Thu Mar  2 11:03:44 2006
@@ -33,7 +33,8 @@
 
   <div class="frame">
     <ins class="view">
-    {"widget": {
+    {"id": "panel5_1",
+     "widget": {
      "type": "panel"
     },
     "model": "panel5_1",
@@ -43,7 +44,8 @@
     </ins>
 
     <ins class="view">
-    {"widget": {
+    {"id": "panel5_2",
+     "widget": {
      "type": "panel"
      },
      "model": "panel5_2",

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 11:03:44 2006
@@ -124,7 +124,8 @@
 
   <!-- panels -->
   <ins class="view">
-  {"widget": {
+  {"id": "v1",
+   "widget": {
      "type": "panel"
    },
    "model": "p1",
@@ -134,7 +135,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "v2",
+   "widget": {
      "type": "panel"
    },
    "model": "p2",
@@ -144,7 +146,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "v3",
+   "widget": {
      "type": "panel"
    },
    "model": "p3",
@@ -154,7 +157,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "v4",
+   "widget": {
      "type": "panel"
    },
    "model": "p1_2",
@@ -164,7 +168,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "v5",
+   "widget": {
      "type": "panel"
    },
    "model": "p2_3",
@@ -174,7 +179,8 @@
   </ins>
 
   <ins class="view">
-  {"widget": {
+  {"id": "v6",
+   "widget": {
      "type": "panel"
    },
    "model": "p2_3_1",
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to