Author: jmorliaguet
Date: Thu Mar  2 15:33:21 2006
New Revision: 2509

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

- simplifications: we refer to components using their id instead of creating an
  object reference.



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 
15:33:21 2006
@@ -47,7 +47,6 @@
   _controllers: $H({}),
   _handlers: $H({}),
 
-  _loaded: 0,
   _initialized: $H({}),
 
   init: function() {
@@ -201,14 +200,13 @@
     ["view", "controller", "model"].each(function(type) {
       elements.each(function(el) {
         if (Element.hasClassName(el, type)) {
-          this._register(el, type, this._loaded);
-          this._loaded += 1;
+          CPSSkins._register(el, type);
         }
-      }.bind(this));
-    }.bind(this));
+      });
+    });
   },
 
-  _register: function(el, classid, index) {
+  _register: function(el, classid) {
       // make the element identifiable
       var def = this._jsonParse(el);
       var id = def.id;
@@ -228,7 +226,7 @@
             var controller = factory(el, def);
             controller.setup();
             this._controllers[id] = controller;
-            CPSSkins.notify("registered controller " + def.id,
+            CPSSkins.notify("registered controller " + id,
                             {'publisher': controller});
           }
           break;
@@ -237,7 +235,7 @@
         case "model": {
           var model = new CPSSkins.Model(el, def);
           this._models[id] = model;
-          CPSSkins.notify("registered model " + def.id, {'publisher': model});
+          CPSSkins.notify("registered model " + id, {'publisher': model});
           break;
         }
 
@@ -283,7 +281,7 @@
               var evt_id = "registered controller " + c;
               CPSSkins.registerEventHandler(evt_id, view, function(event) {
                 var controller = event.publisher;
-                controller.views.push(view);
+                controller.views[id] = id;
                 controller.register(view);
                 CPSSkins.unsubscribe(evt_id);
               });
@@ -323,7 +321,7 @@
   initialize: function(node, def) {
     this.node = this.node;
     this.def = def;
-    this.views = [];
+    this.views = $H({});
   },
 
   setup: function() {
@@ -436,9 +434,10 @@
   },
 
   submitEvent: function(e) {
-    $A(this.views).each(function(view) {
-      var model = this.view.model;
-      var widget = this.view.widget;
+    this.views.each(function(v) {
+      var view = CPSSkins.getViewById(v);
+      var model = view.model;
+      var widget = view.widget;
 
       var form_data = {};
       $A(Form.getInputs(widget)).each(function(i) {
@@ -553,18 +552,19 @@
       if (!(p in visible)) {
         visible[p] = [];
       }
-      visible[p].push(view);
+      if (!(view.def.id in visible[p])) {
+        visible[p].push(view.def.id);
+      }
     });
   },
 
   switchTo: function(perspective) {
     var to_show = this._visible_views[perspective] || [];
-    var to_hide = this.views.select(function(el) {
+    var to_hide = this.views.keys().select(function(el) {
       return to_show.indexOf(el) < 0;
     });
-
-    to_hide.each(function(el) { el.hide(); });
-    to_show.each(function(el) { el.show(); });
+    to_hide.each(function(el) { CPSSkins.getViewById(el).hide(); });
+    to_show.each(function(el) { CPSSkins.getViewById(el).show(); });
   }
 
 });
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to