Author: jmorliaguet
Date: Fri Feb 17 12:04:14 2006
New Revision: 2395

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

- renamed the event's 'target' as 'publisher' since in the subscriber/publisher
  pattern the 'target' can be misunderstood as being the 'subscriber'.

  (this is still what is called 'event target' in DOM events, i.e. the event's
   source)




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 Feb 17 
12:04:14 2006
@@ -99,7 +99,7 @@
   unsubscribe: function(eventid, event) {
     new_subscribers = $A([]);
     CPSSkins.Subscribers[eventid].each(function(e) {
-      if (!(event.subscriber == e.subscriber && event.target == e.target)) {
+      if (!(event.subscriber == e.subscriber && event.publisher == 
e.publisher)) {
         new_subscribers.push(e);
       }
     });
@@ -108,15 +108,15 @@
 
   notify: function(eventid, info) {
     var subscribers = CPSSkins.Subscribers[eventid];
-    var target = info.target;
+    var publisher = info.publisher;
     $A(subscribers).each(function(e) {
-      var event_target = e.target;
-      if (event_target == target || event_target == null) {
+      var event_publisher = e.publisher;
+      if (event_publisher == publisher || event_publisher == null) {
         var handler = CPSSkins.getEventHandler(eventid, e.subscriber);
         if (handler) {
-          // set the target in case no target is specified in the subscription.
+          // set the publisher in case no publisher is specified in the 
subscription.
           info.subscriber = e.subscriber;
-          info.target = target;
+          info.publisher = publisher;
           handler(info);
         }
       }
@@ -161,7 +161,7 @@
     var progress = new Object({'initialized': 0});
     var length = elements.length;
 
-    CPSSkins.subscribe("initialized", {'subscriber': progress, 'target': 
null});
+    CPSSkins.subscribe("initialized", {'subscriber': progress, 'publisher': 
null});
     CPSSkins.registerEventHandler("initialized", progress, function(event) {
       progress.initialized += 1;
       if (progress.initialized >= length) {
@@ -175,7 +175,7 @@
         var options = {
           onComplete: function(req) {
             el.innerHTML = req.responseText;
-            CPSSkins.notify('initialized', {"target": el});
+            CPSSkins.notify('initialized', {'publisher': el});
           }
         }
         var parts = url.split('?');
@@ -186,7 +186,7 @@
         new Ajax.Request(url, options);
       } else {
         /* the definition is written inline */
-        CPSSkins.notify('initialized', {"target": el});
+        CPSSkins.notify('initialized', {'publisher': el});
       }
     });
   },
@@ -219,7 +219,7 @@
             var controller = factory(el, def);
             CPSSkins.Controllers[name] = controller;
             CPSSkins.notify("registered controller " + def.id,
-                            {"target": controller});
+                            {'publisher': controller});
           }
           break;
         }
@@ -227,7 +227,7 @@
         case "model": {
           var model = new CPSSkins.Model(el, def);
           CPSSkins.Models[name] = model;
-          CPSSkins.notify("registered model " + def.id, {"target": model});
+          CPSSkins.notify("registered model " + def.id, {'publisher': model});
           break;
         }
 
@@ -259,10 +259,10 @@
             if (model_id) {
               var evt_id = "registered model " + model_id;
               CPSSkins.registerEventHandler(evt_id, view, function(event) {
-                var model = event.target;
+                var model = event.publisher;
                 view.observe(model);
               });
-              CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
+              CPSSkins.subscribe(evt_id, {'subscriber': view, 'publisher': 
null});
             }
 
             /* register the controllers */
@@ -270,14 +270,14 @@
             $A(controllers_id).each(function(c) {
               var evt_id = "registered controller " + c;
               CPSSkins.registerEventHandler(evt_id, view, function(event) {
-                var controller = event.target;
+                var controller = event.publisher;
                 controller.view = view;
                 controller.register(view);
                 // add a back-reference
                 view.controller = controller;
 
               });
-              CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
+              CPSSkins.subscribe(evt_id, {'subscriber': view, 'publisher': 
null});
             });
 
             /* insert the widget into the DOM */
@@ -419,9 +419,9 @@
 
     var controller = this;
 
-    CPSSkins.registerEventHandler("command", view, function(info) {
+    CPSSkins.registerEventHandler("command", controller, function(info) {
       var view = info.subscriber;
-      var controller = info.target;
+      var controller = info.publisher;
 
       // add some contextual info
       info.view = view;
@@ -437,7 +437,7 @@
       }
     });
 
-    CPSSkins.subscribe("command", {'subscriber': view, "target": controller});
+    CPSSkins.subscribe("command", {'subscriber': controller, 'publisher': 
view});
   }
 
 });
@@ -478,7 +478,7 @@
     var controller = this;
 
     CPSSkins.registerEventHandler("gained focus", controller, function(info) {
-      var view = info.target;
+      var view = info.publisher;
       var selected = info.context;
       if (!view.def.model) {
         var model = Canvas.getModel(selected);
@@ -489,7 +489,7 @@
     });
 
     CPSSkins.registerEventHandler("lost focus", controller, function(info) {
-      var view = info.target;
+      var view = info.publisher;
       view.stopObserving();
     });
 
@@ -847,17 +847,17 @@
     var model = this;
     // observers subscribes to events on the model
     CPSSkins.registerEventHandler('modified', view, function(event) {
-      var data = event.target.def.data;
+      var data = event.publisher.def.data;
       event.subscriber.render(data);
     });
-    CPSSkins.subscribe('modified', {'subscriber': view, 'target': model});
+    CPSSkins.subscribe('modified', {'subscriber': view, 'publisher': model});
     // create a back-reference
     view.model = model;
   },
 
   removeObserver: function(view) {
     var model = this;
-    CPSSkins.unsubscribe('modified', {'subscriber': view, 'target': model});
+    CPSSkins.unsubscribe('modified', {'subscriber': view, 'publisher': model});
   },
 
   /* Private API */
@@ -883,10 +883,10 @@
 
     // the model reacts to events on the storage and notifies observers
     CPSSkins.registerEventHandler('stored', model, function(event) {
-      CPSSkins.notify('modified', {"target": model});
+      CPSSkins.notify('modified', {'publisher': model});
     });
 
-    CPSSkins.subscribe('stored', {'subscriber': model, 'target': storage});
+    CPSSkins.subscribe('stored', {'subscriber': model, 'publisher': storage});
 
     var refresh = storage_def.refresh;
     if (refresh && refresh > 0) {
@@ -989,7 +989,7 @@
     });
     // TODO compare old and new data
     this.model.def.data = filtered_data;
-    CPSSkins.notify('stored', {"target": this});
+    CPSSkins.notify('stored', {'publisher': this});
   },
 
   merge: function(data) {
@@ -1119,16 +1119,16 @@
 
     // merge the data from all storages
     CPSSkins.registerEventHandler('stored', storage, function(event) {
-      event.subscriber.merge(event.target.read());
+      event.subscriber.merge(event.publisher.read());
       // propagate the event
-      CPSSkins.notify('stored', {"target": storage});
+      CPSSkins.notify('stored', {'publisher': storage});
     });
 
     $A(this.model.def.storage.partitions).each(function(p) {
       var model = CPSSkins.getModelById(p);
       models.push(model);
       CPSSkins.subscribe('stored',
-        {'subscriber': storage, 'target': model.storage}
+        {'subscriber': storage, 'publisher': model.storage}
       );
     });
     this.models = models;
@@ -1215,7 +1215,7 @@
   show: function() {
     if (this.visible) return;
 
-    CPSSkins.notify("gained focus", {'target': this, 'context': 
this.selected});
+    CPSSkins.notify("gained focus", {'publisher': this, 'context': 
this.selected});
 
     // get new data
     this.update();
@@ -1256,7 +1256,7 @@
     }
 
     this.visible = false;
-    CPSSkins.notify("lost focus", {'target': this});
+    CPSSkins.notify("lost focus", {'publisher': this});
 
     // tear down the view;
     this.teardown();
@@ -1331,7 +1331,7 @@
       var options = {
         onComplete: function(req) {
           view.source = req.responseText;
-          CPSSkins.notify(evt_id, {"target": view});
+          CPSSkins.notify(evt_id, {'publisher': view});
         }
       }
       new Ajax.Request(url, options);
@@ -1340,7 +1340,7 @@
         view.getData();
       });
 
-      CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
+      CPSSkins.subscribe(evt_id, {'subscriber': view, 'publisher': null});
     }
 
   },
@@ -1646,7 +1646,7 @@
     /* notify the controller to take action */
     var info = {
       "context": this.selected,
-      "target": this.controller,
+      "publisher": this.controller,
       "options": {'action': action, 'choice': choice}
     }
     CPSSkins.notify("command", info);
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to