Author: jmorliaguet
Date: Sun Feb 12 15:53:53 2006
New Revision: 2365

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

- fixed the form controller to make it work with 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 Sun Feb 12 
15:53:53 2006
@@ -241,10 +241,13 @@
           } else {
             /* generic widget type */
             widget_type = def.widget.type;
+            if (!widget_type) {
+              CPSSkins.warn("Must specify a widget type or a template", el);
+            } else if (!(widget_type in Widgets)) {
+              CPSSkins.warn("Unknown widget type: " + widget_type, el);
+            }
           }
-          if (widget_type && !(widget_type in Widgets)) {
-            CPSSkins.warn("Unknown widget type: " + widget_type, el);
-          }
+
           factory = Widgets[widget_type];
           view = factory(def);
 
@@ -261,6 +264,8 @@
                 view.observe(model);
               });
               CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
+            } else {
+              CPSSkins.warn("Must specify a model for " + view.inspect(), el);
             }
 
             /* register the controller */
@@ -269,7 +274,7 @@
               var evt_id = "registered controller " + controller_id;
               CPSSkins.registerEventHandler(evt_id, view, function(event) {
                 var controller = event.target;
-                controller.register(view);
+                controller.control(view);
               });
               CPSSkins.subscribe(evt_id, {'subscriber': view, 'target': null});
             }
@@ -280,6 +285,8 @@
               var replaced = $(replace);
               if (replaced) {
                 replaced.parentNode.replaceChild(view.widget, replaced);
+              } else {
+                CPSSkins.warn("Unknown node id: " + replace, el);
               }
             } else {
               el.parentNode.insertBefore(view.widget, el);
@@ -381,7 +388,7 @@
     this.def = def;
   },
 
-  register: function(view) {
+  control: function(view) {
     /* to override */
   }
 
@@ -403,7 +410,7 @@
 CPSSkins.CommandController = Class.create();
 CPSSkins.CommandController.prototype = Object.extend(new 
CPSSkins.Controller(), {
 
-  register: function(view) {
+  control: function(view) {
 
     var controller = this;
     view.controller = controller;
@@ -434,26 +441,21 @@
 CPSSkins.FormController = Class.create();
 CPSSkins.FormController.prototype = Object.extend(new CPSSkins.Controller(), {
 
-  register: function(view) {
+  control: function(view) {
+    this.view = view;
     var controller = this;
     view.controller = controller;
 
-    var form = view.widget;
-
-    // prevent the browser from posting the form directly
-    form.setAttribute("onsubmit", "return false");
-
-    if (form.tagName.toLowerCase() != 'form') {
-      CPSSkins.warn("A form controller requires a form widget.", form);
-    }
+    var widget = view.widget;
 
     this.submitEvent = this.submitEvent.bindAsEventListener(this);
-    Event.observe(form, "submit", this.submitEvent);
+    Event.observe(widget, "submit", this.submitEvent);
   },
 
   submitEvent: function(e) {
-    var widget = Event.element(e);
-    var model = widget.view.model;
+    var view = this.view;
+    var model = this.view.model;
+    var widget = this.view.widget;
 
     var form_data = {};
     $A(Form.getInputs(widget)).each(function(i) {
@@ -465,7 +467,6 @@
 
 });
 
-
 // Identifiable DOM elements.
 if (!window.Identifiable) var Identifiable = new Object();
 Object.extend(Identifiable, {
@@ -1237,6 +1238,10 @@
 
   },
 
+  inspect: function() {
+    return "[Widget " + this.def.widget.template + "]";
+  },
+
   render: function(data) {
     if (this.source) {
       this.widget.innerHTML = this.source;
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to