cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject svn commit: r473974 - in /cocoon/trunk/blocks: cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/ cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/ cocoon-forms/cocoon-forms-impl/src/...
Date Sun, 12 Nov 2006 15:28:09 GMT
Author: jeremy
Date: Sun Nov 12 07:28:08 2006
New Revision: 473974

URL: http://svn.apache.org/viewvc?view=rev&rev=473974
Log:
Adding support for Dojo's IframeIO to CForms.
This allows forms with file-upload fields to be submitted as a background AJAX process. Currently
this is turned off for Safari where is is not working.

Added:
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl
Modified:
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsForm.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/common.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js?view=diff&rev=473974&r1=473973&r2=473974
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js
(original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js
Sun Nov 12 07:28:08 2006
@@ -38,66 +38,71 @@
 
 dojo.lang.extend(cocoon.ajax.BUHandler, {
     // Default highlight effect
-    highlight: null,
+	highlight: null,
     
-    processResponse: function(doc, request) {
-	    var nodes = doc.documentElement.childNodes;
-	    for (var i = 0; i < nodes.length; i++) {
-	        var node = nodes[i];
-	        if (node.nodeType == dojo.dom.ELEMENT_NODE) {
-	            var handler;
-	            if (node.localName) {
-	                handler = node.localName;
-	            } else {
-	                // No DOM2 support (IE6)
-	                handler = node.nodeName.replace(/.*:/, "");
-	            }
-	            var handlerFunc = this.handlers[handler];
-	            if (handlerFunc) {
-	                handlerFunc(node);
-	            } else {
-	                this.handleError("No handler found for element " + handler, request);
-	            }
-	        }
-	    }
+  processResponse: function(doc, request) {
+		var base = doc.documentElement;
+		
+		var nodes = [];
+		if (base.nodeName.toLowerCase() == "bu:document") {
+			nodes = base.childNodes;
+			dojo.debug("got response using: XMLHTTPTransport");
+		} else {
+			nodes = dojo.byId("browser-update", doc).childNodes;
+			dojo.debug("got response using: IframeTransport");
+		}
+		for (var i = 0; i < nodes.length; i++) {
+			var node = nodes[i];
+			if (node.nodeType == dojo.dom.ELEMENT_NODE) {
+				var handler = node.nodeName.replace(/.*:/, "").toLowerCase();
+				if (handler == "textarea") handler = node.getAttribute("name");
+				var handlerFunc = this.handlers[handler];
+				if (handlerFunc) {
+					handlerFunc(node);
+				} else {
+					this.handleError("No handler found for element " + handler, request);
+				}
+			}
+		}
 	},
 	
 	handleError: function(message, request) {
-	    if (confirm(message + "\nShow server response?")) {
-	        var w = window.open(undefined, "Cocoon Error", "location=no,resizable=yes,scrollbars=yes");
-	        if (w == undefined) {
-	            alert("You must allow popups from this server to display the response.");
-	        } else {
-		        var doc = w.document;
-		        doc.open();
-		        doc.write(request.responseText);
-		        doc.close();
-		    }
+		if (confirm(message + "\nShow server response?")) {
+			var w = window.open(undefined, "Cocoon Error", "location=no,resizable=yes,scrollbars=yes");
+			if (w == undefined) {
+				alert("You must allow popups from this server to display the response.");
+			} else {
+				var doc = w.document;
+				doc.open();
+				doc.write(request.responseText);
+				doc.close();
+			}
 		}
-    },
+	},
+
+	handlers: {
+		replace: function(element) {
+			var id = element.getAttribute("id");
+			if (!id) {
+				alert("no id found on update element");
+				return;
+			}    
+			// Get the first child element (the first child may be some text!)
+			var firstChild = dojo.dom.getFirstChildElement(element);
+			if (!firstChild && element.nodeName.toLowerCase() == "textarea") 
+				firstChild = dojo.dom.createDocumentFromText(element.value).documentElement;
+
+			var oldElement = document.getElementById(id);
+			
+			if (!oldElement) {
+				alert("no element '" + id + "' in source document");
+				return;
+			}
+			var newElement = cocoon.ajax.insertion.replace(oldElement, firstChild);
 
-    handlers: {
-        replace: function(element) {
-	        var id = element.getAttribute("id");
-	        if (!id) {
-	           alert("no id found on update element");
-	           return;
-	        }    
-	        // Get the first child element (the first child may be some text!)
-	        var firstChild = dojo.dom.getFirstChildElement(element);
-	    
-	        var oldElement = document.getElementById(id);
-	        
-	        if (!oldElement) {
-	            alert("no element '" + id + "' in source document");
-	            return;
-	        }
-	        
-	        var newElement = cocoon.ajax.insertion.replace(oldElement, firstChild);
-	        
-	        if (this.highlight) {
-	           this.highlight(newElement);
-	        }
+			if (this.highlight) {
+				this.highlight(newElement);
+			}
 		}
-    }
+	}
 });

Added: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl?view=auto&rev=473974
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl
(added)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl
Sun Nov 12 07:28:08 2006
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!--
+
+  This stylesheet is used to copy the BUTransformer's output into a data island in html
+  so that AJAX-type updates in CForms can use IoFrameTransport in Dojo which allows AJAX-style
file uploads etc.
+  
+-->
+
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:bu="http://apache.org/cocoon/browser-update/1.0"
+                exclude-result-prefixes="bu"
+                >
+
+<!-- this transformtion could be built-in to the BUTransformer -->
+
+	<xsl:template match="/">
+		<html>
+			<head><title>Browser Update Data-Island</title></head>
+			<body>
+				<xsl:apply-templates/>
+			</body>
+		</html>
+	</xsl:template>
+
+	<xsl:template match="bu:document">
+		<form  id="browser-update">
+			<xsl:apply-templates select="@*|*"/>
+		</form>
+	</xsl:template>	
+
+	<!-- wrap the BU Data in a textarea, nasty but widely compatible -->
+	<xsl:template match="bu:*">
+		<textarea name="{local-name()}" id="{@id}">
+			<xsl:apply-templates/>
+		</textarea>
+	</xsl:template>	
+
+  <xsl:template match="@*|node()" priority="-1">
+    <xsl:copy>
+      <xsl:apply-templates select="@*|node()"/>
+    </xsl:copy>
+  </xsl:template>
+
+</xsl:stylesheet>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsForm.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsForm.js?view=diff&rev=473974&r1=473973&r2=473974
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsForm.js
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsForm.js
Sun Nov 12 07:28:08 2006
@@ -1,4 +1,4 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -19,156 +19,166 @@
 dojo.require("dojo.widget.DomWidget");
 dojo.require("cocoon.ajax.BUHandler");
 
+
 /**
  * Dojo widget for forms, that handles the Ajax interaction with the server.
  *
+ * Extends the base DomWidget class. We don't need all the HtmlWidget stuff
+ * but need traversal of the DOM to build child widgets
+ *
  * @version $Id$
  */
-// Extends the base DomWidget class. We don't need all the HtmlWidget stuff
-// but need traversal of the DOM to build child widgets
-cocoon.forms.CFormsForm = function() {
-	dojo.widget.DomWidget.call(this);
-};
 
-dojo.inherits(cocoon.forms.CFormsForm, dojo.widget.DomWidget);
+dojo.widget.defineWidget(
+	"cocoon.forms.CFormsForm",
+	dojo.widget.DomWidget,
+	{
 
-dojo.lang.extend(cocoon.forms.CFormsForm, {
-	// Properties
-	
-	// Widget definition
+	// properties
 	widgetType: "CFormsForm",
-    isContainer: true,
-    buildRendering: function(args, parserFragment, parentWidget) {
-        // Magical statement to get the dom node, stolen in DomWidget
-	    this.domNode = parserFragment["dojo:"+this.widgetType.toLowerCase()].nodeRef;
-
-        this.id = this.domNode.getAttribute("id");
-
-        this.domNode.setAttribute("dojoWidgetId", this.widgetId);
-
-        dojo.event.connect("around", this.domNode, "onsubmit", this, "_browserSubmit");
-        dojo.event.connect(this.domNode, "onclick", this, "_grabClickTarget");
-    },
-
-    _grabClickTarget: function(event) {
-        // Keep targets of onclick so that we can know what input triggered the submit
-        // (the event in onsubmit() is the HTMLFormElement).
-        this.lastClickTarget = dojo.html.getEventTarget(event);
-    },
-
-    /** Connected to the forms 'onsubmit' event, called when the user clicks a submit input
*/
-    _browserSubmit: function(invocation) {
-        if (invocation.proceed() == false) {
-            // onsubmit handlers stopped submission
-            return false;
-        }
-
-        var event = invocation.args[0] || window.event;
-        // Interestingly, FF provides the explicitOriginalTarget property that can avoid
-        // grabClickTarget above, but avoid browser specifics for now.
-        var target = /*event.explicitOriginalTarget ||*/ this.lastClickTarget;
-
-        this.submit(target && target.name);
-        // If real submit has to occur, it's taken care of in submit()
-        return false;
-    },
-
-    /**
-     * Submit the form, choosing automatically Ajax or fullpage mode depending on the
-     * widgets in the form.
-     *
-     * @param name the name of the widget that triggered the submit (if any)
-     * @param params an object containing additional parameters to be added to the
-     *        query string (optional)
-     */
-    submit: function(name, params) {
-        var form = this.domNode;
-
-        var query = cocoon.forms.buildQueryString(form, name);
-        if (!query) {
-            if (params) alert("FIXME: handle additional params in CFormsForm.submit()");
-            // Some inputs are not ajax-compatible. Fall back to full page reload
-            form["forms_submit_id"].value = name;
-            form.submit();
-            return;
-        }
-        
-        query += cocoon.forms.encodeParams(params, true);
-
-        // Provide feedback that something is happening.
-        document.body.style.cursor = "wait";
-
-        // The "ajax-action" attribute specifies an alternate submit location used in Ajax
mode.
-        // This allows to use Ajax in the portal where forms are normally posted to the portal
URL.
-        var uri = form.getAttribute("ajax-action");
-        if (!uri) uri = form.action;
-        if (uri == "") uri = document.location;
-        
-        // FIXME: revisit with dojo.io.bind(), but need to see what happens if we say
-        // mimetype="text/xml" and no XML is sent back
-        var req = dojo.hostenv.getXmlhttpObject()
-
-        req.open("POST", uri, true);
-        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
-        var thisWidget = this;
-        req.onreadystatechange = function() {
-            if (req.readyState == 4) {
-                thisWidget._handleBrowserUpdate(req);
-            }
-        }
-        req.send(query);
-    },
+  isContainer: true,
+    
+	// Widget definition
+	buildRendering: function(args, parserFragment, parentWidget) {
+		// Magical statement to get the dom node, stolen in DomWidget
+		this.domNode = parserFragment["dojo:"+this.widgetType.toLowerCase()].nodeRef;
+		this.id = this.domNode.getAttribute("id");
+		this.domNode.setAttribute("dojoWidgetId", this.widgetId);
+		dojo.event.connect("around", this.domNode, "onsubmit", this, "_browserSubmit");
+		dojo.event.connect(this.domNode, "onclick", this, "_grabClickTarget");
+	},
+
+	_grabClickTarget: function(event) {
+		// Keep targets of onclick so that we can know what input triggered the submit
+		// (the event in onsubmit() is the HTMLFormElement).
+		this.lastClickTarget = dojo.html.getEventTarget(event);
+	},
+
+	/** Connected to the forms 'onsubmit' event, called when the user clicks a submit input
*/
+	_browserSubmit: function(invocation) {
+		if (invocation.proceed() == false) {
+			// onsubmit handlers stopped submission
+			return false;
+		}
+		var event = invocation.args[0] || window.event;
+		// Interestingly, FF provides the explicitOriginalTarget property that can avoid
+		// grabClickTarget above, but avoid browser specifics for now.
+		var target = /*event.explicitOriginalTarget ||*/ this.lastClickTarget;
+		this.submit(target && target.name);
+		// If real submit has to occur, it's taken care of in submit()
+		return false;
+	},
+
+	/**
+	 * Submit the form, choosing the right transport depending on the widgets in the form.
+	 *
+	 * @param name the name of the widget that triggered the submit (if any)
+	 * @param params an object containing additional parameters to be added to the
+	 *        query string (optional)
+	 */
+	submit: function(name, params) {
+		var form = this.domNode;                  /* the form node */
+		var thisWidget = this;                    /* closure magic for the callback handler */
+		var mimetype = "text/xml";		            /* the default mime-type */
+		if (!params) params = {};                 /* create if not passed */
+		
+		// Provide feedback that something is happening.
+		document.body.style.cursor = "wait";
+		
+		// The "ajax-action" attribute specifies an alternate submit location used in Ajax mode.
+		// This allows to use Ajax in the portal where forms are normally posted to the portal
URL.
+		var uri = form.getAttribute("ajax-action");
+		if (!uri) uri = form.action;
+		if (uri == "") uri = document.location;
+
+		form["forms_submit_id"].value = name;     /* name of the button doing the submit */
+		params["cocoon-ajax"] = true;             /* tell Cocoon we want AJAX-style browser updates
*/
+		if (dojo.io.formHasFile(form)) {          /* check for file-upload fields */
+			if (dojo.render.html.safari) {          /* poor old safari, hopefully Apple will fix this
soon, it works in the nightly builds of WebKit (2006-10-11) */
+				form.submit();                        /* do a full-page submit */
+				return;
+			}
+			dojo.require("dojo.io.IframeIO");       /* using IframeIO as we have file-upload fields
*/
+			mimetype = "text/html";                 /* a different mime-type is required for IframeIO
*/
+		}
+
+		dojo.io.bind({
+			url: uri,
+			handle: function(type, data, evt) { thisWidget._handleBrowserUpdate(thisWidget, name,
type, data, evt) },
+			method: "post",
+			mimetype: mimetype,                     /* the mimetype of the response */
+			content: params,                        /* add extra params to the form */
+			formNode: form,                         /* the form */
+			sendTransport: true                     /* tell cocoon what transport we are using */
+		});
+		// Toggle the click target off, so it does not get resubmitted if another submit is fired
before this has finished
+		// NB. This must be done after the form is assembled by dojo, or certain onChange handlers
may fail
+		// Avoid the use of widget.lastClickTarget as it may already be out of date
+		if (form[name]) form[name].disabled = true;
+	},
     
-    /**
-     * Handle the server response
-     */
-    _handleBrowserUpdate: function(request) {
-	    // Restore normal cursor
-	    document.body.style.cursor = "auto";
-        var updater = new cocoon.ajax.BUHandler();
-	    if (request.status == 200) {
-            // Handle browser update directives
-            var doc = request.responseXML;
-            if (!doc) {
-                cocoon.ajax.BUHandler.handleError("No xml answer", request);
-                return;
-            }
-            
-            var thisWidget = this;
-            updater.handlers['continue'] = function() { thisWidget._continue(); }
-            updater.processResponse(doc, request);
-	    } else {
-	        updater.handleError("Request failed - status=" + request.status, request);
-	    }
+	/**
+	 * Handle the server response
+	 */
+	_handleBrowserUpdate: function(widget, name, type, data, evt) {		
+		// Restore normal cursor
+		document.body.style.cursor = "auto";
+		// Attempt to re-enable the click target
+		if (this.domNode[name]) this.domNode[name].disabled = false;
+		
+		var updater = new cocoon.ajax.BUHandler();
+		if (type == "load") {
+			// Handle browser update directives
+			if (!data) {
+				cocoon.ajax.BUHandler.handleError("No xml answer", evt);
+				return;
+			}
+			updater.handlers['continue'] = function() { widget._continue(); }
+			updater.processResponse(data, evt);
+		} else if (type == "error") {
+			updater.handleError("Request failed", evt);
+		} else {
+			// umm, how did we get here ?
+		}
 	},
 	
 	_continue: function() {
-	    var form = this.domNode;
-	    if (form.method.toLowerCase() == "post") {
-	        // Create a fake form and post it
-	        var div = document.createElement("div");
-	        var content = "<form action='" + form.action + "' method='POST'>" +
-	                  "<input type='hidden' name='cocoon-ajax-continue' value='true'/>";
-		    if (form.elements["continuation-id"]) {
-		        content += "<input type='hidden' name='continuation-id' value='" +
-		            form.elements["continuation-id"].value + "'/>";
-		    }
-		    content += "</form>";
-		    div.innerHTML = content;
-		    document.body.appendChild(div);
-		    div.firstChild.submit();
-	    } else {	    
-	        // Redirect to the form's action URL
-		    var contParam = '?cocoon-ajax-continue=true';
-		    if (form.elements["continuation-id"]) {
-		        contParam += "&continuation-id=" + form.elements["continuation-id"].value;
-		    }
-		    window.location.href = form.action + contParam;
+		//alert("_continue()");
+		var form = this.domNode;
+		if (form.method.toLowerCase() == "post") {
+			// Create a fake form and post it
+			var div = document.createElement("div");
+			var content = "<form action='" + form.action + "' method='POST'>" +
+								"<input type='hidden' name='cocoon-ajax-continue' value='true'/>";
+			if (form.elements["continuation-id"]) {
+				content += "<input type='hidden' name='continuation-id' value='" +
+						form.elements["continuation-id"].value + "'/>";
+			}
+			content += "</form>";
+			div.innerHTML = content;
+			document.body.appendChild(div);
+			div.firstChild.submit();
+		} else {	    
+			// Redirect to the form's action URL
+			var contParam = '?cocoon-ajax-continue=true';
+			if (form.elements["continuation-id"]) {
+				contParam += "&continuation-id=" + form.elements["continuation-id"].value;
+			}
+			window.location.href = form.action + contParam;
 		}
 	}
+	
 });
 
-dojo.widget.tags.addParseTreeHandler("dojo:CFormsForm");
-// Register this module as a widget package
-dojo.widget.manager.registerWidgetPackage("cocoon.forms");
-
+// override built-in dojo function, we do not care about 'file' fields that are disabled
+dojo.io.checkChildrenForFile = function(node) {
+	var hasFile = false;
+	var inputs = node.getElementsByTagName("input");
+	dojo.lang.forEach(inputs, function(input){
+		if(hasFile){ return; }
+		if(input.getAttribute("type")=="file" && !input.disabled){
+			hasFile = true;
+		}
+	});
+	return hasFile;
+}

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/common.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/common.js?view=diff&rev=473974&r1=473973&r2=473974
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/common.js
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/common.js
Sun Nov 12 07:28:08 2006
@@ -1,10 +1,9 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
@@ -44,113 +43,32 @@
  * Submits a form. If ajax mode is on and the browser is ajax-aware, the page isn't reloaded
  */
 cocoon.forms.submitForm = function(element, name) {
-    var form = this.getForm(element);
-    if (form == null) {
-        alert("Cannot find form for " + element);
-        return;
-    }
+	var form = this.getForm(element);
+	if (form == null) {
+			alert("Cannot find form for " + element);
+			return;
+	}
 
-    if (!name) name = element.name;
+	if (!name) name = element.name;
 
 	var dojoId = form.getAttribute("dojoWidgetId");
-    if (dojoId) {
-        // Delegate to the CFormsForm widget
-        dojo.widget.byId(dojoId).submit(name);
-
-    } else {
-        // Regular submit. How old-fashioned :-)
-        
-        // Send the identifier of the widget that triggered the submit
-        form["forms_submit_id"].value = name;
-
-        // A form's onsubmit is only called when submit is triggered by user action, but
not when
-        // called by a script. So don't forget to call it, cancelling the submit if (and
only if)
-        // it returns false
-	    if (!form.onsubmit || form.onsubmit() != false) {
-	        form.submit();
-	    }
+	if (dojoId) {
+		// Delegate to the CFormsForm widget
+		dojo.widget.byId(dojoId).submit(name);
+	} else {
+			// Regular submit. How old-fashioned :-)
+			
+			// Send the identifier of the widget that triggered the submit
+			form["forms_submit_id"].value = name;
+
+			// A form's onsubmit is only called when submit is triggered by user action, but not when
+			// called by a script. So don't forget to call it, cancelling the submit if (and only
if)
+			// it returns false
+		if (!form.onsubmit || form.onsubmit() != false) {
+				form.submit();
+		}
 	}
 }
 
 // Override the default forms_submitForm
 forms_submitForm = function() { cocoon.forms.submitForm.apply(cocoon.forms, arguments) };
-
-/**
- * Build a query string with all form inputs.
- *
- * @parameter form the form element
- * @parameter submitId the ID of the widget that submitted the form
- * @return the query string for the form, or null if some inputs cannot be
- *         send in Ajax mode (e.g. file inputs)
- */
-cocoon.forms.buildQueryString = function(form, submitId) {
-    // Indicate to the server that we're in ajax mode
-    var result = "cocoon-ajax=true";
-
-    // If the form has a forms_submit_id input, use it to avoid sending the value twice
-    if (form["forms_submit_id"]) {
-        if (submitId)
-            form["forms_submit_id"].value = submitId;
-        else
-            form["forms_submit_id"].value = null;
-    } else {
-        if (submitId) result += "&forms_submit_id=" + submitId;
-    }
-
-    // Iterate on all form controls
-    for (var i = 0; i < form.elements.length; i++) {
-        input = form.elements[i];
-        
-        if (!input.name) continue; // ignore inputs with no name
-
-        if (typeof(input.type) == "undefined") {
-        	    // Skip fieldset
-            continue;
-        }
-        if (input.type == "submit" || input.type == "image" || input.type == "button") {
-            // Skip buttons
-            continue;
-        }
-        if ((input.type == "checkbox" || input.type == "radio") && !input.checked)
{
-            // Skip unchecked checkboxes and radio buttons
-            continue;
-        }
-        if (input.type == "file") {
-            // Can't send files in Ajax mode. Fall back to full page
-            return null;
-        }
-        if (input.tagName.toLowerCase() == "select" && input.multiple) {
-            var name = encodeURIComponent(input.name);
-            var options = input.options;
-            for (var zz = 0; zz < options.length; zz++) {
-                if (options[zz].selected) {
-                    result += "&" + name + "=" + encodeURIComponent(options[zz].value);
-                }
-            }
-            // don't use the default fallback
-            continue;
-        }
-        
-        // text, passwod, textarea, hidden, single select
-        result += "&" + encodeURIComponent(input.name) + "=" + encodeURIComponent(input.value);
-    }
-    return result;
-}
-
-/**
- * Encode an object as querystring parameters.
- *
- * @parameter params the object to encode
- * @isAppending if true, "&" is prepended to the result
- * @return the querystring
- */
-cocoon.forms.encodeParams = function(params, isAppending) {
-    if (!params) return "";
-    var result = "";
-    var sep = isAppending ? "&" : "";
-    for (var name in params) {
-        result += sep + encodeURIComponent(name) + "=" + encodeURIComponent(params[name]);
-        sep = "&";
-    }
-    return result;
-}

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap?view=diff&rev=473974&r1=473973&r2=473974
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap
(original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap
Sun Nov 12 07:28:08 2006
@@ -238,8 +238,21 @@
        </map:transform>
        <map:select type="ajax-request">
          <map:when test="true">
-           <map:serialize type="xml"/>
+         		<map:select type="request-parameter">
+  						<map:parameter name="parameter-name" value="dojo.transport"/>
+         			<map:when test="iframe">
+         				<map:transform src="resource://org/apache/cocoon/forms/resources/IframeTransport-bu-styling.xsl"/><!---->
+         				<map:serialize type="xhtml"/><!-- this is REALLY important -->
+         			</map:when>
+         			<map:otherwise>
+								<map:serialize type="xml"/>
+         			</map:otherwise>
+         		</map:select>
          </map:when>
+       <!--<map:select type="ajax-request">
+         <map:when test="true">
+           <map:serialize type="xml"/>
+         </map:when>-->
          <map:otherwise>
            <map:serialize type="html"/>
          </map:otherwise>



Mime
View raw message