Author: jmorliaguet
Date: Fri Apr 14 23:48:24 2006
New Revision: 2850

Modified:
   cpsskins/branches/jmo-perspectives/ui/framework/cpsskins.js
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/form.pt
Log:

- updated the remote scripting controller to make it intercept form actions
  so that the page does not get reloaded when a form is submitted.

  (TODO: fix file upload which requires an IFRAME)



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 Apr 14 
23:48:24 2006
@@ -598,14 +598,30 @@
 
   setup: function() {
     this.clickEvent = this.clickEvent.bindAsEventListener(this);
+    this.submitEvent = this.submitEvent.bindAsEventListener(this);
   },
 
   register: function(view) {
     Event.observe(view.widget, "click", this.clickEvent);
+    Event.observe(view.widget, "submit", this.submitEvent);
   },
 
   unregister: function(view) {
     Event.stopObserving(view.widget, "click", this.clickEvent);
+    Event.stopObserving(view.widget, "submit", this.clickEvent);
+  },
+
+  submitEvent: function(e) {
+    var target = Event.findElement(e, 'form');
+    if (target && target != document) {
+      var url = target.getAttribute('action');
+      var params = Form.serialize(target);
+      if (params) {
+        url += '?' + params;
+      }
+      this._call(target, url);
+      Event.stop(e);
+    }
   },
 
   clickEvent: function(e) {
@@ -614,18 +630,23 @@
       target = Event.findElement(e, 'a');
     }
     if (target && target != document) {
-      var _request = this._request;
-      var views = this.views;
-      views.entries().each(function(v) {
-        var view = CPSSkins.getViewById(v);
-        if (target.childOf(view.widget)) {
-          _request(views, view, target.href);
-        }
-      });
+      this._call(target, target.href);
       Event.stop(e);
     }
   },
 
+  _call: function(target, url) {
+    if (!url) return;
+    var _request = this._request;
+    var views = this.views;
+    views.entries().each(function(v) {
+      var view = CPSSkins.getViewById(v);
+      if (target.childOf(view.widget)) {
+        _request(views, view, url);
+      }
+    });
+  },
+
   _request: function(views, view, url) {
     var options = {
       onComplete: function(req) {

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/cpsskins_panels.pt
    Fri Apr 14 23:48:24 2006
@@ -43,12 +43,6 @@
 
   <ins class="model">
   {"id": "panel",
-   "storage": {
-     "type": "remote",
-     "accessors": {
-       "set": "@@doSomething"
-     }
-   },
    "data": {
      "url": "@@panels-form.html",
      "form": {}
@@ -57,12 +51,6 @@
 
   <ins class="model">
   {"id": "panel2",
-   "storage": {
-     "type": "remote",
-     "accessors": {
-       "set": "@@doSomething"
-     }
-   },
    "data": {
      "url": "@@panels-form.html",
      "form": {}
@@ -74,7 +62,7 @@
     {"id": "panel-view",
      "model": "panel",
      "perspectives": ["default"],
-     "controllers": ["show-panel", "form", "request1"],
+     "controllers": ["show-panel", "request1"],
      "widget": {
        "type": "panel"
      },
@@ -90,7 +78,7 @@
     {"id": "panel-view-2",
      "model": "panel2",
      "perspectives": ["default"],
-     "controllers": ["show-panel", "form2", "request2"],
+     "controllers": ["show-panel", "request2"],
      "widget": {
        "type": "panel"
      },
@@ -102,17 +90,6 @@
   </div>
 
   <ins class="controller">
-  {"id": "form",
-   "type": "form"
-  }
-  </ins>
-
-  <ins class="controller">
-  {"id": "form2",
-   "type": "form"
-  }
-  </ins>
-  <ins class="controller">
   {"id": "request1",
    "type": "remote scripting"
   }

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/form.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/form.pt
       (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/panels/form.pt
       Fri Apr 14 23:48:24 2006
@@ -1,4 +1,4 @@
-<form action="" method="get" onsubmit="return false"
+<form action="@@doSomething" method="get" onsubmit="return false"
   tal:define="updated request/form/updated|nothing">
 
   <div tal:condition="not:updated">
@@ -16,4 +16,8 @@
     I have just been updated!
   </p>
 
+  <p>
+    <input type="hidden" name="param" value="1" />
+  </p>
+
 </form>
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to