You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/10/23 01:54:48 UTC

git commit: Re-implement the update zone on change behavior for the Select component

Updated Branches:
  refs/heads/5.4-js-rewrite c7596e911 -> 212ad9ce0


Re-implement the update zone on change behavior for the Select component


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

Branch: refs/heads/5.4-js-rewrite
Commit: 212ad9ce0f8a984e1ca8f69ab86eb299ce7ff534
Parents: c7596e9
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Mon Oct 22 16:54:40 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Mon Oct 22 16:54:40 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/select.coffee            |   30 +++++++++++++++
 .../coffeescript/META-INF/modules/core/zone.coffee |    9 +++-
 .../tapestry5/corelib/components/Select.java       |    9 ++--
 .../resources/org/apache/tapestry5/tapestry.js     |   17 --------
 4 files changed, 42 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/212ad9ce/tapestry-core/src/main/coffeescript/META-INF/modules/core/select.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/select.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/select.coffee
new file mode 100644
index 0000000..67b7f6d
--- /dev/null
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/select.coffee
@@ -0,0 +1,30 @@
+# Copyright 2012 The Apache Software Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http:#www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+# ##core/select
+#
+# Provides a document event handler that triggers an update a zone when the value
+# of a select element within the zone changes.
+define ["core/events", "core/spi", "core/zone"],
+
+  (events, spi, zone) ->
+
+        spi.onDocument "change", "select[data-update-zone]", ->
+
+          containingZone = zone.findZone this
+
+          containingZone and containingZone.trigger events.zone.refresh,
+            url: this.attribute "data-update-url"
+            parameters:
+              "t:selectvalue": this.value()

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/212ad9ce/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
index 0bbc68f..79c4e50 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/zone.coffee
@@ -23,6 +23,11 @@ define ["core/spi", "core/events", "core/ajax", "core/console", "core/forms",  "
 
   (spi, events, ajax, console, forms, _) ->
 
+    # For a given element that may have the `data-update-zone` attribute, locates the
+    # zone element. May return null if the zone can not be found (after logging an error
+    # to the console).
+    #
+    # * element starting point for determining zone
     findZone = (element) ->
       zoneId = element.attribute "data-update-zone"
 
@@ -108,5 +113,5 @@ define ["core/spi", "core/events", "core/ajax", "core/console", "core/forms",  "
 
         zone.trigger events.zone.refresh, { url }
 
-    # Most of this module is document event handlers, but there's also one export.
-    return { deferredZoneUpdate }
\ No newline at end of file
+    # Most of this module is document event handlers, but there's also some exports.
+    return { deferredZoneUpdate, findZone }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/212ad9ce/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
index d128021..6801c4e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Select.java
@@ -25,7 +25,6 @@ import org.apache.tapestry5.internal.util.SelectModelRenderer;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.*;
 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
 import org.apache.tapestry5.util.EnumSelectModel;
@@ -196,11 +195,13 @@ public class Select extends AbstractField
 
         if (this.zone != null)
         {
-            Link link = resources.createEventLink(CHANGE_EVENT);
+            javaScriptSupport.require("core/select");
 
-            JSONObject spec = new JSONObject("selectId", getClientId(), "zoneId", zone, "url", link.toURI());
+            Link link = resources.createEventLink(CHANGE_EVENT);
 
-            javascriptSupport.addInitializerCall("linkSelectToZone", spec);
+            writer.attributes(
+                    "data-update-zone", zone,
+                    "data-update-url", link);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/212ad9ce/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 54a21f4..52f0068 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
@@ -613,23 +613,6 @@ define("core/compat/tapestry", [
             });
         },
 
-
-        /**
-         * Converts a link into an Ajax update of a Zone. The url includes
-         * the information to reconnect with the server-side Form.
-         *
-         * @param spec.selectId
-         *            id or instance of &lt;select&gt;
-         * @param spec.zoneId
-         *            id of element to update when select is changed
-         * @param spec.url
-         *            component event request URL
-         */
-        linkSelectToZone: function (spec) {
-            Tapestry.Initializer.updateZoneOnEvent("change", spec.selectId,
-                    spec.zoneId, spec.url);
-        },
-
         linkSubmit: function (spec) {
 
             Tapestry.replaceElementTagName(spec.clientId, "A");