cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jer...@apache.org
Subject svn commit: r491930 [1/2] - in /cocoon/trunk/blocks: cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/ cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/ cocoon-ajax/cocoon-ajax-impl/src...
Date Tue, 02 Jan 2007 20:44:32 GMT
Author: jeremy
Date: Tue Jan  2 12:44:30 2007
New Revision: 491930

URL: http://svn.apache.org/viewvc?view=rev&rev=491930
Log:
Update Dojo to 0.4.1, use namespaces for loading widgets, cleanup of client-side libraries, deprecation and replacement of functions in forms_lib.js cocoon.js CFormsForm.js, all cforms forms now use a dojo widget, fixes to forms and ajax samples.

Added:
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js   (with props)
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.4.1-ajax.zip   (with props)
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js   (with props)
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js   (with props)
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/manifest.js   (with props)
Removed:
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.3.1-widget.zip
Modified:
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/cocoon.js
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/BUHandler.js
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/FormUploadProgress.js
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/PartialLink.js
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/common.js
    cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-calendar-styling.xsl
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-htmlarea-styling.xsl
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsDragAndDropRepeater.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/CFormsRepeater.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsSuggest.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-impl/src/main/resources/org/apache/cocoon/forms/resources/js/forms-lib.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/captcha/sitemap.xmap
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/dreamteam/content/showTeam.jx
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/dreamteam/flow/team.js
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/dreamteam/sitemap.xmap
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/ajax_suggest_form.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/ajax_suggest_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/calculatedfields_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/carselector_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/datasource_chooser_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/dynamicrepeater_dojo_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/dynamicrepeater_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/dynamicrepeaters_dojo_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/file_explorer_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/form1_success_jx.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/inplace_edit_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/multipage_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/sampletree_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/upload_model.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/upload_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/forms/uploadprogress_template.xml
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/library/sitemap.xmap
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/sitemap.xmap
    cocoon/trunk/blocks/cocoon-forms/cocoon-forms-sample/src/main/resources/COB-INF/welcome.xml

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/cocoon.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/cocoon.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/cocoon.js (original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/cocoon.js Tue Jan  2 12:44:30 2007
@@ -36,6 +36,7 @@
 
 // Setup hooks to load JS files provided by Cocoon blocks
 (function() {
+    dojo.debug("DEPRECATED: We now use dojo 0.4.1 with namespace registration, please see the samples.");
     // base path is "resources/dojo". Move to back to "resources"
     var rsrcPath = "../";
   

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=491930&r1=491929&r2=491930
==============================================================================
--- 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 Tue Jan  2 12:44:30 2007
@@ -16,7 +16,7 @@
  */
 
 /**
- * General purpose AJAX infrastructure to handle a BU ("browser update") response
+ * General purpose AJAX infrastructure to handle a BU (browser update) response
  *
  * To add a new handler for a given request, create a new BUHandler and update its
  * handlers property.
@@ -24,24 +24,21 @@
  * @version $Id$
  */
 
+dojo.provide("cocoon.ajax.BUHandler");
 dojo.require("dojo.dom");
 dojo.require("dojo.html");
+dojo.require("cocoon.ajax.common");
 dojo.require("cocoon.ajax.insertion");
-dojo.provide("cocoon.ajax.BUHandler");
 
 cocoon.ajax.BUHandler = function() { };
 
-cocoon.ajax.BUHandler.fade = function(node) {
-    dojo.require("dojo.fx.*");
-    dojo.fx.highlight(element, dojo.graphics.color.hex2rgb("#ffc"), 700, 300);
-}
+// Default highlight effect (none)
+cocoon.ajax.BUHandler.highlight = null;
 
 dojo.lang.extend(cocoon.ajax.BUHandler, {
-    // Default highlight effect
-	highlight: null,
     
-  processResponse: function(doc, request) {
-		var base = doc.documentElement;
+    processResponse: function(doc) {
+		var base = doc.documentElement;		
 		
 		var nodes = [];
 		if (base.nodeName.toLowerCase() == "bu:document") {
@@ -109,9 +106,9 @@
 			}
 			var newElement = cocoon.ajax.insertion.replace(oldElement, firstChild);
 
-			if (this.highlight) {
-				this.highlight(newElement);
+			if (typeof(cocoon.ajax.BUHandler.highlight) == "function") {
+				cocoon.ajax.BUHandler.highlight(newElement);
 			}
 		}
-	}
-});
\ No newline at end of file
+	}	
+});

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/FormUploadProgress.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/FormUploadProgress.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/FormUploadProgress.js (original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/FormUploadProgress.js Tue Jan  2 12:44:30 2007
@@ -30,26 +30,27 @@
 dojo.provide("cocoon.ajax.FormUploadProgress");
 dojo.require("dojo.event");
 dojo.require("dojo.widget.HtmlWidget");
-dojo.require("dojo.animation.Timer");
+dojo.require("dojo.lang.timing.Timer");
 
 dojo.widget.defineWidget(
     "cocoon.ajax.FormUploadProgress",
     dojo.widget.HtmlWidget,
     {
         // override properties (these may be overridden by using the same-named attributes on the widget tag)
-        background: "",      // the colour of the progress bar
-        color: "",           // the colour of the text and border
-        ready: "Ready.",     // Strings the widget needs, that may require external i18n transformation
+        background: "#BFCCDF",      // the colour of the progress bar
+        color: "#336699",           // the colour of the text and border
+        ready: "Ready.",            // Strings the widget needs, that may require external i18n transformation
         connecting: "Connecting ...",
         
         // widget API properties
+        ns: "forms",
         widgetType: "FormUploadProgress",
         isContainer: true,
         templateString: '<div class="FormUpload">' +
                             '<div class="FormUploadUser" dojoAttachPoint="containerNode"></div>' + 
-                            '<div class="FormUploadProgress" style="border:1px solid #336699;margin:2px;height: 16px;position:relative;">' +
-                                '<div style="width:0px;background:#BFCCDF;position:absolute;top:0;left:0;width:0;right:0;" class="bar" dojoAttachPoint="barNode">&nbsp;</div>' + 
-                                '<div style="color:#336699;position:absolute;top:0;left:0;bottom:0;right:0;background:none;padding:2px;font-size:10px;overflow:hidden;" class="data" dojoAttachPoint="msgNode">&nbsp;</div>' + 
+                            '<div class="FormUploadProgress" style="border:1px solid ${this.color};margin:2px;height: 16px;position:relative;">' +
+                                '<div style="width:0px;background:${this.background};position:absolute;top:0;left:0;width:0;right:0;" class="bar" dojoAttachPoint="barNode">&nbsp;</div>' + 
+                                '<div style="color:${this.color};position:absolute;top:0;left:0;bottom:0;right:0;background:none;padding:2px;font-size:10px;overflow:hidden;" class="data" dojoAttachPoint="msgNode">${this.ready}</div>' + 
                             '</div>' +
                          '</div>',
                         
@@ -60,53 +61,45 @@
         
         // private properties
         _form: null,           // this widget's form
-        _target: null,         // the form's widget
+        _target: null,         // the form's *Form widget
         _timer: null,          // timer for periodical updates
         _busy: false,          // busy getting the status
         _delay: 2000,          // 2 secs between status calls
         
         // widget interface
         postCreate: function(){
-            // optional styling
-            if (this.background) this.barNode.style.background = this.background;
-            if (this.color) {
-                this.barNode.parentNode.style.borderColor = this.color;
-                this.msgNode.style.color = this.color;
-            }
             // work out where to attach the event listener
             this._form = dojo.dom.getFirstAncestorByTag(this.domNode, "form");
             if (this._form) {
                 var dojoId = this._form.getAttribute("dojoWidgetId");
                 var formWidget = dojo.widget.byId(dojoId);
-                if (formWidget) { // use the CFormsForm Widget if there is one
+                if (formWidget) { // use the *Form Widget if there is one
                     this._target = formWidget;
                     dojo.event.connect("after", this._target, "submit", this, "_startUpload");
                 } else { // otherwise use the form itself
                     dojo.event.connect("after", this._form, "onsubmit", this, "_startUpload");
                 }
             } else {
-                dojo.debug("WARNING: The FormUploadProgress widget may only be used inside a form.");
+                throw new Error("The FormUploadProgress widget may only be used inside a form.");
             }
-            this.msgNode.innerHTML = this.ready;
         },
     
         // widget interface
         destroy: function(){
             if (this._target) {
                 dojo.event.disconnect("after", this._target, "submit", this, "_startUpload");
-            } else {
-                if (this._form) dojo.event.disconnect("after", this._form, "onsubmit", this, "_startUpload");
+            } else if (this._form) {
+                dojo.event.disconnect("after", this._form, "onsubmit", this, "_startUpload");
             }
         },
 
         // private widget funtions
 
-        // event handler should fire after the forms starts submitting
+        // event handler, should fire after the forms starts submitting
         _startUpload: function(event) {
             if (this._checkForActiveFile(this._form)) {
-                var self = this;
-                this._timer = new dojo.animation.Timer(this._delay);
-                this._timer.onTick = function() { self._getStatus() };
+                this._timer = new dojo.lang.timing.Timer(this._delay);
+                this._timer.onTick = dojo.lang.hitch(this, function() { this._getStatus() });
                 this._timer.onStart = this._timer.onTick;
                 this._timer.start();
                 this.msgNode.innerHTML = this.connecting;
@@ -116,25 +109,24 @@
         // get the current upload status from Cocoon
         _getStatus: function() {
             if (this._busy) return; // only one request at a time
-            var self = this;
             dojo.io.bind({
                 url: new dojo.uri.Uri(djConfig["baseRelativePath"], "../../../_cocoon/system/ajax/upload/status"),
                 mimetype: "text/json",
-                handle: function(type, data, evt) {
+                handle: dojo.lang.hitch(this, function(type, data, evt) {
                     if (type == "load") {
-                        if (!data) return;
-                        self._update(data);
-                        self._busy = false;
+                        this._update(data);
+                        this._busy = false;
                     } else if (type == "error") {
                         dojo.debug("FormUploadProgress - status request failed");
                     }           
-                }
+                })
             });
             this._busy = true;
         },
 
         // perform the display update
         _update: function(status) {
+            if (!status) return;
             if (status.sent) {
                 if (status.finished) {
                     this.barNode.style.width = "100%";
@@ -146,7 +138,7 @@
             if (status.message) this.msgNode.innerHTML = status.message;
         },
 
-        // look to see if there are active file-upload fields in the form
+        // look to see if there are active (file has been chosen) file-upload fields in the form
         _checkForActiveFile: function(node) {
             var hasFile = false;
             var inputs = node.getElementsByTagName("input");

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/PartialLink.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/PartialLink.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/PartialLink.js (original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/PartialLink.js Tue Jan  2 12:44:30 2007
@@ -17,7 +17,6 @@
 dojo.provide("cocoon.ajax.PartialLink");
 
 dojo.require("dojo.widget.DomWidget");
-dojo.require("dojo.io");
 dojo.require("cocoon.ajax.common");
 
 /**
@@ -26,25 +25,21 @@
  * @version $Id$
  */
 
-cocoon.ajax.PartialLink = function() {
-	dojo.widget.DomWidget.call(this);
-};
-
-dojo.inherits(cocoon.ajax.PartialLink, dojo.widget.DomWidget);
-
-dojo.lang.extend(cocoon.ajax.PartialLink, {
+dojo.widget.defineWidget(
+    "cocoon.ajax.PartialLink",
+    dojo.widget.DomWidget,
+ {
 	// Properties
 	href: "",
 	target: "",
 	
 	// Widget definition
+	ns: "forms",
 	widgetType: "PartialLink",
-    isContainer: true,
+    isContainer: false,
+    preventClobber: true, // don't clobber our node
     
-    buildRendering: function(args, parserFragment, parentWidget) {
-
-        // Magical statement to get the dom node, stolen in DomWidget
-	    this.domNode = parserFragment["dojo:"+this.widgetType.toLowerCase()].nodeRef;
+    fillInTemplate: function(args, frag) {
 
 	    if (this.target.indexOf("#") < 0) {
 	        dojo.debug("PartialLink: wrong value for 'target' attribute: " + this.target);
@@ -60,8 +55,4 @@
         cocoon.ajax.update(_this.href, _this.target);
     }
 });
-
-dojo.widget.tags.addParseTreeHandler("dojo:PartialLink");
-// Register this module as a widget package
-dojo.widget.manager.registerWidgetPackage("cocoon.ajax");
 

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/common.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/common.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/common.js (original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/js/common.js Tue Jan  2 12:44:30 2007
@@ -22,6 +22,8 @@
 dojo.provide("cocoon.ajax");
 dojo.provide("cocoon.ajax.common");
 dojo.require("cocoon.ajax.insertion");
+dojo.require("dojo.lfx.html");
+
 
 dojo.lang.mixin(cocoon.ajax, {
     /**
@@ -75,5 +77,39 @@
         timer.onStart = timer.onTick;
         timer.start();
         return timer;
+    },
+    
+    // Update effects. These function can be used to set cocoon.ajax.BUHandler.highlight
+    effects: {
+        // highlight effects - transition the background colour
+        highlight: { // these are intended to look like a semi-opaque layer of colour over white
+            yellow: function(node) {
+                dojo.lfx.html.highlight(node, [240, 238, 133], 1000).play(0);
+            },
+            blue: function(node) {
+                dojo.lfx.html.highlight(node, [141, 133, 252], 1000).play(0);
+            },
+            red: function(node) {
+                dojo.lfx.html.highlight(node, [220, 133, 133], 1000).play(0);
+            },
+            green: function(node) {
+                dojo.lfx.html.highlight(node, [159, 223, 133], 1000).play(0);
+            },
+            grey: function(node) {
+                dojo.lfx.html.highlight(node, [128, 128, 128], 1000).play(0);
+            },
+            purple: function(node) {
+                dojo.lfx.html.highlight(node, [197, 133, 220], 1000).play(0);
+            },
+            orange: function(node) {
+                dojo.lfx.html.highlight(node, [252, 202, 133], 1000).play(0);
+            }
+        },
+        blink: function(node) { // hide then show the node
+            var opacity = dojo.html.getOpacity(node);
+            dojo.html.setOpacity(node, 0.2);
+            setTimeout(function() {dojo.html.setOpacity(node, opacity);}, 600);
+        }
+        // add more effects?
     }
 });

Added: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js?view=auto&rev=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js (added)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js Tue Jan  2 12:44:30 2007
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+ 
+ /*
+  * Mapping of all widget short names to their full package names
+  * This is used for widget autoloading - no dojo.require() is necessary.
+  * If you use a widget in markup or create one dynamically, then this
+  * mapping is used to find and load any dependencies not already loaded.
+  * You should use your own namespace for any custom widgets (remember to register it).
+  * For extra widgets you use, dojo.require() may still be used to explicitly load them.
+  *
+  * NOTE: Introduced in 2.1.11, replaces functionality in cocoon.js
+  *
+  * @version $Id$
+  */
+  
+dojo.provide("cocoon.ajax.manifest");
+
+(function(){
+	var map = {
+		html: {
+			"formuploadprogress"        : "cocoon.ajax.FormUploadProgress",
+			"partiallink"               : "cocoon.ajax.PartialLink"
+            // register new Widgets in the cocoon.ajax namespace here
+		},
+		svg: {
+		    // register svg widgets here
+		},
+		vml: {
+		    // register vml widgets here
+		}
+	};
+	
+	function ajaxResolver(name, domain){
+		if(!domain){ domain="html"; }
+		if(!map[domain]){ return null; }
+		return map[domain][name];    
+	}
+    
+    dojo.registerModulePath("cocoon.ajax", "../ajax/js");
+	dojo.registerNamespace("ajax", "cocoon.ajax", ajaxResolver);
+
+})();

Propchange: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/ajax/resources/manifest.js
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.4.1-ajax.zip
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.4.1-ajax.zip?view=auto&rev=491930
==============================================================================
Binary file - no diff available.

Propchange: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.4.1-ajax.zip
------------------------------------------------------------------------------
    svn:executable = *

Propchange: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-impl/src/main/resources/org/apache/cocoon/dojo/resources/dojo-0.4.1-ajax.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml (original)
+++ cocoon/trunk/blocks/cocoon-ajax/cocoon-ajax-sample/src/main/resources/COB-INF/linked-updater.xml Tue Jan  2 12:44:30 2007
@@ -22,9 +22,11 @@
 	// djConfig = { isDebug: true };
   </script>
   <script type="text/javascript" src="${cocoon.request.contextPath}/_cocoon/resources/dojo/dojo.js"/>
-  <script type="text/javascript" src="${cocoon.request.contextPath}/_cocoon/resources/ajax/cocoon.js"/>
+  <!--<script type="text/javascript" src="${cocoon.request.contextPath}/_cocoon/resources/ajax/cocoon.js"/>-->
   <script type="text/javascript">
-	dojo.require("cocoon.ajax.PartialLink");
+    dojo.require("dojo.widget.*");
+    dojo.registerModulePath("cocoon.ajax", "../ajax/js");
+	dojo.require("cocoon.ajax.common");
 	
 	function initTimer() {
 	    cocoon.ajax.periodicalUpdate(2000, "display-freememory", "freemem");
@@ -54,12 +56,12 @@
 		<table width="100%">
 			<tr valign="top">
 				<td width="30%">
-					<a href="linked-updater-content-1" dojoType="PartialLink" target="replace#changeme">Click me to do a replace</a><br/>
-					<a href="linked-updater-content-2" dojoType="PartialLink" target="replace#changeme">Click me to do a different replace</a><br/>
-					<a href="linked-updater-content-3" dojoType="PartialLink" target="before#changeme">Click me to insert before</a><br/>
-					<a href="linked-updater-content-3" dojoType="PartialLink" target="top#changeme">Click me to insert at the top</a><br/>
-					<a href="linked-updater-content-3" dojoType="PartialLink" target="bottom#changeme">Click me to insert at the bottom</a><br/>
-					<a href="linked-updater-content-3" dojoType="PartialLink" target="after#changeme">Click me to insert after</a><br/>
+					<a href="linked-updater-content-1" dojoType="ajax:PartialLink" target="replace#changeme">Click me to do a replace</a><br/>
+					<a href="linked-updater-content-2" dojoType="ajax:PartialLink" target="replace#changeme">Click me to do a different replace</a><br/>
+					<a href="linked-updater-content-3" dojoType="ajax:PartialLink" target="before#changeme">Click me to insert before</a><br/>
+					<a href="linked-updater-content-3" dojoType="ajax:PartialLink" target="top#changeme">Click me to insert at the top</a><br/>
+					<a href="linked-updater-content-3" dojoType="ajax:PartialLink" target="bottom#changeme">Click me to insert at the bottom</a><br/>
+					<a href="linked-updater-content-3" dojoType="ajax:PartialLink" target="after#changeme">Click me to insert after</a><br/>
 					<p>Memory available on the server:
 					  <span id="freemem">[unknown]</span>
 					</p>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-advanced-field-styling.xsl Tue Jan  2 12:44:30 2007
@@ -238,7 +238,7 @@
           <xsl:value-of select="@id"/>
           <xsl:text>:input').value = arguments[0];</xsl:text>
           <xsl:if test="(@listening = 'true' and not(fi:styling/@submit-on-change = 'false')) or fi:styling/@submit-on-change = 'true'">
-            <xsl:text>forms_submitForm(dojo.byId('</xsl:text>
+            <xsl:text>cocoon.forms.submitForm(dojo.byId('</xsl:text>
             <xsl:value-of select="@id"/>
             <xsl:text>:input'))</xsl:text>
           </xsl:if>
@@ -253,7 +253,7 @@
             <xsl:value-of select="fi:value"/>
           </xsl:when>
           <xsl:otherwise>
-            <xsl:attribute name="defaultText">
+            <xsl:attribute name="value">
               <xsl:text>[</xsl:text>
               <xsl:value-of select="fi:hint"/>
               <xsl:text>]</xsl:text>
@@ -272,7 +272,7 @@
       +-->
   <xsl:template match="fi:field[fi:styling/@type='suggest' and @state='active']">
     <span id="{@id}">
-      <input name="{@id}" id="{@id}:input" value="{fi:value}" dojoType="CFormsSuggest">
+      <input name="{@id}" id="{@id}:input" value="{fi:value}" dojoType="forms:CFormsSuggest">
         <xsl:apply-templates select="." mode="styling"/>
         <xsl:if test="fi:suggestion">
           <xsl:attribute name="suggestion"><xsl:value-of select="fi:suggestion"/></xsl:attribute>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-calendar-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-calendar-styling.xsl?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-calendar-styling.xsl (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-calendar-styling.xsl Tue Jan  2 12:44:30 2007
@@ -82,7 +82,7 @@
 	        </xsl:when>
 	        <xsl:otherwise>
 	          <a href="#" name="{$id}" id="{$id}"
-	             onclick="forms_calendar.select(forms_getForm(this)['{@id}'],'{$id}','{$format}'); return false;">
+	             onclick="forms_calendar.select(cocoon.forms.getForm(this)['{@id}'],'{$id}','{$format}'); return false;">
 	            <img src="{$resources-uri}/forms/img/cal.gif" alt="forms:calendar.alt" i18n:attr="alt"/>
 	          </a>
 	        </xsl:otherwise>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-field-styling.xsl Tue Jan  2 12:44:30 2007
@@ -27,30 +27,61 @@
                 xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
                 exclude-result-prefixes="fi">
 
+  <xsl:param name="dojo-debug">false</xsl:param><!-- option to turn on console debugging for dojo on the browser, from a parameter in the sitemap -->
+
+  <!--+  
+      | Setup the scripts for CForms
+      |
+      | CForms can run in two different modes, in each mode different form widgets get instantiated.
+      | The @ajax attribute in your ft:form-template controls the mode.
+      |
+      | 1. non-ajax mode (@ajax="false", this is the default) : 
+      |     All form submits happen via full page loads.
+      |     Form submission is handled by cocoon.forms.SimpleForm (dojoType="forms:SimpleForm")
+      |     either directly (submit buttons) or via cocoon.forms.submitForm (scripts, onChange handlers etc.).
+      |
+      | 2. ajax-mode (@ajax="true") :
+      |     All form submits happen via AJAX (XHR or IframeIO) resulting in partial page updates.
+      |     Form submission is handled by cocoon.forms.AjaxForm (dojoType="forms:AjaxForm")
+      |     either directly (buttons) or via cocoon.forms.submitForm (scripts).
+      | 
+      | NOTES: 
+      |    Dojo is always loaded by this XSLT. You can use dojo widgets regardless of whether you want ajax-type behaviour.
+      |    Since 2.1.11, cocoon widgets no longer need to be explicitly 'dojo.require'd in the page, they load automatically using a namespace manifest.
+      |    You may use this same mechanism for your own namespace widgets.
+      |    Because we now use lazy-loading, it is recommended that any initialisation code your templates or custom widgets require
+      |    should be added as an OnLoadHandler, as this guarentees that all code is loaded without you having to register cocoon modules etc.
+      |
+      |    If you are overiding this xslt to avoid the use of dojo (untested, but cocoon.forms.common should still work)
+      |    you should add a call to run CForms OnLoadHandlers into the body's @onload attribute
+      |     
+      |      eg.
+      |       <xsl:attribute name="onload">cocoon.forms.callOnLoadHandlers(); <xsl:value-of select="@onload"/></xsl:attribute>
+      +-->
   <xsl:template match="head" mode="forms-field">
-    <!-- copy any pre-initialization code which can be used e.g. to setup dojo debugging with
-         <script> djConfig = {isDebug: true} </script> -->
-    <xsl:copy-of select="fi:init/node()"/>
-    <script src="{$resources-uri}/dojo/dojo.js" type="text/javascript"/>
-    <script src="{$resources-uri}/ajax/cocoon.js" type="text/javascript"/>
-    <script src="{$resources-uri}/forms/js/forms-lib.js" type="text/javascript"/>
+    <xsl:if test="$dojo-debug = 'true'">                                           <!-- turn on debugging, if requested -->
+        <script type="text/javascript"> djConfig = {isDebug: true} </script>
+    </xsl:if>
+    <script src="{$resources-uri}/dojo/dojo.js" type="text/javascript"/>           <!-- load dojo -->
+    <script type="text/javascript">dojo.require("dojo.widget.*");</script>         <!-- require dojo.widget for auto-loading -->
+    <xsl:if test="$dojo-debug = 'true'">                                           <!-- require console etc. for dojo debug, if requested -->
+        <script type="text/javascript">dojo.require("dojo.debug.console"); dojo.require("dojo.widget.Tree");</script>
+    </xsl:if>
+    <script src="{$resources-uri}/forms/js/forms-lib.js" type="text/javascript"/>  <!-- load legacy scripts -->
+    <!-- load forms library -->
     <script type="text/javascript">
-        dojo.addOnLoad(forms_onload);
-        dojo.require("cocoon.forms.*");
-    </script>
-    
-    <!-- googlemap-key -->
-    <xsl:if test="/*/fi:googlemap">
+    dojo.registerModulePath("cocoon.forms", "../forms/js");                        <!-- tell dojo how to find our forms module. NB: (since 2.1.11, replaces cocoon.js) -->
+    dojo.require("cocoon.forms.common");                                           <!-- tell dojo we require the commons library -->
+    dojo.addOnLoad(cocoon.forms.callOnLoadHandlers);                               <!-- ask dojo to run our onLoad handlers -->
+    </script>    
+    <xsl:copy-of select="fi:init/node()"/>                                         <!-- copy optional initialisation from form template -->    
+    <xsl:if test="/*/fi:googlemap">                                                <!-- googlemap-key TODO: This looks broken to me (JQ) -->
       <script src="/*/fi:googlemap/fi:key" type="text/javascript"/>
     </xsl:if>
-
-    
     <link rel="stylesheet" type="text/css" href="{$resources-uri}/forms/css/forms.css"/>
   </xsl:template>
   
-  <xsl:template match="fi:init">
-    <!-- ignore, was handled above -->
-  </xsl:template>
+  <xsl:template match="fi:init"/>                                                  <!-- ignore, was handled above -->
 
   <xsl:template match="body" mode="forms-field">
     <xsl:copy-of select="@*"/>
@@ -104,13 +135,13 @@
     <!--  Auto submit on fields which are listening -->
     <xsl:if test="@listening = 'true' and not(fi:styling/@submit-on-change = 'false') and not(fi:styling/@onchange) and not(fi:styling/@list-type = 'double-listbox')">
       <xsl:choose>
-          <!-- IE does not react to a click with an onchange, as firefox does, so for radio and checkbox put an onclick handler instead -->
-	      <xsl:when test="local-name() = 'booleanfield' or fi:styling/@list-type = 'radio' or fi:styling/@list-type = 'checkbox'">
-	        <xsl:attribute name="onclick">forms_submitForm(this)</xsl:attribute>  
-	      </xsl:when>
-          <xsl:otherwise>
-	      	<xsl:attribute name="onchange">forms_submitForm(this)</xsl:attribute>
-          </xsl:otherwise>
+        <!-- IE does not react to a click with an onchange, as firefox does, so for radio and checkbox put an onclick handler instead -->
+        <xsl:when test="local-name() = 'booleanfield' or fi:styling/@list-type = 'radio' or fi:styling/@list-type = 'checkbox'">
+          <xsl:attribute name="onclick">cocoon.forms.submitForm(this)</xsl:attribute>  
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:attribute name="onchange">cocoon.forms.submitForm(this)</xsl:attribute>
+        </xsl:otherwise>
       </xsl:choose>
     </xsl:if>
 
@@ -140,7 +171,7 @@
 
   <xsl:template match="fi:styling/@submit-on-change" mode="styling">
     <xsl:if test=". = 'true'">
-      <xsl:attribute name="onchange">forms_submitForm(this)</xsl:attribute>
+      <xsl:attribute name="onchange">cocoon.forms.submitForm(this)</xsl:attribute>
     </xsl:if>
   </xsl:template>
 
@@ -390,10 +421,10 @@
       +-->
   <xsl:template match="fi:booleanfield[@state='output']" priority="3">
     <input id="{@id}" type="checkbox" title="{fi:hint}" disabled="disabled" value="{@true-value}" name="{@id}">
-        <xsl:apply-templates select="." mode="css"/>
-    	  <xsl:if test="fi:value != 'false'">
-    	    <xsl:attribute name="checked">checked</xsl:attribute>
-    	  </xsl:if>
+      <xsl:apply-templates select="." mode="css"/>
+      <xsl:if test="fi:value != 'false'">
+        <xsl:attribute name="checked">checked</xsl:attribute>
+      </xsl:if>
     </input>
   </xsl:template>
 
@@ -411,7 +442,7 @@
       | fi:action, link-style
       +-->
   <xsl:template match="fi:action[fi:styling/@type = 'link']" priority="1">
-    <a id="{@id}" title="{fi:hint}" href="#" onclick="forms_submitForm(this, '{@id}'); return false">
+    <a id="{@id}" title="{fi:hint}" href="#" onclick="cocoon.forms.submitForm(this, '{@id}'); return false">
       <xsl:apply-templates select="." mode="styling"/>
       <xsl:copy-of select="fi:label/node()"/>
     </a>
@@ -495,7 +526,7 @@
         <xsl:variable name="value" select="@value"/>
         <xsl:if test="$values[. = $value]">
           <xsl:value-of select="fi:label/node()"/>
-    	</xsl:if>
+        </xsl:if>
       </xsl:for-each>
     </span>
   </xsl:template>
@@ -512,7 +543,7 @@
             <xsl:text>[</xsl:text>
             <xsl:value-of select="fi:value"/>
             <xsl:text>] </xsl:text>
-            <input type="button" id="{@id}:input" name="{@id}" value="..." onclick="forms_submitForm(this)" class="forms upload-change-button"/>
+            <input type="button" id="{@id}:input" name="{@id}" value="..." onclick="cocoon.forms.submitForm(this)" class="forms upload-change-button"/>
         </xsl:when>
         <xsl:otherwise>
           <input type="file" id="{@id}:input" name="{@id}" title="{fi:hint}" accept="{@mime-types}">
@@ -578,23 +609,33 @@
 
   <!--+
       | fi:form-template|fi:form-generated
+      |
+      |      NB. If you are overiding this xslt to avoid the use of Dojo
+      |      You should add a call to run CForms OnSubmitHandlers into the form's @onsubmit attribute
+      |      
+      |      eg.
+      |        <xsl:attribute name="onsubmit">cocoon.forms.callOnSubmitHandlers(this); <xsl:value-of select="@onsubmit"/></xsl:attribute>
       +-->
   <xsl:template match="fi:form-template|fi:form-generated">
-    <form>
-      <xsl:copy-of select="@*"/>
+    <xsl:variable name="id">
       <xsl:choose>
-        <xsl:when test="@ajax = 'true'">
-          <xsl:attribute name="dojoType">CFormsForm</xsl:attribute>
-          <xsl:if test="@ajax = 'true'">
-            <script type="text/javascript">cocoon.forms.ajax = true;</script>
-          </xsl:if>
-        </xsl:when>
-        <xsl:otherwise>
-          <xsl:attribute name="onsubmit">forms_onsubmit(); <xsl:value-of select="@onsubmit"/></xsl:attribute>
-        </xsl:otherwise>
+        <xsl:when test="@id != ''"><xsl:value-of select="@id"/></xsl:when>
+        <xsl:otherwise><xsl:value-of select="generate-id()"/></xsl:otherwise>
       </xsl:choose>
-      <!-- hidden field to store the submit id -->
-      <div><input type="hidden" name="forms_submit_id"/></div>
+    </xsl:variable>
+    <form>
+      <xsl:copy-of select="@*"/>
+      <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute><!-- form/@id required since 2.1.11-->
+      <xsl:if test="not(@dojoType)">
+        <xsl:choose>
+          <xsl:when test="@ajax = 'true'">
+            <xsl:attribute name="dojoType">forms:AjaxForm</xsl:attribute>
+          </xsl:when>
+          <xsl:otherwise>
+            <xsl:attribute name="dojoType">forms:SimpleForm</xsl:attribute>
+          </xsl:otherwise>
+        </xsl:choose>
+      </xsl:if>
       <xsl:apply-templates/>
 
       <!-- TODO: consider putting this in the xml stream from the generator? -->
@@ -654,7 +695,7 @@
       <xsl:if test="fi:message">
         <xsl:apply-templates select="." mode="label"/>:
         <ul>
-		  <xsl:apply-templates select="." mode="css"/>            
+          <xsl:apply-templates select="." mode="css"/>
           <xsl:for-each select="fi:message">
             <li><xsl:apply-templates/></li>
           </xsl:for-each>

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-htmlarea-styling.xsl
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-htmlarea-styling.xsl?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-htmlarea-styling.xsl (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/forms-htmlarea-styling.xsl Tue Jan  2 12:44:30 2007
@@ -60,7 +60,7 @@
             <xsl:value-of select="fi:styling/conf/text()"/>
             editor.generate();
           }
-          forms_onloadHandlers.push(handler);      
+          cocoon.forms.addOnLoadHandler(handler);      
         </script>        
       </xsl:when>
       <!-- use a passed configuration function -->
@@ -73,7 +73,7 @@
             "or not available! Can't render widget '<xsl:value-of select="@id"/>'");
           }
           handler.forms_onload = <xsl:value-of select="fi:styling/initFunction"/>;
-          forms_onloadHandlers.push(handler);   
+          cocoon.forms.addOnLoadHandler(handler);   
         </script>
       </xsl:when>    
       <!-- default mode with all buttons available -->  
@@ -84,7 +84,7 @@
           handler.forms_onload = function() {
             HTMLArea.replace('<xsl:value-of select="@id"/>');
           }
-          forms_onloadHandlers.push(handler);      
+          cocoon.forms.addOnLoadHandler(handler);      
         </script>  
       </xsl:otherwise>
     </xsl:choose>

Added: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js?view=auto&rev=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js (added)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js Tue Jan  2 12:44:30 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+dojo.provide("cocoon.forms.AjaxForm");
+dojo.require("cocoon.forms.SimpleForm");
+dojo.require("cocoon.ajax.BUHandler");
+
+
+/**
+ * Dojo widget for CForms, that handles the Ajax interaction with the server.
+ *
+ * Extends cocoon.forms.SimpleForm with Ajax behaviour
+ *
+ * NOTE: Introduced in 2.1.11
+ *
+ * @version $Id$
+ */
+
+dojo.widget.defineWidget(
+    "cocoon.forms.AjaxForm",
+    cocoon.forms.SimpleForm,
+    {
+
+    // widget properties
+    widgetType: "AjaxForm",
+
+    /**
+     * Submit the form via Ajax.
+     * Choose the right transport depending on the widgets in the form and the browser's capabilities.
+     *
+     * @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 form data (optional)
+     */
+    submit: function(name, params) {
+        var form = this.domNode;                                /* the form node */
+        var mimetype = "text/xml";                              /* the default mime-type */
+        if (!params) params = {};                               /* create if not passed */
+        
+        // TODO: should CForm's onSubmit handlers be called for Ajax events ?
+        //if (cocoon.forms.callOnSubmitHandlers(form)) == false) return; /* call CForm's onSubmit handlers */
+        
+        // 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;
+
+        params["forms_submit_id"] = 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 */
+            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: dojo.lang.hitch(this, function(type, data) { this._handleBrowserUpdate(this, name, type, data) }),
+            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's BrowserUpdate response.
+     * Update the part of the form referenced by ids in the reponse.
+     */
+    _handleBrowserUpdate: function(widget, name, type, data) {
+        // Restore normal cursor
+        document.body.style.cursor = "auto";
+        // Attempt to re-enable the click target
+        if (this.domNode[name]) this.domNode[name].disabled = false;
+        // get a BrowsewrUpdateHandler which will replace the updated parts of the form
+        var updater = new cocoon.ajax.BUHandler();
+        if (type == "load") {
+            if (!data) {
+                cocoon.ajax.BUHandler.handleError("No xml answer", data);
+                return;
+            }
+            // add the continue handler for CForms
+            updater.handlers['continue'] = function() { widget._continue(); } 
+            // Handle browser update directives
+            updater.processResponse(data);
+        } else if (type == "error") {
+            updater.handleError("Request failed", data);
+        } else {
+            dojo.debug("WARNING: dojo.io.bind returned an unhandled state : " + type);
+        }
+    },
+    
+    /**
+     * Handle the server continue message.
+     * The server is signalling in a BrowserUpdate response that the CForm is finished.
+     * Return an acknowledgement to the continuation so cocoon.sendForm may complete.
+     */
+    _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;
+        }
+    }
+});
+
+/**
+ * Override built-in dojo function, we do not care about 'file' fields that are disabled.
+ * We overide because dojo will call this during form submission and we do not want it
+ * to be bothered by disabled file fields. Hopefully this can be added to dojo .....
+ */
+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;
+}

Propchange: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/AjaxForm.js
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsDragAndDropRepeater.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsDragAndDropRepeater.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsDragAndDropRepeater.js (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsDragAndDropRepeater.js Tue Jan  2 12:44:30 2007
@@ -27,16 +27,17 @@
  */
 
 // Extends the base CFormsRepeater class.
-cocoon.forms.CFormsDragAndDropRepeater = function() {
-    cocoon.forms.CFormsRepeater.call(this);
-};
 
-dojo.inherits(cocoon.forms.CFormsDragAndDropRepeater, cocoon.forms.CFormsRepeater);
-
-dojo.lang.extend(cocoon.forms.CFormsDragAndDropRepeater, {
+dojo.widget.defineWidget(
+    "cocoon.forms.CFormsDragAndDropRepeater",
+    cocoon.forms.CFormsRepeater, {
     // Properties
     // Widget definition
+    ns: "forms",
     widgetType: "CFormsDragAndDropRepeater",
+    isContainer: true,
+    preventClobber: true, // don't clobber our node
+    
     /**
      * Returns the action name to be called on the server for model update.
      */
@@ -55,11 +56,15 @@
              }
              return "cforms-" + type;
     },
-    buildRendering: function(args, parserFragment, parentWidget) {
+    
+    // widget interface
+    buildRendering: function(args, frag) {
         // FIXME: we should destroy all drag sources and drop targets when the widget is destroyed
-        // Magical statement to get the dom node, stolen in DomWidget
-        this.domNode = parserFragment["dojo:"+this.widgetType.toLowerCase()].nodeRef;
 
+        // refering to this.domNode, allows a user to specify a template to wrap the widget
+        //if (!this.domNode) this.domNode = this.domNode;
+		cocoon.forms.CFormsRepeater.superclass.buildRendering.call(this, args, frag);
+		
         this.id = this.domNode.getAttribute("id");
         if (!this.orderable && this.select == "none") {
             dojo.debug(this.widgetType + " '" + this.id + "' is not orderable nor selectable");
@@ -84,8 +89,8 @@
                 with (this.dropIndicator.style) {
                     position = "absolute";
                     zIndex = 1;
-                    width = dojo.style.getInnerWidth(this.domNode) + "px";
-                    left = dojo.style.getAbsoluteX(this.domNode) + "px";
+                    width = dojo.html.getBorderBox(this.domNode).width + "px";
+                    left = dojo.html.getAbsolutePosition(this.domNode).x + "px";
                 }
             };
             dojo.event.connect("before", dropTarget, "insert", this, "beforeInsert");
@@ -225,7 +230,3 @@
                     dojoForm.submit(this.getDndAction(), params);
         }
 });
-
-dojo.widget.tags.addParseTreeHandler("dojo:CFormsDragAndDropRepeater");
-// Register this module as a widget package
-dojo.widget.manager.registerWidgetPackage("cocoon.forms");

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=491930&r1=491929&r2=491930
==============================================================================
--- 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 Tue Jan  2 12:44:30 2007
@@ -17,10 +17,13 @@
 dojo.provide("cocoon.forms.CFormsForm");
 dojo.require("dojo.event");
 dojo.require("dojo.widget.DomWidget");
+dojo.require("cocoon.forms.common");
 dojo.require("cocoon.ajax.BUHandler");
 
 
 /**
+ * DEPRECATED: 2.1.11, in favour of SimpleForm and AjaxForm
+ *
  * 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
@@ -35,17 +38,18 @@
     {
 
     // properties
+    ns: "forms",
     widgetType: "CFormsForm",
     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;
+    buildRendering: function(args, frag) {
+        this.domNode = this.getFragNodeRef(frag);
         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");
+        dojo.debug("DEPRECATED: cocoon.forms.CFormsForm - Please use cocoon.forms.AjaxForm instead.");
     },
 
     _grabClickTarget: function(event) {
@@ -77,10 +81,10 @@
      *              query string (optional)
      */
     submit: function(name, params) {
-        var form = this.domNode;                                    /* the form node */
-        var thisWidget = this;                                      /* closure magic for the callback handler */
+        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 */
+        if (!params) params = {};                               /* create if not passed */
         
         // Provide feedback that something is happening.
         document.body.style.cursor = "wait";
@@ -91,25 +95,25 @@
         if (!uri) uri = form.action;
         if (uri == "") uri = document.location;
 
-        form["forms_submit_id"].value = name;           /* name of the button doing the submit */
+        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 */
+        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.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 */
+            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
@@ -120,7 +124,7 @@
     /**
      * Handle the server response
      */
-    _handleBrowserUpdate: function(widget, name, type, data, evt) {     
+    _handleBrowserUpdate: function(widget, name, type, data, evt) {
         // Restore normal cursor
         document.body.style.cursor = "auto";
         // Attempt to re-enable the click target
@@ -143,7 +147,6 @@
     },
     
     _continue: function() {
-        //alert("_continue()");
         var form = this.domNode;
         if (form.method.toLowerCase() == "post") {
             // Create a fake form and post it

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsRepeater.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsRepeater.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsRepeater.js (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsRepeater.js Tue Jan  2 12:44:30 2007
@@ -30,30 +30,30 @@
 
 // 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.CFormsRepeater = function() {
-	dojo.widget.DomWidget.call(this);
-};
 
-dojo.inherits(cocoon.forms.CFormsRepeater, dojo.widget.DomWidget);
-
-dojo.lang.extend(cocoon.forms.CFormsRepeater, {
+dojo.widget.defineWidget(
+    "cocoon.forms.CFormsRepeater",
+    dojo.widget.DomWidget, {
     // Properties
     orderable: false,
     select: "$no$", // default value used to type the property, but indicating that
                     // no selection will occur
 
     // Widget definition
+    ns: "forms",
     widgetType: "CFormsRepeater",
     isContainer: true,
-    //
+    preventClobber: true, // don't clobber our node
+    
     getType: function() {
 			    return "cforms-" + this.id;
     },
-    buildRendering: function(args, parserFragment, parentWidget) {
+    
+    // widget interface
+    buildRendering: function(args, frag) {
 	    // FIXME: we should destroy all drag sources and drop targets when the widget is destroyed
-        // Magical statement to get the dom node, stolen in DomWidget
-	    this.domNode = parserFragment["dojo:"+this.widgetType.toLowerCase()].nodeRef;
-
+	    
+        cocoon.forms.CFormsRepeater.superclass.buildRendering.call(this, args, frag);
         this.id = this.domNode.getAttribute("id");
         if (!this.orderable && this.select == "none") {
             dojo.debug(this.widgetType + " '" + this.id + "' is not orderable nor selectable");
@@ -78,8 +78,8 @@
 				with (this.dropIndicator.style) {
 					position = "absolute";
 					zIndex = 1;
-					width = dojo.style.getInnerWidth(this.domNode) + "px";
-					left = dojo.style.getAbsoluteX(this.domNode) + "px";
+					width = dojo.html.getBorderBox(this.domNode).width + "px";
+					left = dojo.html.getAbsolutePosition(this.domNode).x + "px";
 				}
 			};
 			dojo.event.connect(dropTarget, "insert", this, "afterInsert");
@@ -159,8 +159,3 @@
 	    }
 	}
 });
-
-dojo.widget.tags.addParseTreeHandler("dojo:CFormsRepeater");
-// Register this module as a widget package
-dojo.widget.manager.registerWidgetPackage("cocoon.forms");
-

Modified: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsSuggest.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsSuggest.js?view=diff&rev=491930&r1=491929&r2=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsSuggest.js (original)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/CFormsSuggest.js Tue Jan  2 12:44:30 2007
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 dojo.provide("cocoon.forms.CFormsSuggest");
-dojo.require("dojo.widget.html.ComboBox");
+dojo.require("dojo.widget.ComboBox");
 
 /**
  * Dojo widget for suggestion-lists. Extends Dojo's ComboBox widget.
@@ -34,17 +34,17 @@
  * @version $Id$
  */
 
-cocoon.forms.CFormsSuggest = function() {
-    dojo.widget.html.ComboBox.call(this);
-    this.widgetType = "CFormsSuggest";
-}
-
-dojo.inherits(cocoon.forms.CFormsSuggest, dojo.widget.html.ComboBox);
-
-dojo.lang.extend(cocoon.forms.CFormsSuggest, {
+dojo.widget.defineWidget(
+    "cocoon.forms.CFormsSuggest",
+    dojo.widget.ComboBox, {
+    
+    // Widget definition
+    ns: "forms",
+    widgetType: "CFormsSuggest",
+    
     fillInTemplate: function(args, frag) {
         this.mode = "remote";
-        var node = frag["dojo:"+this.widgetType.toLowerCase()]["nodeRef"];
+        var node = this.getFragNodeRef(frag);
         var form = cocoon.forms.getForm(node);
         var contId = form["continuation-id"].value;
         if (!contId) throw "Cannot find continuation Id";
@@ -53,7 +53,7 @@
             this.dataUrl = "_cocoon/forms/suggest?widget=" + node.getAttribute("name") +
                 "&continuation-id=" + contId + "&filter=%{searchString}";
         }
-        dojo.widget.html.ComboBox.prototype.fillInTemplate.apply(this, arguments);
+        cocoon.forms.CFormsSuggest.superclass.fillInTemplate.call(this, args, frag);
         if (node.value) {
             // Get the suggestion text from the server
             this.getData(this, "_cocoon/forms/suggest?widget=" + node.getAttribute("name") + 
@@ -84,8 +84,4 @@
             mimetype: "text/json"
         });
     }
-})
-
-dojo.widget.tags.addParseTreeHandler("dojo:CFormsSuggest");
-// Register this module as a widget package
-dojo.widget.manager.registerWidgetPackage("cocoon.forms");
+});

Added: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js?view=auto&rev=491930
==============================================================================
--- cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js (added)
+++ cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js Tue Jan  2 12:44:30 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+dojo.provide("cocoon.forms.SimpleForm");
+dojo.require("dojo.event");
+dojo.require("dojo.widget.DomWidget");
+dojo.require("cocoon.forms.common");
+
+
+/**
+ * Dojo widget for Cocoon Forms, that handles full-page submits to 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
+ *
+ * NOTE: Introduced in 2.1.11, replaces functionality in forms-lib.js
+ *
+ * @version $Id$
+ */
+
+dojo.widget.defineWidget(
+    "cocoon.forms.SimpleForm",
+    dojo.widget.DomWidget,
+    {
+
+    // widget properties
+    ns: "forms",
+    widgetType: "SimpleForm",
+    isContainer: true,
+    preventClobber: true, // don't clobber our form node (this.domNode)
+        
+    // widget interface
+    fillInTemplate: function(args, frag) {
+        this.id = this.domNode.getAttribute("id"); 
+        if (!this.id) dojo.debug("WARNING: IDs on forms are now required, this form may not work properly.");
+        this.domNode.setAttribute("dojoWidgetId", this.widgetId); // mark this node as a widget impl of a form
+        dojo.event.connect("around", this.domNode, "onsubmit", this, "_browserSubmit");
+        dojo.event.connect(this.domNode, "onclick", this, "_grabClickTarget"); 
+    },
+    
+    /** 
+     * Connected to the 'onclick' event to capture the clicked element 
+     * Keep targets of onclick so that we can know what input triggered the submit
+     * (the event in onsubmit() is the HTMLFormElement).
+     */
+    _grabClickTarget: function(event) {
+        this.lastClickTarget = dojo.html.getEventTarget(event);
+    },
+
+    /** 
+     * Connected to the forms 'onsubmit' event 
+     * called when the user clicks a submit input 
+     * Calls the user's optional @onsubmit handler on the form tag
+     * If real submit has to occur, it's taken care of in this.submit()
+     * We always return false, to stop the native submit from running
+     *
+     */
+    _browserSubmit: function(onSubmitEvent) {
+        if (onSubmitEvent.proceed() == false) { 
+            // onsubmit handlers stopped submission
+            return false;
+        }
+        this.submit(this.lastClickTarget && this.lastClickTarget.name); // submit the form
+        return false;
+    },
+
+    /**
+     * Submit the form, full page request.
+     *
+     * @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 request (optional)
+     *
+     */
+    submit: function(name, params) {
+        dojo.debug("SimpleForm.submit");
+        if (!params) params = {};
+        cocoon.forms.fullPageSubmit(this.domNode, name, params);
+        // Toggle the click target off, so it does not get resubmitted if another submit is fired before this has finished
+        if (this.domNode[name]) this.domNode[name].disabled = true;
+    }
+});

Propchange: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/js/SimpleForm.js
------------------------------------------------------------------------------
    svn:keywords = Id

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=491930&r1=491929&r2=491930
==============================================================================
--- 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 Tue Jan  2 12:44:30 2007
@@ -16,10 +16,15 @@
  */
 
 /**
- * Utility functions for form handling.
+ * Utility functions for CForm handling.
+ *
+ * These scripts will use Dojo if it is avalable, but should work without.
+ *
+ * NOTE: (2.1.11) Functionality from forms-lib.js has been refactored, namespaced and moved here
  *
  * @version $Id$
  */
+ 
 // Can be loaded either through "cocoon.forms" or "cocoon.forms.common"
 // or individually out of Dojo.
 if (dojo) {
@@ -30,8 +35,11 @@
     cocoon.forms = cocoon.forms || {};
 }
 
+    
 /**
- * Get the form of an element
+ * Get the parent form of an element
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_getForm
  */
 cocoon.forms.getForm = function(element) {
     while(element != null && element.tagName != null && element.tagName.toLowerCase() != "form") {
@@ -41,9 +49,17 @@
 }
 
 /**
- * Submits a form. If ajax mode is on and the browser is ajax-aware, the page isn't reloaded
+ * Submits a form.
+ * This function is designed to submit the form when called from scripts (onchange handlers etc.)
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_submitForm
+ *
+ * @param element   the DOM Node that is triggering this submit
+ * @param name      (Optional) tell CForms the name of the submitting element
+ * @param params    (Optional) an Associative Array of parameters to add to the submitted form
+ *
  */
-cocoon.forms.submitForm = function(element, name) {
+cocoon.forms.submitForm = function(element, name, params) {
     var form = this.getForm(element);
     if (form == null) {
         alert("Cannot find form for " + element);
@@ -54,22 +70,136 @@
 
     var dojoId = form.getAttribute("dojoWidgetId");
     if (dojoId) {
-        // Delegate to the CFormsForm widget
-        dojo.widget.byId(dojoId).submit(name);
+        // Delegate to the SimpleForm or AjaxForm widget
+        dojo.widget.byId(dojoId).submit(name, params);
     } 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();
+        // Regular submit. There is no *Form widget available
+
+        // A form's onsubmit is only called when submit is triggered by user action, but not when
+        // called by a script. So call it now, cancelling the submit if it returns false
+        if (!form.onsubmit || form.onsubmit() != false) {     // call the user's onSubmit handler
+            cocoon.forms.fullPageSubmit(form, name, params);
+        }
+    }
+}
+
+/**
+ * Internal function
+ * Submits a form using a full page submit
+ *
+ * @param form      the form DOM Node that is being submitted
+ * @param name      tell CForms the name of the submitting widget
+ * @param params    an Associative Array of parameters to add to the submitted form
+ *
+ */
+cocoon.forms.fullPageSubmit = function(form, name, params) {
+    // Send the identifier of the widget that triggered the submit
+    params["forms_submit_id"] = name;
+    // call CForm's onSubmit handlers - allow them to stop the form by returning false
+    if (cocoon.forms.callOnSubmitHandlers(form)) {   
+        for (var param in params) { // add extra params to the form
+            var input = form[param] || document.createElement("input");
+            input.setAttribute("type", "hidden");
+            input.setAttribute("name", param);
+            input.setAttribute("value", params[param]);
+            if (!form[param]) form.appendChild(input);
         }
+        form.submit();
+    }
+}
+
+/**
+ * onLoad Handlers
+ * Manage functions that should be called when the page has loaded
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onloadHandlers
+ */
+cocoon.forms.onLoadHandlers = new Array();
+
+/**
+ * add an onLoad Hander
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onloadHandlers.push
+ */
+cocoon.forms.addOnLoadHandler = function(handler) {
+    if (handler && typeof(handler.forms_onload) == "function") {
+        cocoon.forms.onLoadHandlers.push(handler);
     }
 }
 
-// Override the default forms_submitForm
-forms_submitForm = function() { cocoon.forms.submitForm.apply(cocoon.forms, arguments) };
+/**
+ * call the onLoad Handlers (typically this function is passed to dojo.addOnLoad)
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onloadHandlers.push
+ */
+cocoon.forms.callOnLoadHandlers = function() {
+    for (var i = 0; i < cocoon.forms.onLoadHandlers.length; i++) {
+        cocoon.forms.onLoadHandlers[i].forms_onload();
+    }
+    // Reset it (we do not need them anymore)
+    cocoon.forms.onLoadHandlers = new Array();
+}
+
+/**
+ * onSubmit Handlers
+ * Manage functions that should be called before the form is submitted
+ * If an onSubmit Handler returns false, the form will not be submitted
+ * NB. onSubmit Handlers are not currently called for Ajax forms
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onsubmitHandlers.push
+ */
+cocoon.forms.onSubmitHandlers = {};
+
+/**
+ * add an onSubmit Handler
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onsubmitHandlers.push
+ *
+ * @param element  the form control adding the handler
+ * @param handler  the handler
+ */
+cocoon.forms.addOnSubmitHandler = function(element, handler) {
+    if (handler && typeof(handler.forms_onsubmit) == "function") {
+        var form = this.getForm(element);
+        if (form) {
+            var id = form.getAttribute("id");
+            if (id) {
+                if (!cocoon.forms.onSubmitHandlers[id]) cocoon.forms.onSubmitHandlers[id] = new Array();
+                cocoon.forms.onSubmitHandlers[id].push(handler);
+            } else {
+                if (dojo) dojo.debug("WARNING: SubmitHandler not added. There is no id attribute on your form.");
+            }
+        }
+    }
+}
+
+/**
+ * call the onSubmit Handlers
+ *
+ * NOTE: Introduced in 2.1.11, replaces forms_onsubmit
+ *
+ * @param form      the form (DOMNode) being submitted
+ */
+cocoon.forms.callOnSubmitHandlers = function(form) {
+    var id = form.getAttribute("id");
+    if (cocoon.forms.onSubmitHandlers == null) {
+        // Form already submited, but the new page is not yet loaded. This can happen when
+        // the focus is in an input with an "onchange" and the user clicks on a submit button.
+        return false;
+    }
+    for (var i = 0; i < cocoon.forms.onSubmitHandlers[id].length; i++) {
+        if (cocoon.forms.onSubmitHandlers[id][i].forms_onsubmit() == false) {
+            // handler cancels the submit
+            return false;
+            // TODO: should we allow all onsubmithandlers to be called, but then return the aggregate result ?
+        }
+    }
+    // clear it
+    // TODO: if AjaxForm were to start calling submit handlers, this would need to change
+    cocoon.forms.onSubmitHandlers[id] = null;
+    return true;
+}
+
+
+
+



Mime
View raw message