You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/07/19 23:31:45 UTC
svn commit: r1148548 [1/3] - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/mixins/
main/java/org/apache/tapestry5/internal/services/javascript/
main/resources/org/apache/tapestry5/ test/java/org/apache/tapestry5...
Author: hlship
Date: Tue Jul 19 21:31:44 2011
New Revision: 1148548
URL: http://svn.apache.org/viewvc?rev=1148548&view=rev
Log:
TAP5-1578: Rework how and when FormFragment enables/disables the hidden field
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-formfragment.js
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/TriggerFragment.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-core.js
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-init.js
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tree.js
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFragmentDemo.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/TriggerFragment.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/TriggerFragment.java?rev=1148548&r1=1148547&r2=1148548&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/TriggerFragment.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/TriggerFragment.java Tue Jul 19 21:31:44 2011
@@ -30,7 +30,7 @@ import org.apache.tapestry5.services.jav
* {@link org.apache.tapestry5.corelib.components.Radio} component that will link the input field and a
* {@link org.apache.tapestry5.corelib.components.FormFragment}, making the field control the client-side visibility of
* the FormFragment. See a full example with {@link FormFragment}'s documentation.
- *
+ *
* @tapestrydoc
*/
public class TriggerFragment
@@ -47,7 +47,7 @@ public class TriggerFragment
/**
* If true then the client-side logic is inverted; the fragment is made visible when the checkbox is NOT checked.
* The default is false (the fragment is visible when the checkbox IS checked).
- *
+ *
* @since 5.2.0
*/
@Parameter
@@ -59,8 +59,7 @@ public class TriggerFragment
@HeartbeatDeferred
void beginRender()
{
- JSONObject spec = new JSONObject("triggerId", container.getClientId(), "fragmentId", fragment.getClientId());
- spec.put("invert", invert);
+ JSONObject spec = new JSONObject("triggerId", container.getClientId(), "fragmentId", fragment.getClientId()).put("invert", invert);
javascriptSupport.addInitializerCall("linkTriggerToFormFragment", spec);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java?rev=1148548&r1=1148547&r2=1148548&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/CoreJavaScriptStack.java Tue Jul 19 21:31:44 2011
@@ -59,7 +59,8 @@ public class CoreJavaScriptStack impleme
"${tapestry.scriptaculous}/effects.js",
- // Uses functions defined by the prior three.
+ // Below uses functions defined by the prior three.
+
// Order is important, there are some dependencies
// going on here. Switching over to a more managed module system
// is starting to look like a really nice idea!
@@ -86,6 +87,8 @@ public class CoreJavaScriptStack impleme
ROOT + "/t5-ajax.js",
+ ROOT + "/t5-formfragment.js",
+
ROOT + "/tapestry.js",
ROOT + "/tapestry-console.js",
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-core.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-core.js?rev=1148548&r1=1148547&r2=1148548&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-core.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-core.js Tue Jul 19 21:31:44 2011
@@ -17,47 +17,46 @@
* The master T5 namespace. A few critical functions are added directly to T5,
* but mostly it is used as a containing namespace for namespaces defined by
* other modules.
- *
+ *
* @since 5.3
*/
var T5 = {
- /**
- * Extends an object using a source. In the simple case, the source object's
- * properties are overlaid on top of the destination object. In the typical
- * case, the source parameter is a function that returns the source object
- * ... this is to facilitate modularity and encapsulation.
- *
- * @param destination
- * object to receive new or updated properties
- * @param source
- * source object for properties, or function returning source
- * object
- * @returns the destination object
- */
- extend : function(destination, source) {
- if (typeof source == "function") {
- source = source();
- }
+ /**
+ * Extends an object using a source. In the simple case, the source object's
+ * properties are overlaid on top of the destination object. In the typical
+ * case, the source parameter is a function that returns the source object
+ * ... this is to facilitate modularity and encapsulation.
+ *
+ * @param destination
+ * object to receive new or updated properties
+ * @param source
+ * source object for properties, or function returning source
+ * object
+ * @returns the destination object
+ */
+ extend : function(destination, source) {
+ if (typeof source == "function") {
+ source = source();
+ }
- // Prototype:
- return Object.extend(destination, source);
- },
+ // Prototype:
+ return Object.extend(destination, source);
+ },
- /**
- * Defines a new namespace under the T5 object.
- *
- * @param name
- * string name of the namespace
- * @param source
- * source object for properties (or function returning source
- * object)
- * @return the namespace object
- */
- define : function(name, source) {
- var namespace = {};
- T5[name] = namespace;
-
- return this.extend(namespace, source);
- }
+ /**
+ * Defines a new namespace under the T5 object.
+ *
+ * @param name
+ * string name of the namespace
+ * @param source
+ * source object for properties (or function returning source
+ * object)
+ * @return the namespace object
+ */
+ define : function(name, source) {
+ var namespace = {};
+ T5[name] = namespace;
+ return this.extend(namespace, source);
+ }
}
\ No newline at end of file
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-formfragment.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-formfragment.js?rev=1148548&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-formfragment.js (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-formfragment.js Tue Jul 19 21:31:44 2011
@@ -0,0 +1,83 @@
+T5.extendInitializers(function() {
+
+ function init(spec) {
+
+ var element = $(spec.element);
+
+ var hidden = $(spec.element + "-hidden");
+ var form = $(hidden.form);
+
+ if (! spec.alwaysSubmit) {
+ hidden.disabled = ! element.isDeepVisible();
+ }
+
+ function updateUI(makeVisible) {
+
+ if (! spec.alwaysSubmit) {
+ hidden.disabled = ! (makeVisible && element.parentNode.isDeepVisible());
+ }
+
+ var effect = makeVisible ? Tapestry.ElementEffect[spec.show]
+ || Tapestry.ElementEffect.slidedown
+ : Tapestry.ElementEffect[spec.hide]
+ || Tapestry.ElementEffect.slideup;
+ return effect(element);
+ }
+
+ element.observe(Tapestry.CHANGE_VISIBILITY_EVENT, function(event) {
+ // Since events propagate up, you have to call event.stop()
+ // here to prevent hiding/revealing any container FormFragment elements.
+ event.stop();
+
+ var makeVisible = event.memo.visible;
+
+ if (makeVisible == element.visible())
+ return;
+
+ updateUI(makeVisible);
+ });
+
+ element.observe(Tapestry.HIDE_AND_REMOVE_EVENT,
+ function(event) {
+ event.stop();
+ var effect = updateUI(false);
+
+ effect.options.afterFinish = function() {
+ Tapestry.remove(element);
+ };
+ });
+ }
+
+ /**
+ * Links a FormFragment to a trigger (a radio or a checkbox), such
+ * that changing the trigger will hide or show the FormFragment.
+ * Care should be taken to render the page with the checkbox and the
+ * FormFragment's visibility in agreement.
+ */
+ function linker(spec) {
+ var trigger = $(spec.triggerId);
+
+ function update() {
+ var checked = trigger.checked;
+ var makeVisible = checked == !spec.invert;
+
+ $(spec.fragmentId).fire(Tapestry.CHANGE_VISIBILITY_EVENT, {
+ visible : makeVisible
+ }, true);
+ }
+
+ // Let the event bubble up to the form level.
+ if (trigger.type == "radio") {
+ $(trigger.form).observe("click", update);
+ return;
+ }
+
+ // Normal trigger is a checkbox; listen just to it.
+ trigger.observe("click", update);
+ }
+
+ return {
+ formFragment : init,
+ linkTriggerToFormFragment : linker
+ };
+});
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-init.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-init.js?rev=1148548&r1=1148547&r2=1148548&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-init.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/t5-init.js Tue Jul 19 21:31:44 2011
@@ -21,16 +21,16 @@ T5.extend(T5, function() {
* The T5.Initializer namespace, which contains functions used to
* perform page load initializations.
*/
- Initializer : {},
+ initializers : {},
/**
* A convenience method for extending the T5.Initializer namespace.
*
* @param source
- * object or function used to extend T5.Initializer
+ * object or function used to extend T5.initializers
*/
- extendInitializer : function(source) {
- T5.extend(T5.Initializer, source);
+ extendInitializers : function(source) {
+ T5.extend(T5.initializers, source);
}
};
});
\ No newline at end of file