tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [3/3] git commit: Rebuild support for Submit and LinkSubmit
Date Tue, 23 Oct 2012 23:42:02 GMT
Rebuild support for Submit and LinkSubmit


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a548632d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a548632d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a548632d

Branch: refs/heads/5.4-js-rewrite
Commit: a548632d36171ba6a6648da72a5601f1c661c61c
Parents: 3c451a7
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Tue Oct 23 14:06:56 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Tue Oct 23 14:06:56 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/forms.coffee             |   31 +++++++-
 .../tapestry5/corelib/components/LinkSubmit.java   |   24 +++----
 .../tapestry5/corelib/components/Submit.java       |   17 ++---
 .../resources/org/apache/tapestry5/tapestry.js     |   57 ---------------
 tapestry-core/src/test/app1/ImageSubmitDemo.tml    |    4 +-
 5 files changed, 43 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a548632d/tapestry-core/src/main/coffeescript/META-INF/modules/core/forms.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/forms.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/forms.coffee
index effe4f2..e5e295a 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/forms.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/forms.coffee
@@ -29,9 +29,17 @@ define ["core/events", "core/spi", "core/builder", "_"],
       # Clear if found
       hidden and hidden.value null
 
+      form.meta SKIP_VALIDATION, null
+
       return
 
-    setSubmittingHidden = (form, wrapper) ->
+    setSubmittingHidden = (form, submitter) ->
+
+      mode = submitter.attribute "data-submit-mode"
+      isCancel = mode and mode isnt "normal"
+      if isCancel
+        form.meta SKIP_VALIDATION, true
+
       hidden = form.findFirst "[name='t:submit']"
 
       unless hidden
@@ -40,7 +48,7 @@ define ["core/events", "core/spi", "core/builder", "_"],
         firstHidden.insertBefore hidden
 
       # TODO: Research why we need id and name and get rid of one if possible.
-      value = Object.toJSON [ wrapper.element.id, wrapper.element.name ]
+      value = Object.toJSON [ submitter.element.id, isCancel ? "cancel" : submitter.element.name
]
 
       hidden.value value
 
@@ -118,8 +126,6 @@ define ["core/events", "core/spi", "core/builder", "_"],
       # is an Ajax submission.
       return
 
-    # TODO: May want to define a data attribute to control whether Tapestry gets
-    # involved at all?
     spi.onDocument "submit", "form", defaultValidateAndSubmit
 
     # On any click on a submit or image, update the containing form to indicate that the
element
@@ -127,6 +133,23 @@ define ["core/events", "core/spi", "core/builder", "_"],
     # information about which control triggered the submit gets lost.
     spi.onDocument "click", "input[type=submit], input[type=image]", ->
       setSubmittingHidden (spi this.element.form), this
+      return
+
+    # Support for link submits. `data-submit-mode` will be non-null, possibly "cancel".
+    # Update the hidden field, but also cancel the default behavior for the click.
+    spi.onDocument "click", "a[data-submit-mode]", ->
+      form = this.findContainer "form"
+
+      unless form
+        console.error "Submitting link element not contained inside a form element."
+        return false
+
+      setSubmittingHidden form, this
+
+      form.element.submit()
+
+      # And cancel the default behavior for the original click event
+      return false
 
     exports =
       gatherParameters: gatherParameters

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a548632d/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
index 9461da9..7970959 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/LinkSubmit.java
@@ -15,30 +15,26 @@
 package org.apache.tapestry5.corelib.components;
 
 import org.apache.tapestry5.*;
-import org.apache.tapestry5.annotations.Environmental;
-import org.apache.tapestry5.annotations.Events;
-import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.annotations.*;
 import org.apache.tapestry5.corelib.SubmitMode;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.json.JSONArray;
-import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.FormSupport;
 import org.apache.tapestry5.services.Heartbeat;
 import org.apache.tapestry5.services.Request;
-import org.apache.tapestry5.services.javascript.InitializationPriority;
 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 
 /**
  * Generates a client-side hyperlink that submits the enclosing form. If the link is clicked
in the browser, the
- * component will trigger an event ({@linkplain EventConstants#SELECTED selected} by default)
, just like {@link Submit}
- * .
+ * component will trigger an event ({@linkplain EventConstants#SELECTED selected} by default)
, just like
+ * {@link Submit}.
  *
  * @tapestrydoc
  */
 @SupportsInformalParameters
 @Events(EventConstants.SELECTED + " by default, may be overridden")
+@Import(modules = "core/forms")
 public class LinkSubmit implements ClientElement
 {
     /**
@@ -151,7 +147,11 @@ public class LinkSubmit implements ClientElement
 
             formSupport.store(this, new ProcessSubmission(clientId));
 
-            writer.element("span",
+            writer.element("a",
+
+                    "href", "#",
+
+                    "data-submit-mode", mode.name().toLowerCase(),
 
                     "id", clientId);
 
@@ -164,12 +164,6 @@ public class LinkSubmit implements ClientElement
         if (!disabled)
         {
             writer.end();
-
-            JSONObject spec = new JSONObject("form", formSupport.getClientId(), "clientId",
clientId);
-
-            spec.put("mode", mode.name().toLowerCase());
-
-            javascriptSupport.addInitializerCall(InitializationPriority.EARLY, "linkSubmit",
spec);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a548632d/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
index 7e691a7..5766b43 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
@@ -20,7 +20,6 @@ import org.apache.tapestry5.annotations.Events;
 import org.apache.tapestry5.annotations.Parameter;
 import org.apache.tapestry5.annotations.SupportsInformalParameters;
 import org.apache.tapestry5.corelib.SubmitMode;
-import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.json.JSONArray;
@@ -32,7 +31,8 @@ import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 /**
  * Corresponds to &lt;input type="submit"&gt; or &lt;input type="image"&gt;,
a client-side element that can force the
  * enclosing form to submit. The submit responsible for the form submission will post a notification
that allows the
- * application to know that it was the responsible entity. The notification is named "selected"
and has no context.
+ * application to know that it was the responsible entity. The notification is named
+ * {@linkplain EventConstants#SELECTED selected}, by default, and has no context.
  *
  * @tapestrydoc
  */
@@ -153,11 +153,7 @@ public class Submit implements ClientElement
     {
         clientId = javascriptSupport.allocateClientId(resources);
 
-        boolean isCancel = mode == SubmitMode.CANCEL;
-
-        String name =
-                isCancel ? InternalConstants.CANCEL_NAME :
-                        formSupport.allocateControlName(resources.getId());
+        String name = formSupport.allocateControlName(resources.getId());
 
         // Save the element, to see if an id is later requested.
 
@@ -169,6 +165,8 @@ public class Submit implements ClientElement
 
                 "name", name,
 
+                "data-submit-mode", mode.name().toLowerCase(),
+
                 "class", cssClass,
 
                 "id", clientId);
@@ -186,11 +184,6 @@ public class Submit implements ClientElement
         formSupport.store(this, new ProcessSubmission(clientId, name));
 
         resources.renderInformalParameters(writer);
-
-        if (mode != SubmitMode.NORMAL)
-        {
-            javascriptSupport.addInitializerCall("enableBypassValidation", getClientId());
-        }
     }
 
     void afterRender(MarkupWriter writer)

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a548632d/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
index 965cfa1..46605ee 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -288,40 +288,6 @@ define("core/compat/tapestry", [
         },
 
         /**
-         * Creates a clone of the indicated element, but with the alternate tag
-         * name. Attributes of the original node are copied to the new node. Tag
-         * names should be all upper-case. The content of the original element is
-         * copied to the new element and the original element is removed. Event
-         * observers on the original element will be lost.
-         *
-         * @param element
-         *            element or element id
-         * @since 5.2.0
-         */
-        replaceElementTagName: function (element, newTagName) {
-
-            element = $(element);
-
-            var tag = element.tagName;
-
-            /* outerHTML is IE only; this simulates it on any browser. */
-
-            var dummy = document.createElement('html');
-            dummy.appendChild(element.cloneNode(true));
-            var outerHTML = dummy.innerHTML;
-
-            var replaceHTML = outerHTML.replace(new RegExp("^<" + tag, "i"),
-                    "<" + newTagName).replace(new RegExp("</" + tag + ">$", "i"),
-                    "</" + newTagName + ">");
-
-            element.insert({
-                before: replaceHTML
-            });
-
-            T5.dom.remove(element);
-        },
-
-        /**
          * Removes an element and all of its direct and indirect children. The
          * element is first purged, to ensure that Internet Explorer doesn't leak
          * memory if event handlers associated with the element (or its children)
@@ -601,29 +567,6 @@ define("core/compat/tapestry", [
             });
         },
 
-        linkSubmit: function (spec) {
-
-            Tapestry.replaceElementTagName(spec.clientId, "A");
-
-            $(spec.clientId).writeAttribute("href", "#");
-
-            if (spec.mode == "cancel") {
-                $(spec.clientId).writeAttribute("name", "cancel");
-            }
-
-            $(spec.clientId).observeAction("click", function (event) {
-
-                var form = $(spec.form);
-
-                if (spec.mode != "normal") {
-                    form.skipValidation();
-                }
-
-                form.setSubmittingElement(this);
-
-                form.performSubmit(event);
-            });
-        },
 
         /**
          * Used by other initializers to connect an element (either a link

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a548632d/tapestry-core/src/test/app1/ImageSubmitDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/ImageSubmitDemo.tml b/tapestry-core/src/test/app1/ImageSubmitDemo.tml
index ec2932b..56ea1d7 100644
--- a/tapestry-core/src/test/app1/ImageSubmitDemo.tml
+++ b/tapestry-core/src/test/app1/ImageSubmitDemo.tml
@@ -1,5 +1,5 @@
 <t:border xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
-          xmlns:p="tapestry:parameter">
+        >
 
     <h1>Submit with an image</h1>
 
@@ -16,7 +16,7 @@
         <t:errors/>
         <t:textfield t:id="value"/>
         <br/>
-        <t:submit t:id="mySubmit" t:image="context:images/tapestry_banner.gif" />
+        <t:submit t:id="mySubmit" class="btn btn-large" t:image="context:images/tapestry_banner.gif"
/>
     </t:form>
 
 </t:border>
\ No newline at end of file


Mime
View raw message