Author: jmorliaguet
Date: Fri Mar 17 23:14:49 2006
New Revision: 2653

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

- race condition / cycle fixes. best working version so far



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 Fri Mar 17 
23:14:49 2006
@@ -856,27 +856,34 @@
       }
     }.bind(this));
     CPSSkins.subscribe("parsed", {"subscriber": this, "publisher": this.node});
+    this._current = null;
   },
 
   register: function(view) {
     var visible = this._visible_views;
+    var view_id = view.hash();
+    var current_perspective = this._current;
     $A(view.def.perspectives).each(function(p) {
       if (!(p in visible)) {
         visible[p] = [];
       }
-      if (!(view.hash() in visible[p])) {
-        visible[p].push(view.hash());
+      if (!(view_id in visible[p])) {
+        visible[p].push(view_id);
+      }
+      if (p == current_perspective) {
+        CPSSkins.getViewById(view_id).show();
       }
     });
   },
 
   switchTo: function(perspective) {
+    this._current = perspective;
     var to_show = this._visible_views[perspective] || [];
-    var to_hide = this.views.entries().select(function(el) {
-      return to_show.indexOf(el) < 0;
+    var to_hide = this.views.entries().select(function(v) {
+      return to_show.indexOf(v) < 0;
     });
-    to_hide.each(function(el) { CPSSkins.getViewById(el).hide(); });
-    to_show.each(function(el) { CPSSkins.getViewById(el).show(); });
+    to_hide.each(function(v) { CPSSkins.getViewById(v).hide(); });
+    to_show.each(function(v) { CPSSkins.getViewById(v).show(); });
   }
 
 });
@@ -1597,12 +1604,6 @@
     this.def = def;
 
     this.setup();
-
-    CPSSkins.registerEventHandler("displayed", this, function(event) {
-      var view = event.subscriber;
-      view.attachControllers();
-    });
-    CPSSkins.subscribe("displayed", {'subscriber': this});
   },
 
   hash: function() {
@@ -1677,7 +1678,6 @@
     var data = this.readData();
     if (data) {
       this.display(data);
-      CPSSkins.notify("displayed", {'publisher': this});
     }
   },
 
@@ -1685,7 +1685,6 @@
     var data = this.getData();
     if (data) {
       this.display(data);
-      CPSSkins.notify("displayed", {'publisher': this});
     }
   },
 
@@ -1698,7 +1697,7 @@
   },
 
   show: function() {
-    if (this._visible) { return }
+    if (this._visible) return;
     var widget = $(this.widget);
 
     CPSSkins.notify("gained focus", {'publisher': this,
@@ -1719,9 +1718,7 @@
   },
 
   hide: function() {
-    if (!this._visible) {
-      return;
-    }
+    if (!this._visible) return;
     var widget = $(this.widget);
 
     if (this.def.hide_effect) {
@@ -1729,12 +1726,11 @@
     } else {
       widget.hide();
     }
-
-    this._visible = false;
     CPSSkins.notify("lost focus", {'publisher': this});
 
     // tear down the view;
     this.teardown();
+    this._visible = false;
   },
 
   applyEffect: function(options) {
@@ -1856,6 +1852,7 @@
       node.innerHTML = this.source;
       ctal.process_ctal(node, data);
       this.widget.innerHTML = node.innerHTML;
+      this.attachControllers();
     }
   }
 
@@ -1896,7 +1893,7 @@
       var options = {
         onComplete: function() {
           CPSSkins._parse(widget);
-          CPSSkins.notify("displayed", {'publisher': view});
+          view.attachControllers();
         }
       };
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to