Author: jmorliaguet
Date: Sat Mar  4 18:21:04 2006
New Revision: 2523

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

- some fixes to avoid rendering the same panel several times



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 Sat Mar  4 
18:21:04 2006
@@ -89,6 +89,20 @@
     context.parentNode.replaceChild(div, context);
   },
 
+  /* Comparison */
+
+  compare: function(a, b) {
+    if (a == undefined && b == undefined) {
+      return true;
+    }
+    if (typeof a == 'object' && typeof b == 'object') {
+      if (a.hash != undefined && b.hash != undefined) {
+        return a.hash() == b.hash();
+      }
+    }
+    return (a == b);
+  },
+
   /* Action handlers */
   addActions: function(handlers) {
     Object.extend(this._handlers, handlers);
@@ -99,7 +113,12 @@
     if (!(eventid in this._subscribers)) {
       this._subscribers[eventid] = [];
     }
-    this._subscribers[eventid].push(event);
+    if (this._subscribers[eventid].findAll(function(e) {
+      return (CPSSkins.compare(event.subscriber, e.subscriber) &&
+        CPSSkins.compare(event.publisher, e.publisher))
+    }).length == 0) {
+      this._subscribers[eventid].push(event);
+    }
   },
 
   unsubscribe: function(eventid, event) {
@@ -107,8 +126,8 @@
     if (!(eventid in subscribers)) { return; }
     subscribers[eventid] = subscribers[eventid].reject(function(e) {
       if (event == undefined) return true;
-      return (event.subscriber == e.subscriber &&
-              event.publisher == e.publisher)
+      return (CPSSkins.compare(event.subscriber, e.subscriber) &&
+              CPSSkins.compare(event.publisher, e.publisher))
       });
     if (subscribers[eventid].length == 0) {delete subscribers[eventid]}
   },
@@ -117,9 +136,13 @@
     var subscribers = this._subscribers;
     var publisher = event.publisher;
     (subscribers[eventid] || []).findAll(function(e) {
-      // FIXME: this is broken, comparisons in javascript only check object
-      // identify;
-      return (e.publisher == publisher || e.publisher == null)
+      if (e.publisher == null) {
+        return true;
+      }
+      if (CPSSkins.compare(e.publisher, publisher)) {
+        return true;
+      }
+      return false;
     }).each(function(e) {
       var handler = CPSSkins.getEventHandler(eventid, e.subscriber);
       if (handler) {
@@ -374,6 +397,10 @@
     this.views = new CPSSkins.Set();
   },
 
+  hash: function() {
+    return this.def.id;
+  },
+
   setup: function() {
     /* to override */
   },
@@ -970,6 +997,10 @@
     this.storage = this._setStorageAdapter();
   },
 
+  hash: function() {
+    return this.def.id;
+  },
+
   // low-level I/O
   readData: function() {
     return this._data || this.def.data;
@@ -1003,8 +1034,7 @@
     var model = this;
     // observers subscribes to events on the model
     CPSSkins.registerEventHandler('changed', view, function(event) {
-      var data = event.publisher.readData();
-      event.subscriber.display(data);
+      event.subscriber.refresh();
     });
     CPSSkins.subscribe('changed', {'subscriber': view, 'publisher': model});
   },
@@ -1324,6 +1354,10 @@
     this.setup();
   },
 
+  hash: function() {
+    return this.def.id;
+  },
+
   /* Public API */
   inspect: function() {
     return "[CPSSkins " + this.def.widget + "]";
@@ -1378,7 +1412,7 @@
   },
 
   show: function() {
-    if (this.visible) return;
+    if (this._visible) { return }
 
     CPSSkins.notify("gained focus", {'publisher': this,
                                      'context': this.selected});
@@ -1394,11 +1428,11 @@
     } else {
       Element.show(this.widget);
     }
-    this.visible = true;
+    this._visible = true;
   },
 
   hide: function() {
-    if (!this.visible) {
+    if (!this._visible) {
       return;
     }
 
@@ -1408,7 +1442,7 @@
       Element.hide(this.widget);
     }
 
-    this.visible = false;
+    this._visible = false;
     CPSSkins.notify("lost focus", {'publisher': this});
 
     // tear down the view;
@@ -1524,16 +1558,15 @@
 CPSSkins.Panel = Class.create();
 CPSSkins.Panel.prototype = Object.extend(new CPSSkins.View(), {
 
-  setup: function() {
-    this.visible = false;
-  },
-
   inspect: function() {
     return '[CPSSkins Panel]';
   },
 
   render: function(data) {
     var url = data.url;
+    if (!url) {
+      return;
+    }
     var script = data.script;
     if (script) {
       this.script_id = this.def.model;
@@ -1563,9 +1596,6 @@
     }
   },
 
-  prepare: function() {
-  },
-
   teardown: function() {
     if (this.css_id) {
       CPSSkins.Canvas.removeStyleSheet(this.css_id);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to