Author: hlship
Date: Mon Feb 22 18:20:37 2010
New Revision: 915003

URL: http://svn.apache.org/viewvc?rev=915003&view=rev
Log:
Add support for submit mode to the LinkSubmit component

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/linksubmit.js

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java?rev=915003&r1=915002&r2=915003&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
 Mon Feb 22 18:20:37 2010
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry5.*;
 import org.apache.tapestry5.annotations.*;
+import org.apache.tapestry5.corelib.SubmitMode;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.FormSupport;
@@ -47,6 +48,16 @@
     private String event = EventConstants.SELECTED;
 
     /**
+     * Defines the mode, or client-side behavior, for the submit. The default 
is {...@link SubmitMode#NORMAL}; clicking the
+     * button submits the form with validation. {...@link SubmitMode#CANCEL} 
indicates the client-side validation
+     * should be omitted (though server-side validation still occurs).
+     * 
+     * @since 5.2.0
+     */
+    @Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)
+    private SubmitMode mode = SubmitMode.NORMAL;
+
+    /**
      * If true (the default), then any notification sent by the component will 
be deferred until the end of the form
      * submission (this is usually desirable).
      */
@@ -68,6 +79,10 @@
     @Inject
     private Request request;
 
+    @SuppressWarnings("unchecked")
+    @Environmental
+    private TrackableComponentEventCallback eventCallback;
+
     private String clientId;
 
     private static class ProcessSubmission implements 
ComponentAction<LinkSubmit>
@@ -97,7 +112,7 @@
             {
                 public void run()
                 {
-                    resources.triggerEvent(event, null, null);
+                    resources.triggerEvent(event, null, eventCallback);
                 }
             };
 
@@ -137,6 +152,8 @@
 
             JSONObject spec = new JSONObject("form", 
formSupport.getClientId(), "clientId", clientId);
 
+            spec.put("validate", mode == SubmitMode.NORMAL);
+
             javascriptSupport.addInitializerCall("linkSubmit", spec);
         }
     }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/linksubmit.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/linksubmit.js?rev=915003&r1=915002&r2=915003&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/linksubmit.js
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/linksubmit.js
 Mon Feb 22 18:20:37 2010
@@ -12,47 +12,52 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-Tapestry.LinkSubmit = Class.create({
+Tapestry.LinkSubmit = Class
+               .create( {
 
-    initialize: function(spec)
-    {
-        this.form = $(spec.form);
-        this.element = $(spec.clientId);
-
-        this.element.observe("click", this.onClick.bindAsEventListener(this));
-    },
-
-    createHidden : function()
-    {
-        var hidden = new Element("input", { "type":"hidden",
-            "id": this.element.id + "-hidden",
-            "name": this.element.id + "-hidden",
-            "value": this.element.id});
-
-        if (this.form.select("input#" + this.element.id + "-hidden").length == 
0)
-            this.element.insert({after:hidden});
-    },
-
-    onClick : function(event)
-    {
-        // Tapestry.debug("LinkSubmit #{id} clicked.", this.element);
-
-        Event.stop(event);
-
-        var onsubmit = this.form.onsubmit;
-        
-        this.createHidden();
-        
-        if (onsubmit == undefined || onsubmit.call(window.document, event))
-        {    
-            this.form.submit();
-        }
-
-        return false;
-    }
-});
-
-Tapestry.Initializer.linkSubmit = function(spec)
-{
-    new Tapestry.LinkSubmit(spec);
+                       initialize : function(spec) {
+                               this.form = $(spec.form);
+                               this.element = $(spec.clientId);
+                               this.validate = spec.validate;
+
+                               this.element.observe("click", this.onClick
+                                               .bindAsEventListener(this));
+                       },
+
+                       createHidden : function() {
+                               var hidden = new Element("input", {
+                                       "type" : "hidden",
+                                       "id" : this.element.id + "-hidden",
+                                       "name" : this.element.id + "-hidden",
+                                       "value" : this.element.id
+                               });
+
+                               if (this.form.select("input#" + this.element.id 
+ "-hidden").length == 0)
+                                       this.element.insert( {
+                                               after : hidden
+                                       });
+                       },
+
+                       onClick : function(event) {
+                               // Tapestry.debug("LinkSubmit #{id} clicked.", 
this.element);
+
+                       Event.stop(event);
+
+                       var onsubmit = this.form.onsubmit;
+
+                       this.createHidden();
+
+                       if (!this.validate)
+                               $T(this.form).skipValidation = true;
+
+                       if (onsubmit == undefined || 
onsubmit.call(window.document, event)) {
+                               this.form.submit();
+                       }
+
+                       return false;
+               }
+               });
+
+Tapestry.Initializer.linkSubmit = function(spec) {
+       new Tapestry.LinkSubmit(spec);
 }
\ No newline at end of file


Reply via email to