Author: jmorliaguet
Date: Wed May  3 00:06:39 2006
New Revision: 3030

Modified:
   cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
Log:

- Remote Scripting controller: added support for file uploads. If the form
  contains a file input widget, an <iframe> will be created on-the-fly.
  (existing ZPTs do not need to be modified)



Modified: cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js
==============================================================================
--- cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    
(original)
+++ cpsskins/branches/paris-sprint-2006/lib/cpsskins/src/cpsskins.js    Wed May 
 3 00:06:39 2006
@@ -611,20 +611,50 @@
     Event.stopObserving(view.widget, "submit", this.submitEvent);
   },
 
+  refreshViews: function() { 
+    this.views.entries().each(function(v) {
+      CPSSkins.getViewById(v).refresh();
+    });
+  },
+
   submitEvent: function(e) {
     var target = Event.findElement(e, 'form');
     if (target && target != document) {
-      var method = target.getAttribute('action');
-      var params = Form.serialize(target);
-      if (!method) 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, method, params);
-        }
-      });
+      var form = target;
+
+      if (Form.getInputs(form, 'file').length > 0) {
+        /* The form contains a file input, use an IFrame */
+        var id = 'uploadIFrame';
+        var onUploaded = "window.parent.CPSSkins.getControllerById('" +
+                         this.def.id + "').refreshViews()";
+        var iframe = CPSSkins.Canvas.createNode({
+          tag: "iframe",
+          style: {display: 'none'},
+          attributes: {
+            id: id,
+            name: id,
+            onload: onUploaded
+            }
+        });
+        form.appendChild(iframe);
+        form.target = id;
+        return false;
+
+      } else {
+        /* AJAX request */
+        var method = form.getAttribute('action');
+        var params = Form.serialize(form);
+        if (!method) return;
+        var _request = this._request;
+        var views = this.views;
+        views.entries().each(function(v) {
+          var view = CPSSkins.getViewById(v);
+          if (form.childOf(view.widget)) {
+            _request(views, view, method, params);
+          }
+        });
+      }
+
       Event.stop(e);
     }
   },
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to