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 2008/03/19 17:39:52 UTC

svn commit: r638930 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/corelib/mixins/ main/resources/org/apache/tapestry/ test/app1/ test/java/org/apache/tapestry/integration/ test/java/org/apache/tapestry/integration/app1...

Author: hlship
Date: Wed Mar 19 09:39:43 2008
New Revision: 638930

URL: http://svn.apache.org/viewvc?rev=638930&view=rev
Log:
TAPESTRY-2261: TriggerFragment mixin should work with Radio as well as Checkbox components
TAPESTRY-2262: TrigerFragment mixin will run the "show" animation even when the fragment is already visible

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentOutput.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/SubscribeData.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormFragmentDemo.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/mixins/TriggerFragment.java Wed Mar 19 09:39:43 2008
@@ -23,11 +23,10 @@
 import org.apache.tapestry.services.Heartbeat;
 
 /**
- * A mixin that can be applied to a Checkbox component that will link the checkbox and a FormFragment, making the
- * Checkbox control the client-side visibility of the FormFragment.
- *
- * @see org.apache.tapestry.corelib.components.Checkbox
- * @see org.apache.tapestry.corelib.components.FormFragment
+ * A mixin that can be applied to a {@link org.apache.tapestry.corelib.components.Checkbox} or {@link
+ * org.apache.tapestry.corelib.components.Radio} component that will link the input field and a {@link
+ * org.apache.tapestry.corelib.components.FormFragment}, making the field control the client-side visibility of the
+ * FormFragment.
  */
 public class TriggerFragment
 {
@@ -52,7 +51,7 @@
         {
             public void run()
             {
-                _pageRenderSupport.addScript("Tapestry.linkCheckboxToFormFragment('%s', '%s');",
+                _pageRenderSupport.addScript("Tapestry.linkTriggerToFormFragment('%s', '%s');",
                                              _container.getClientId(),
                                              _fragment.getClientId());
             }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js Wed Mar 19 09:39:43 2008
@@ -223,18 +223,30 @@
     },
 
 
-    // Links a FormFragment to a checkbox, such that changing the checkbox will hide
+    // 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.
 
-    linkCheckboxToFormFragment : function(checkbox, element)
+    linkTriggerToFormFragment : function(trigger, element)
     {
-        checkbox = $(checkbox);
+        trigger = $(trigger);
 
-        checkbox.observe("change", function()
+        trigger.observe("change", function()
         {
-            $(element).formFragment.setVisible(checkbox.checked);
+            $(element).formFragment.setVisible(trigger.checked);
         });
+
+
+        if (trigger.type == "radio")
+        {
+            $(trigger.form).observe("change", function()
+            {
+                if (! trigger.checked)
+                {
+                    $(element).formFragment.hide();
+                }
+            });
+        }
     },
 
     // Adds a validator for a field.  A FieldEventManager is added, if necessary.
@@ -691,7 +703,6 @@
         new Effect.SlideUp(element);
     },
 
-
     fade : function(element)
     {
         new Effect.Fade(element);
@@ -763,12 +774,14 @@
 
     hide : function()
     {
-        this.hideFunc(this.element);
+        if (this.element.visible())
+            this.hideFunc(this.element);
     },
 
     show : function()
     {
-        this.showFunc(this.element);
+        if (! this.element.visible())
+            this.showFunc(this.element);
     },
 
     toggle : function()

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentDemo.tml Wed Mar 19 09:39:43 2008
@@ -24,6 +24,24 @@
             </t:formfragment>
 
 
+            <br/>
+
+            <t:radiogroup value="codeVisible">
+                <t:radio t:id="on" label="On" value="true" t:mixins="triggerfragment" fragment="codeFragment"/>
+                <t:label for="on"/>
+                <t:radio t:id="off" label="Off" value="false"/>
+                <t:label for="off"/>
+            </t:radiogroup>
+
+
+            <t:formfragment t:id="codeFragment" visible="codeVisible">
+                <div class="t-beaneditor-row">
+                    <t:label for="code"/>
+                    <t:textfield t:id="code" value="subscribe.code"/>
+                </div>
+            </t:formfragment>
+
+
             <div class="t-beaneditor-row">
                 <input type="submit" value="Subscribe"/>
             </div>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentOutput.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentOutput.tml?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentOutput.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFragmentOutput.tml Wed Mar 19 09:39:43 2008
@@ -8,6 +8,8 @@
         <dd id="name">${subscribe.name}</dd>
         <dt>Email</dt>
         <dd id="email">${subscribe.email}</dd>
+        <dt>Code</dt>
+        <dd id="code">${subscribe.code}</dd>
     </dl>
 
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Wed Mar 19 09:39:43 2008
@@ -1690,13 +1690,19 @@
         clickAndWait("link=Clear");
 
         click("subscribeToEmail");
+        click("on");
         type("name", "Barney");
         type("email", "rubble@bedrock.gov");
+        type("code", "ABC123");
+
+        click("off");
+        sleep(1000);
 
         clickAndWait(SUBMIT);
 
         assertText("name", "Barney");
         assertText("email", "rubble@bedrock.gov");
+        assertText("code", "");
     }
 
     @Test

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/SubscribeData.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/SubscribeData.java?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/SubscribeData.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/data/SubscribeData.java Wed Mar 19 09:39:43 2008
@@ -21,6 +21,8 @@
     private String _name;
     private String _email;
 
+    private String _code;
+
     @Validate("required")
     public String getName()
     {
@@ -42,5 +44,16 @@
     public void setEmail(String email)
     {
         _email = email;
+    }
+
+    @Validate("required")
+    public String getCode()
+    {
+        return _code;
+    }
+
+    public void setCode(String code)
+    {
+        _code = code;
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormFragmentDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormFragmentDemo.java?rev=638930&r1=638929&r2=638930&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormFragmentDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/FormFragmentDemo.java Wed Mar 19 09:39:43 2008
@@ -16,15 +16,21 @@
 
 import org.apache.tapestry.annotations.Component;
 import org.apache.tapestry.annotations.InjectPage;
+import org.apache.tapestry.annotations.Property;
 import org.apache.tapestry.corelib.components.Form;
 import org.apache.tapestry.integration.app1.data.SubscribeData;
 
 public class FormFragmentDemo
 {
+    @Property
     private SubscribeData _subscribe;
 
+    @Property
     private boolean _subscribeToEmail;
 
+    @Property
+    private boolean _codeVisible;
+
     @Component
     private Form _form;
 
@@ -36,16 +42,6 @@
         return _subscribe;
     }
 
-    public boolean isSubscribeToEmail()
-    {
-        return _subscribeToEmail;
-    }
-
-    public void setSubscribeToEmail(boolean subscribeToEmail)
-    {
-        _subscribeToEmail = subscribeToEmail;
-    }
-
     void onPrepare()
     {
         _subscribe = new SubscribeData();
@@ -63,8 +59,6 @@
 
     Object onSuccess()
     {
-
-
         return _outputPage.initialize(_subscribe);
     }
 }