Author: jmorliaguet
Date: Sun Feb  5 21:22:24 2006
New Revision: 2301

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

- fixed a couple of bugs:

  - the page must be parsed in two stages

  - 'notify' would erase the 'target' subscription information



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 Sun Feb  5 
21:22:24 2006
@@ -106,8 +106,7 @@
         var handler = CPSSkins.getEventHandler(eventid, e.subscriber);
         if (handler) {
           // set the target in case no target is specified in the subscription.
-          e.target = target;
-          handler(e);
+          handler({'subscriber': e.subscriber, 'target': target});
         }
       }
     });
@@ -147,30 +146,48 @@
     return res;
   },
 
+  // first stage
   parse: function(node) {
-    $A(["view", "controller", "model"]).each(function(type) {
-
-      var elements = node.getElementsByTagName("ins");
-      $A(elements).each(function(el, index) {
-
-        var this_type = el.className;
-        if (this_type != type) return;
+    var elements = node.getElementsByTagName("ins");
+    var progress = new Object({'initialized': 0});
+    var length = elements.length;
+
+    CPSSkins.subscribe("initialized", {'subscriber': progress, 'target': 
null});
+    CPSSkins.registerEventHandler("initialized", progress, function(event) {
+      progress.initialized += 1;
+      if (progress.initialized >= length) {
+        CPSSkins.load(node);
+      }
+    });
 
-        var url = el.getAttribute("cite");
-        if (url) {
-          var options = {
-            onComplete: function(req) {
-              el.innerHTML = req.responseText;
-              CPSSkins.register(el, type, index);
-            }
-          }
-          var parts = url.split('?');
-          if (parts.length == 2) {
-            var url = parts[0];
-            options.parameters = parts[1];
+    $A(elements).each(function(el, index) {
+      var url = el.getAttribute("cite");
+      if (url) {
+        var options = {
+          onComplete: function(req) {
+            el.innerHTML = req.responseText;
+            CPSSkins.notify('initialized', el);
           }
-          new Ajax.Request(url, options);
-        } else {
+        }
+        var parts = url.split('?');
+        if (parts.length == 2) {
+          var url = parts[0];
+          options.parameters = parts[1];
+        }
+        new Ajax.Request(url, options);
+      } else {
+        /* the definition is written inline */
+        CPSSkins.notify('initialized', el);
+      }
+    });
+  },
+
+  // second stage
+  load: function(node) {
+    var elements = node.getElementsByTagName("ins");
+    $A(["view", "controller", "model"]).each(function(type) {
+      $A(elements).each(function(el, index) {
+        if (Element.hasClassName(el, type)) {
           CPSSkins.register(el, type, index);
         }
       });
@@ -178,11 +195,9 @@
   },
 
   register: function(el, classid, index) {
-
       // make the element identifiable
       var name = classid + index;
       el.setAttribute("name", name);
-
       var def = CPSSkins.jsonParse(el);
 
       switch(classid) {
@@ -247,8 +262,7 @@
               }
               CPSSkins.Perspectives[p].push(view);
             });
-            CPSSkins.notify("registered", view);
-
+            //CPSSkins.notify("registered view " + def.id, view);
           }
           break;
         }
@@ -1111,7 +1125,7 @@
       var widget = this.widget;
       var options = {
         onComplete: function() {
-          CPSSkins.parse(widget);
+          CPSSkins.load(widget);
         }
       };
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to