Author: jmorliaguet
Date: Sun Jan 29 23:01:39 2006
New Revision: 2242

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_observer_test.html
   cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
Log:

- saving work

  * controllers (command handlers) can be registered with:

  <ins class="controller">
  { ... }
  </ins>

  * handlers are registered with:

  CPSSkins.registerHandler({'handler name': handler);

  * added a test for zope3 to access remote data (no setter yet)



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 Jan 29 
23:01:39 2006
@@ -40,6 +40,8 @@
 
   Controllers: $H({}),
 
+  Handlers: $H({}),
+
   Perspectives: $H({}),
 
   Cache: $H({}),
@@ -62,6 +64,21 @@
     return model;
   },
 
+  getControllerById: function(id) {
+    var controller = null;
+    $A(CPSSkins.Controllers).each(function(c) {
+      var def = c[1].def;
+      if (def.id == id) {
+        controller = c[1]
+      };
+    });
+    return controller;
+  },
+
+  registerHandlers: function(handlers) {
+    Object.extend(CPSSkins.Handlers, handlers);
+  },
+
   jsonParse: function(el) {
     var res = null;
     var text = el.innerHTML;
@@ -114,6 +131,12 @@
 
       switch(classid) {
 
+        case "controller": {
+          var controller = new CPSSkins.Controller(el, def);
+          CPSSkins.Controllers[name] = controller;
+          break;
+        }
+
         case "model": {
           var model = new CPSSkins.Model(el, def);
           model.id = index;
@@ -139,6 +162,13 @@
               view.observe(model);
             }
 
+            /* register the controller */
+            var controller_id = def.controller || null;
+            if (controller_id) {
+              var controller = CPSSkins.getControllerById(controller_id);
+              view.controller = controller;
+            }
+
             /* insert the widget into the DOM */
             el.parentNode.insertBefore(view.widget, el);
 
@@ -233,14 +263,9 @@
 CPSSkins.Controller = Class.create();
 CPSSkins.Controller.prototype = {
 
-  initialize: function(id) {
-    this.id = id;
-    this.handlers = {};
-    CPSSkins.Controllers[id] = this;
-  },
-
-  register: function(handlers) {
-    Object.extend(this.handlers, handlers);
+  initialize: function(node, def) {
+    this.node = this.node;
+    this.def = def;
   }
 
 }
@@ -686,13 +711,6 @@
     this.widget = widget;
     this.def = def;
 
-    var controller_id = def.controller || null;
-    if (controller_id) {
-      this.controller = CPSSkins.Controllers[controller_id];
-    } else {
-      this.controller = null;
-    }
-
     this.show_effect = def.show_effect || {};
     this.hide_effect = def.hide_effect || {};
 
@@ -736,9 +754,10 @@
   handleAction: function(object, action, args) {
     var controller = this.controller;
     if (!controller) return;
-    var handler = controller.handlers[action];
-    if (handler) {
-      handler(object, args);
+    var handler_id = controller.def.handlers[action];
+    if (handler_id) {
+      var handler = CPSSkins.Handlers[handler_id];
+      handler(this.model, object, args);
     }
   },
 

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
       Sun Jan 29 23:01:39 2006
@@ -14,6 +14,17 @@
 
 <body>
 
+  <ins class="controller">
+  {"id": "controller",
+   "handlers": {
+     "edit": "displayChoice",
+     "copy": "displayChoice",
+     "paste": "displayChoice",
+     "delete": "displayChoice"
+   }
+  }
+  </ins>
+
   <h1>CPSSkins: Contextual actions</h1>
 
   <div style="float: left; margin: 1em">
@@ -92,18 +103,12 @@
 
   <!-- Controller -->
   <script type="text/javascript">
-    function displayChoice(selected, choice) {
+    function displayChoice(model, context, choice) {
       $("message").innerHTML +=
-        selected.getAttribute('id') + ' =&gt; ' + choice + '\n';
+        context.getAttribute('id') + ' =&gt; ' + choice + '\n';
     }
 
-    new CPSSkins.Controller('controller').register({
-      'edit': displayChoice,
-      'copy': displayChoice,
-      'paste': displayChoice,
-      'delete': displayChoice,
-    })
-
+    CPSSkins.registerHandlers({'displayChoice': displayChoice});
   </script>
 
   <pre id="message"></pre>

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
  Sun Jan 29 23:01:39 2006
@@ -16,6 +16,19 @@
 
   <h1>CPSSkins Contextual menu</h1>
 
+  <ins class="controller">
+  {"id": "controller",
+   "handlers": {
+     "edit": "displayChoice",
+     "copy": "displayChoice",
+     "paste": "displayChoice",
+     "format": "displayChoice",
+     "delete": "displayChoice",
+     "size": "displayChoice"
+   }
+  }
+  </ins>
+
   <div style="float: left; margin: 1em">
 
     <!-- View: contextual menu widget -->
@@ -150,20 +163,12 @@
 
   <!-- Controller -->
   <script type="text/javascript">
-    function displayChoice(selected, choice) {
+    function displayChoice(model, context, choice) {
       $("message").innerHTML +=
-        selected.getAttribute('id') + ' =&gt; ' + choice + '\n';
+        context.getAttribute('id') + ' =&gt; ' + choice + '\n';
     }
 
-    new CPSSkins.Controller('controller').register({
-      'edit': displayChoice,
-      'copy': displayChoice,
-      'paste': displayChoice,
-      'format': displayChoice,
-      'delete': displayChoice,
-      'size': displayChoice
-    })
-
+    CPSSkins.registerHandlers({'displayChoice': displayChoice});
   </script>
 
   <pre id="message"></pre>

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
        (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/functional/cpsskins_observer_test.html
        Sun Jan 29 23:01:39 2006
@@ -78,20 +78,20 @@
 
     Object.extend(Widgets, {
 
-      counter: function(viewtag) {
+      counter: function(def) {
         var widget = Canvas.createNode({
           tag: "div",
           classes: "counter"
         });
-        return new Counter(widget, viewtag);
+        return new Counter(widget, def);
       },
 
-      progressbar: function(viewtag) {
+      progressbar: function(def) {
         var widget = Canvas.createNode({
           tag: "div",
           classes: "progressBar"
         });
-        return new ProgressBar(widget, viewtag);
+        return new ProgressBar(widget, def);
       }
 
     });

Modified: cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py      
(original)
+++ cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/browser.py      
Sun Jan 29 23:01:39 2006
@@ -6,8 +6,8 @@
 class Accessors(BrowserView):
 
     def getData1(self):
-        return json.write({'hint': 'Click here to open the document.'})
+        return json.write({'content': 'Enter some text'})
 
-    def setData1(self):
+    def setData1(self, data):
         # TODO
         pass

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/cpsskins_storage_adapters.pt
    Sun Jan 29 23:01:39 2006
@@ -11,20 +11,77 @@
   <link rel="stylesheet" href="/++skin++cpsskins/@@/++resource++cpsskins.css" 
type="text/css" />
 
   <style type="text/css">
-    pre {
+    div.inputbox {
       padding: 0.5em;
-    }
-    a {
-      border: 1px solid #999;
+      width: 180px;
+      border: 1px solid gray;
       background-color: #efc;
-      padding: 0.5em;
-      text-decoration: none;
     }
-    #area1 {
-      padding: 1em;
+    input {
     }
   </style>
 
+  <script type="text/javascript">
+
+    Object.extend(Widgets, {
+
+      inputbox: function(def) {
+        var widget = Canvas.createNode({
+          tag: "div",
+          classes: "inputbox"
+        });
+
+        return new InputBox(widget, def);
+      }
+
+    });
+
+    InputBox = Class.create();
+    InputBox.prototype = Object.extend(new CPSSkins.View(), {
+
+      setup: function() {
+        this.changeEvent = this.changeEvent.bindAsEventListener(this);
+        Event.observe(this.widget, "change", this.changeEvent);
+      },
+
+      render: function(data) {
+        var widget = this.widget;
+        widget.innerHTML = '';
+
+        var input = Canvas.createNode({
+          tag: "input",
+          attributes: {
+            "type": "text"
+          }
+        });
+
+        var content = Canvas.createNode({
+          tag: "div",
+        });
+        content.appendChild(document.createTextNode(data.content));
+
+        widget.appendChild(input);
+        widget.appendChild(content);
+      },
+
+      changeEvent: function(e) {
+        var target = Event.element(e);
+        var value = target.value;
+        this.handleAction(target, 'change', value);
+      }
+
+    });
+
+    /* Controller */
+
+    function changeContent(model, context, value) {
+      model.setData({'content': value});
+    }
+
+    CPSSkins.registerHandlers({'changeContent': changeContent});
+
+  </script>
+
 </head>
 <body>
 
@@ -34,29 +91,36 @@
      data.
   </p>
 
+  <ins class="controller">
+  {"id": "controller",
+   "handlers": {
+     "change": "changeContent"
+  }}
+  </ins>
 
   <div id="area1">
 
     <ins class="model">
-    {"data": {
-      "hint": ""
-      },
-      "storage": {
-        "type": "remote",
-        "accessors": {
-          "get": "@@getData1",
-          "set": "@@setData1"
-        }
-      }
+    {"id": "data-provider",
+     "data": {
+      "content": "..."
+     },
+     "storage": {
+       "type": "remote",
+       "accessors": {
+         "get": "@@getData1",
+         "set": "@@setData1"
+       }
+     }
     }
     </ins>
 
-    <a href="#">Open</a>
-
     <ins class="view">
     {"widget": {
-      "type": "tooltip"
-      }
+      "type": "inputbox"
+     },
+     "model": "data-provider",
+     "controller": "controller"
     }
     </ins>
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to