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 2008/04/23 19:23:48 UTC

svn commit: r650942 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/services/ main/resources/org/apache/tapestry/ test/java/org/apache/tapestry/integration/ test/java/org/...

Author: hlship
Date: Wed Apr 23 10:23:23 2008
New Revision: 650942

URL: http://svn.apache.org/viewvc?rev=650942&view=rev
Log:
TAPESTRY-2381: Linking a radio button as a FormFragment trigger does not appear to work in IE 7

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_in_development_mode.txt
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/DocumentLinkerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/tapestry.js
    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/internal/services/DocumentLinkerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/DocumentLinkerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/DocumentLinkerImpl.java?rev=650942&r1=650941&r2=650942&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/DocumentLinkerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/DocumentLinkerImpl.java Wed Apr 23 10:23:23 2008
@@ -33,6 +33,13 @@
 
     private final List<IncludedStylesheet> _includedStylesheets = newList();
 
+    private final boolean _developmentMode;
+
+    public DocumentLinkerImpl(boolean productionMode)
+    {
+        _developmentMode = !productionMode;
+    }
+
     private class IncludedStylesheet
     {
         private final String _url;
@@ -120,17 +127,21 @@
 
         // TAPESTRY-2364
 
+
         for (String scriptURL : _scripts)
         {
             body.element("script", "src", scriptURL, "type", "text/javascript");
         }
 
-        if (_scriptBlock.length() > 0)
+        boolean blockNeeded = (_developmentMode && !_scripts.isEmpty()) || _scriptBlock.length() > 0;
+
+        if (blockNeeded)
         {
             Element e = body.element("script", "type", "text/javascript");
             e.raw("\n<!--\n");
 
-            // This assumes that Prototype and tapestry.js is available.
+            if (_developmentMode)
+                e.text("Tapestry.DEBUG_ENABLED = true;\n");
 
             e.text("Tapestry.onDOMLoaded(function() {\n");
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=650942&r1=650941&r2=650942&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Wed Apr 23 10:23:23 2008
@@ -1425,6 +1425,9 @@
      */
     public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration,
 
+                                         @Symbol(TapestryConstants.PRODUCTION_MODE_SYMBOL)
+                                         final boolean productionMode,
+
                                          @Path("${tapestry.default-stylesheet}")
                                          final Asset stylesheetAsset,
 
@@ -1441,7 +1444,7 @@
         {
             public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer)
             {
-                DocumentLinkerImpl linker = new DocumentLinkerImpl();
+                DocumentLinkerImpl linker = new DocumentLinkerImpl(productionMode);
 
                 PageRenderSupportImpl support = new PageRenderSupportImpl(linker, symbolSource, assetSource,
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css?rev=650942&r1=650941&r2=650942&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry/default.css Wed Apr 23 10:23:23 2008
@@ -384,4 +384,33 @@
 
 UL.t-data-list LI {
     list-style-type: square;
+}
+
+/* The console is used to show debugging messages. */
+DIV.t-console {
+    position: absolute;
+    z-index: 1;
+    top: 2px;
+    left: 2px;
+}
+
+DIV.t-console DIV {
+    font-weight: bold;
+    cursor: pointer;
+    padding: 0px 2px;
+}
+
+DIV.t-console DIV.t-err {
+    background-color: red;
+    color: white;
+}
+
+DIV.t-console DIV.t-warn {
+    background-color: yellow;
+    color: black;
+}
+
+DIV.t-console DIV.t-debug {
+    background-color: silver;
+    color: black;
 }

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=650942&r1=650941&r2=650942&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 Apr 23 10:23:23 2008
@@ -18,6 +18,11 @@
 
     FORM_PREPARE_FOR_SUBMIT_EVENT : "form:prepareforsubmit",
 
+    DEBUG_ENABLED : false,
+
+    /** Time, in seconds, that console messages are visible. */
+    CONSOLE_DURATION : 10,
+
     FormEvent : Class.create(),
 
     FormEventManager : Class.create(),
@@ -97,11 +102,14 @@
         $H(spec).each(function(pair)
         {
             var functionName = pair.key;
+
+            // Tapestry.logWarning("Initialize: #{name} ...", { name:functionName });
+
             var initf = Tapestry.Initializer[functionName];
 
             if (initf == undefined)
             {
-                Tapestry.logError("Function Tapestry.Initializer.#{name}() does not exist.", { name:functionName });
+                Tapestry.error("Function Tapestry.Initializer.#{name}() does not exist.", { name:functionName });
                 return;
             }
 
@@ -117,11 +125,52 @@
         });
     },
 
-    logError : function (message, substitutions)
+    error : function (message, substitutions)
+    {
+        Tapestry.updateConsole("t-err", message, substitutions);
+    },
+
+    warn : function (message, substitutions)
+    {
+        Tapestry.updateConsole("t-warn", message, substitutions);
+    },
+
+    debug : function (message, substitutions)
     {
-        var formatted = message.interpolate(substitutions);
+        if (Tapestry.DEBUG_ENABLED)
+            Tapestry.updateConsole("t-debug", message, substitutions);
+    },
+
+    updateConsole : function (className, message, substitutions)
+    {
+        if (substitutions != undefined)
+            message = message.interpolate(substitutions);
+
+        if (Tapestry.console == undefined)
+        {
+            var body = $$("BODY").first();
+
+            Tapestry.console = new Element("div", { 'class': "t-console" });
+
+            body.insert({ bottom: Tapestry.console });
+        }
+
+        var div = new Element("div", { 'class': className }).update(message);
+
+        Tapestry.console.insert({ bottom: div });
+
+        var effect = new Effect.BlindUp(div, { delay: Tapestry.CONSOLE_DURATION,
+            afterFinish: function()
+            {
+                div.remove();
+            }});
+
+        div.observe("click", function()
+        {
+            effect.cancel();
+            div.remove();
+        });
 
-        window.alert(formatted);
     },
 
     getFormEventManager : function(form)
@@ -252,7 +301,7 @@
 
             if (vfunc == undefined)
             {
-                Tapestry.logError("Function Tapestry.Validator.#{name}() does not exist for field '#{fieldName}'.", {name:name, fieldName:pair.key});
+                Tapestry.error("Function Tapestry.Validator.#{name}() does not exist for field '#{fieldName}'.", {name:name, fieldName:pair.key});
                 return;
             }
 
@@ -283,22 +332,26 @@
     {
         trigger = $(trigger);
 
-        trigger.observe("change", function()
-        {
-            $(element).formFragment.setVisible(trigger.checked);
-        });
-
-
         if (trigger.type == "radio")
         {
-            $(trigger.form).observe("change", function()
+            $(trigger.form).observe("click", function()
             {
-                if (! trigger.checked)
-                {
-                    $(element).formFragment.hide();
-                }
+                $(element).formFragment.setVisible(trigger.checked);
             });
+
+            return;
         }
+
+        // Otherwise, we assume it is a checkbox.  The difference is
+        // that we can observe just the single checkbox element,
+        // rather than handling clicks anywhere in the form (as with
+        // the radio).
+
+        trigger.observe("click", function()
+        {
+            $(element).formFragment.setVisible(trigger.checked);
+        });
+
     }
 };
 
@@ -451,7 +504,7 @@
         this.innerSpan = new Element("span");
         this.outerDiv = $(new Element("div", { 'class' : 't-error-popup' })).update(this.innerSpan).hide();
 
-        var body = $$('body')[0];
+        var body = $$('BODY').first();
 
         body.insert({ bottom: this.outerDiv });
 

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=650942&r1=650941&r2=650942&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 Apr 23 10:23:23 2008
@@ -1853,7 +1853,7 @@
 
         click("link=Add a row");
 
-        sleep(500);
+        sleep(1000);
 
         type("//input[@type='text'][1]", "5.1");
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java?rev=650942&r1=650941&r2=650942&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/DocumentLinkerImplTest.java Wed Apr 23 10:23:23 2008
@@ -33,7 +33,7 @@
 
         document.newRootElement("not-html").text("not an HTML document");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addScript("foo.js");
         linker.addScript("doSomething();");
@@ -50,7 +50,7 @@
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addScriptLink("foo.js");
         linker.addScriptLink("bar/baz.js");
@@ -67,7 +67,7 @@
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with styles.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addStylesheetLink("foo.css", null);
         linker.addStylesheetLink("bar/baz.css", "print");
@@ -84,7 +84,7 @@
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with styles.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addStylesheetLink("foo.css", null);
         linker.addStylesheetLink("bar/baz.css", "print");
@@ -105,7 +105,7 @@
         document.newRootElement("html").element("head").comment("existing head").getParent()
                 .element("body").text("body content");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addStylesheetLink("foo.css", null);
 
@@ -121,7 +121,7 @@
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         for (int i = 0; i < 3; i++)
         {
@@ -142,7 +142,7 @@
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addScript("doSomething();");
         linker.addScript("doSomethingElse();");
@@ -152,6 +152,22 @@
         assertEquals(document.toString(), readFile("add_script.txt").trim());
     }
 
+    @Test
+    public void add_script_in_development_mode() throws Exception
+    {
+        Document document = new Document();
+
+        document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.");
+
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(false);
+
+        linker.addScriptLink("foo.js");
+
+        linker.updateDocument(document);
+
+        assertEquals(document.toString(), readFile("add_script_in_development_mode.txt").trim());
+    }
+
     /**
      * Perhaps the linker should create the &lt;body&gt; element in this case? In the meantime,
      */
@@ -162,7 +178,7 @@
 
         document.newRootElement("html").element("notbody").element("p").text("Ready to be updated with scripts.");
 
-        DocumentLinkerImpl linker = new DocumentLinkerImpl();
+        DocumentLinkerImpl linker = new DocumentLinkerImpl(true);
 
         linker.addScriptLink("foo.js");
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_in_development_mode.txt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_in_development_mode.txt?rev=650942&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_in_development_mode.txt (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry/internal/services/add_script_in_development_mode.txt Wed Apr 23 10:23:23 2008
@@ -0,0 +1,7 @@
+<html><body><p>Ready to be updated with scripts.</p><script src="foo.js" type="text/javascript"></script><script type="text/javascript">
+<!--
+Tapestry.DEBUG_ENABLED = true;
+Tapestry.onDOMLoaded(function() {
+});
+// -->
+</script></body></html>
\ No newline at end of file