Author: jmorliaguet
Date: Thu Feb 16 22:55:02 2006
New Revision: 2391

Added:
   cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data3.txt   
(contents, props changed)
Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_external_sources.html
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
   cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt
   cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/quiz/cpsskins_quiz.pt
Log:

- a same view can have several controllers registered at the same time

- added a Focus Observer (a controller that receives "gained focus"
  and "lost focus" events coming from objects that are clicked on or that
  temporarily get some focus.

  - the controller makes the view observe the model of the object that 
    "gained focus"

  - when the object loses focus, the controller makes the view stops observing
    the model

  this is currently used with contextual menus and with tooltips



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 Feb 16 
22:55:02 2006
@@ -265,16 +265,20 @@
               CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
             }
 
-            /* register the controller */
-            var controller_id = def.controller || null;
-            if (controller_id) {
-              var evt_id = "registered controller " + controller_id;
+            /* register the controllers */
+            var controllers_id = def.controllers || [];
+            $A(controllers_id).each(function(c) {
+              var evt_id = "registered controller " + c;
               CPSSkins.registerEventHandler(evt_id, view, function(event) {
                 var controller = event.target;
-                controller.control(view);
+                controller.view = view;
+                controller.register(view);
+                // add a back-reference
+                view.controller = controller;
+
               });
               CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
-            }
+            });
 
             /* insert the widget into the DOM */
             var replace = def.widget.replace;
@@ -385,7 +389,7 @@
     this.def = def;
   },
 
-  control: function(view) {
+  register: function(view) {
     /* to override */
   }
 
@@ -394,12 +398,16 @@
 if (!window.Controllers) { var Controllers = new Object(); }
 Object.extend(Controllers, {
 
-  command: function(node, def) {
+  'command': function(node, def) {
     return new CPSSkins.CommandController(node, def);
   },
 
-  form: function(node, def) {
+  'form': function(node, def) {
     return new CPSSkins.FormController(node, def);
+  },
+
+  'focus observer': function(node, def) {
+    return new CPSSkins.FocusObserver(node, def);
   }
 
 });
@@ -407,10 +415,9 @@
 CPSSkins.CommandController = Class.create();
 CPSSkins.CommandController.prototype = Object.extend(new 
CPSSkins.Controller(), {
 
-  control: function(view) {
+  register: function(view) {
 
     var controller = this;
-    view.controller = controller;
 
     CPSSkins.registerEventHandler("command", view, function(info) {
       var view = info.subscriber;
@@ -438,10 +445,7 @@
 CPSSkins.FormController = Class.create();
 CPSSkins.FormController.prototype = Object.extend(new CPSSkins.Controller(), {
 
-  control: function(view) {
-    this.view = view;
-    var controller = this;
-    view.controller = controller;
+  register: function(view) {
 
     var widget = view.widget;
 
@@ -466,6 +470,35 @@
 
 });
 
+CPSSkins.FocusObserver = Class.create();
+CPSSkins.FocusObserver.prototype = Object.extend(new CPSSkins.Controller(), {
+
+  register: function(view) {
+
+    var controller = this;
+
+    CPSSkins.registerEventHandler("gained focus", controller, function(info) {
+      var view = info.target;
+      var selected = info.context;
+      if (!view.def.model) {
+        var model = Canvas.getModel(selected);
+        if (model) {
+          view.observe(model);
+        }
+      }
+    });
+
+    CPSSkins.registerEventHandler("lost focus", controller, function(info) {
+      var view = info.target;
+      view.stopObserving();
+    });
+
+    CPSSkins.subscribe("gained focus", {'subscriber': controller});
+    CPSSkins.subscribe("lost focus", {'subscriber': controller});
+  }
+
+});
+
 // Identifiable DOM elements.
 if (!window.Identifiable) var Identifiable = new Object();
 Object.extend(Identifiable, {
@@ -1182,14 +1215,7 @@
   show: function() {
     if (this.visible) return;
 
-    if (!this.def.model) {
-      var model = Canvas.getModel(this.selected);
-      if (model) {
-        this.observe(model);
-      } else {
-        return;
-      }
-    }
+    CPSSkins.notify("gained focus", {'target': this, 'context': 
this.selected});
 
     // get new data
     this.update();
@@ -1230,7 +1256,7 @@
     }
 
     this.visible = false;
-    this.stopObserving();
+    CPSSkins.notify("lost focus", {'target': this});
 
     // tear down the view;
     this.teardown();
@@ -1747,6 +1773,7 @@
 
     var model = Canvas.getModel(selected);
     if (!model) return;
+
     var data = model.def.data;
     if (!data) return;
     if (data.hint == null) return;

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
       (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualactions_test.html
       Thu Feb 16 22:55:02 2006
@@ -15,7 +15,13 @@
 <body>
 
   <ins class="controller">
-  {"id": "controller",
+  {"id": "show-hide-menu",
+   "type": "focus observer"
+  }
+  </ins>
+
+  <ins class="controller">
+  {"id": "do-action",
    "type": "command",
    "handlers": {
      "edit": "displayChoice",
@@ -60,7 +66,7 @@
          }
        ]
      },
-     "controller": "controller",
+     "controllers": ["show-hide-menu", "do-action"],
      "show_effect": {
        "transition": "fadein"
      },

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_contextualmenu_test.html
  Thu Feb 16 22:55:02 2006
@@ -17,7 +17,13 @@
   <h1>CPSSkins Contextual menu</h1>
 
   <ins class="controller">
-  {"id": "controller",
+  {"id": "show-hide-menu",
+   "type": "focus observer"
+  }
+  </ins>
+
+  <ins class="controller">
+  {"id": "do-action",
    "type": "command",
    "handlers": {
      "edit": "displayChoice",
@@ -99,7 +105,7 @@
          }
        ]
      },
-     "controller": "controller",
+     "controllers": ["show-hide-menu", "do-action"],
      "show_effect": {
        "transition": "fadein"
      },

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_external_sources.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_external_sources.html
     (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_external_sources.html
     Thu Feb 16 22:55:02 2006
@@ -37,6 +37,9 @@
 
   <div id="area1">
 
+    <ins class="controller" cite="data3.txt">
+    </ins>
+
     <ins class="model" cite="data1.txt">
     </ins>
     <a href="#">Open</a>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
      (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_tooltip.html
      Thu Feb 16 22:55:02 2006
@@ -53,6 +53,12 @@
 
   <div id="area1">
 
+    <ins class="controller">
+    {"id": "show-hide-tooltip",
+     "type": "focus observer"
+    }
+    </ins>
+
     <ins class="model">
     {"data": {
       "hint":"Click here to open the document."
@@ -78,12 +84,11 @@
     {"widget": {
        "type": "tooltip"
      },
-
+     "controllers": ["show-hide-tooltip"],
      "show_effect": {
        "transition": "fadein",
        "delay": 1000
      },
-
      "hide_effect": {
        "transition": "fadeout",
        "delay": 500
@@ -121,12 +126,11 @@
     {"widget": {
        "type": "tooltip"
      },
-
+     "controllers": ["show-hide-tooltip"],
      "show_effect": {
        "transition": "fadein",
        "delay": 500
      },
-
      "hide_effect": {
        "transition": "fadeout",
        "delay": 1000

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt  
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data1.txt  
Thu Feb 16 22:55:02 2006
@@ -1,4 +1,4 @@
 {"data": {
-  "hint":"Click here to close the document."
+  "hint":"Click here to open the document."
   }
 }

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt  
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data2.txt  
Thu Feb 16 22:55:02 2006
@@ -3,6 +3,8 @@
    "type": "tooltip"
  },
 
+ "controllers": ["show-hide-tooltip"],
+
  "show_effect": {
    "transition": "fadein"
  },

Added: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data3.txt
==============================================================================
--- (empty file)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/data3.txt  
Thu Feb 16 22:55:02 2006
@@ -0,0 +1,3 @@
+{"id": "show-hide-tooltip",
+ "type": "focus observer"
+}

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/chat/cpsskins_chat.pt
        Thu Feb 16 22:55:02 2006
@@ -135,7 +135,7 @@
       "template": "chatinput.html"
      },
      "model": "form",
-     "controller": "form-controller"
+     "controllers": ["form-controller"]
     }
     </ins>
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    Thu Feb 16 22:55:02 2006
@@ -55,7 +55,7 @@
       "template": "sampleform.html"
      },
      "model": "form-data",
-     "controller": "form-controller"
+     "controllers": ["form-controller"]
     }
     </ins>
 

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/quiz/cpsskins_quiz.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/quiz/cpsskins_quiz.pt
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/quiz/cpsskins_quiz.pt
        Thu Feb 16 22:55:02 2006
@@ -164,7 +164,7 @@
       "type": "inputbox"
      },
      "model": "ram-data-provider",
-     "controller": "controller"
+     "controllers": ["controller"]
     }
     </ins>
 
@@ -198,7 +198,7 @@
       "type": "inputbox"
      },
      "model": "local-data-provider",
-     "controller": "controller"
+     "controllers": ["controller"]
     }
     </ins>
 
@@ -258,7 +258,7 @@
       "type": "inputbox"
      },
      "model": "remote-data-provider",
-     "controller": "controller"
+     "controllers": ["controller"]
     }
     </ins>
 
@@ -329,7 +329,7 @@
       "type": "inputbox"
      },
      "model": "compound-data-provider",
-     "controller": "controller"
+     "controllers": ["controller"]
     }
     </ins>
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to