Author: jmorliaguet
Date: Fri Feb 10 13:59:02 2006
New Revision: 2336

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

- added support for CTAL view templates



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 10 
13:59:02 2006
@@ -232,14 +232,24 @@
         }
 
         case "view": {
-          var widget_type = def.widget.type;
+          var view;
+          var widget_type;
+
+          var template = def.widget.template;
+          if (template) {
+            widget_type = 'custom';
+          } else {
+            /* generic widget type */
+            widget_type = def.widget.type;
+          }
           if (widget_type && !(widget_type in Widgets)) {
             CPSSkins.warn("Unknown widget type: " + widget_type, el);
           }
+          factory = Widgets[widget_type];
+          view = factory(def);
+
           /* create the view */
-          var factory = Widgets[widget_type];
-          if (factory) {
-            var view = factory(def);
+          if (view) {
             view.id = index;
 
             /* register the observed model */
@@ -1156,6 +1166,13 @@
 if (!window.Widgets) { var Widgets = new Object(); }
 Object.extend(Widgets, {
 
+  custom: function(def) {
+    var widget = Canvas.createNode({
+      tag: "div"
+    });
+    return new CPSSkins.CustomWidget(widget, def);
+  },
+
   contextmenu: function(def) {
     var widget = Canvas.createNode({
       tag: "div",
@@ -1192,6 +1209,43 @@
   }
 });
 
+// Custom widget
+CPSSkins.CustomWidget = Class.create();
+CPSSkins.CustomWidget.prototype = Object.extend(new CPSSkins.View(), {
+
+  setup: function() {
+
+    var url = this.def.widget.template;
+    var view = this;
+
+    if (url) {
+      var evt_id = "loaded widget template";
+      var options = {
+        onComplete: function(req) {
+          view.source = req.responseText;
+          CPSSkins.notify(evt_id, {"target": view});
+        }
+      }
+      new Ajax.Request(url, options);
+
+      CPSSkins.registerEventHandler(evt_id, view, function(event) {
+        view.update();
+      });
+
+      CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
+    }
+
+  },
+
+  render: function(data) {
+    if (this.source) {
+      this.widget.innerHTML = this.source;
+      ctal.process_ctal(this.widget, data);
+    }
+  }
+
+});
+
 // Panels
 
 CPSSkins.Panel = Class.create();
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to