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 2012/11/20 16:13:13 UTC
[1/4] git commit: Support informal parameters on the AjaxFormLoop -
informals are added to each row,
including the "tail" row - make a distinction between the element to insert
before (on the client), and the element which triggers the insert - trigger a
Updated Branches:
refs/heads/5.4-js-rewrite b927ceb14 -> 64f4d9a3c
Support informal parameters on the AjaxFormLoop
- informals are added to each row, including the "tail" row
- make a distinction between the element to insert before (on the client), and the element which triggers the insert
- trigger a zone update on the inserted row, to support components such as DateField that scan newly added content
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/64f4d9a3
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/64f4d9a3
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/64f4d9a3
Branch: refs/heads/5.4-js-rewrite
Commit: 64f4d9a3c371d91d9e68dd0d2fd3e5c497e2ef60
Parents: e9e07c9
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Nov 20 07:12:58 2012 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Nov 20 07:12:58 2012 -0800
----------------------------------------------------------------------
.../META-INF/modules/core/ajaxformloop.coffee | 16 +++++-----
.../META-INF/modules/core/events.coffee | 7 ++++-
.../tapestry5/corelib/components/AddRowLink.java | 17 +---------
.../tapestry5/corelib/components/AjaxFormLoop.java | 23 ++++++++++----
.../tapestry5/corelib/components/AjaxFormLoop.tml | 18 +++++++----
5 files changed, 43 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64f4d9a3/tapestry-core/src/main/coffeescript/META-INF/modules/core/ajaxformloop.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/ajaxformloop.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/ajaxformloop.coffee
index 6ec63d7..6dc0adf 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/ajaxformloop.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/ajaxformloop.coffee
@@ -20,7 +20,7 @@ define ["core/dom", "core/events", "core/console", "core/ajax", "core/builder"],
(dom, events, console, ajax, builder) ->
# "afl" is short for "AjaxFormLoop".
- AFL_SELECTOR = "[data-container-type=core/ajaxformloop]"
+ AFL_SELECTOR = "[data-container-type=core/AjaxFormLoop]"
FRAGMENT_TYPE = "core/ajaxformloop-fragment"
dom.onDocument "click", "#{AFL_SELECTOR} [data-afl-behavior=remove]", ->
@@ -50,13 +50,11 @@ define ["core/dom", "core/events", "core/console", "core/ajax", "core/builder"],
return false
- dom.onDocument "click", "#{AFL_SELECTOR} [data-afl-behavior=insert-before]", ->
+ dom.onDocument "click", "#{AFL_SELECTOR} [data-afl-behavior=insert-before] [data-afl-trigger=add]", ->
afl = this.findContainer AFL_SELECTOR
- unless afl
- console.error "Enclosing element for AjaxFormLoop inject row link not found."
- return false
+ insertionPoint = this.findContainer "[data-afl-behavior=insert-before]"
url = afl.attribute "data-inject-row-url"
@@ -64,18 +62,20 @@ define ["core/dom", "core/events", "core/console", "core/ajax", "core/builder"],
onsuccess: (response) =>
content = response.responseJSON?.content
- insertionPoint = this.findContainer "[data-container-type=#{FRAGMENT_TYPE}]"
-
# Create a new element with the same type (usually "div") and class as this element.
# It will contain the new content.
newElement = builder insertionPoint.element.tagName,
- class: insertionPoint.element.class,
+ class: insertionPoint.element.className,
"data-container-type": FRAGMENT_TYPE
newElement.update content
insertionPoint.insertBefore newElement
+ # Trigger this event, to inform the world that the zone-like new element has been updated
+ # with content.
+ newElement.trigger events.zone.didUpdate,
+
return false
# This module is all event handlers, and no exported functions.
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64f4d9a3/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
index bb874b6..b252ca7 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/events.coffee
@@ -122,7 +122,12 @@ define
willUpdate: "t5:zone:will-update"
# Triggered (by the standard hanndler) just after the content in a Zone has updated. If the zone was not visible, it
- # is made visible after its content is changed, and before this event is triggered.
+ # is made visible after its content is changed, and before this event is triggered. Some number of other components that
+ # also perform Ajax updates of the page also trigger this event.
+ #
+ # Certain components bind this event to scan new additions to the page to see if certain structures exist and
+ # create client-side support in the form of controllers and event handlers. DateField is one such example
+ # (see `core/datefield` module).
didUpdate: "t5:zone:did-update"
# Triggered on a zone element, the default handler will peform an Ajax request and, when the response is available,
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64f4d9a3/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AddRowLink.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AddRowLink.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AddRowLink.java
index b9ef3c5..394d377 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AddRowLink.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AddRowLink.java
@@ -1,4 +1,4 @@
-// Copyright 2008, 2010, 2011 The Apache Software Foundation
+// Copyright 2008, 2010, 2011, 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.
@@ -16,11 +16,8 @@ package org.apache.tapestry5.corelib.components;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.SupportsInformalParameters;
-import org.apache.tapestry5.corelib.internal.AjaxFormLoopContext;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.services.javascript.JavaScriptSupport;
/**
* Used inside an {@link org.apache.tapestry5.corelib.components.AjaxFormLoop} component to spur the addition of a new
@@ -33,24 +30,14 @@ import org.apache.tapestry5.services.javascript.JavaScriptSupport;
@SupportsInformalParameters
public class AddRowLink
{
- @Environmental
- private AjaxFormLoopContext context;
-
- @Inject
- private JavaScriptSupport jsSupport;
-
@Inject
private ComponentResources resources;
void beginRender(MarkupWriter writer)
{
- writer.element("a",
- "href", "#",
- "data-afl-behavior", "insert-before");
+ writer.element("a", "href", "#", "data-afl-trigger", "add");
resources.renderInformalParameters(writer);
-
-
}
void afterRender(MarkupWriter writer)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64f4d9a3/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
index 3db5c7e..fdebe11 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
@@ -57,6 +57,7 @@ import java.util.Iterator;
@Events(
{EventConstants.ADD_ROW, EventConstants.REMOVE_ROW})
@Import(module = "core/ajaxformloop")
+@SupportsInformalParameters
public class AjaxFormLoop
{
/**
@@ -151,7 +152,6 @@ public class AjaxFormLoop
@Inject
private ComponentDefaultProvider defaultProvider;
-
@Inject
private AjaxResponseRenderer ajaxResponseRenderer;
@@ -319,7 +319,7 @@ public class AjaxFormLoop
injectRowLink.addParameter(RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
writer.element("div",
- "data-container-type", "core/ajaxformloop",
+ "data-container-type", "core/AjaxFormLoop",
"data-remove-row-url", removeRowLink,
"data-inject-row-url", injectRowLink);
}
@@ -331,20 +331,20 @@ public class AjaxFormLoop
boolean beginRender(MarkupWriter writer)
{
- writer.element("div", "data-container-type", "core/ajaxformloop-fragment");
-
if (!iterator.hasNext())
+ {
return false;
+ }
value = iterator.next();
- return true; // Render body, etc.
+ // Return true: render the body for this value; that ends up being a form-fragment.
+
+ return true;
}
Object afterRender(MarkupWriter writer)
{
- writer.end();
-
// When out of source items to render, switch over to the addRow block (either the default,
// or from the addRow parameter) before proceeding to cleanup render.
@@ -358,6 +358,15 @@ public class AjaxFormLoop
return false;
}
+ // Capture BeginRender event from the formfragment or the addRowWrapper, and render the informal parameters
+ // into the row.
+ boolean onBeginRender(MarkupWriter writer)
+ {
+ resources.renderInformalParameters(writer);
+
+ return true;
+ }
+
void cleanupRender(MarkupWriter writer)
{
writer.end();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/64f4d9a3/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
index bad4199..7f08c26 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
@@ -1,19 +1,23 @@
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
- <t:formfragment t:id="fragment" element="prop:element" visible="true">
+ <t:formfragment t:id="fragment" element="prop:element" visible="true" t:mixins="rendernotification"
+ data-container-type="core/ajaxformloop-fragment">
<t:delegate to="block:ajaxResponse"/>
</t:formfragment>
<t:block id="tail">
- <div data-container-type="core/ajaxformloop-fragment">
- <t:any element="prop:element" data-afl-behavior="insert-before">
- <t:delegate to="prop:addRow"/>
- </t:any>
- </div>
+ <t:any t:id="addRowWrapper"
+ t:mixins="rendernotification"
+ element="prop:element" data-afl-behavior="insert-before"
+ data-container-type="core/ajaxformloop-fragment">
+ <t:delegate to="prop:addRow"/>
+ </t:any>
</t:block>
<t:block id="defaultAddRow">
- <t:addrowlink class="btn"><i class="icon-add"/> Add row</t:addrowlink>
+ <div class="controls">
+ <t:addrowlink class="btn"><i class="icon-plus-sign"/> Add row</t:addrowlink>
+ </div>
</t:block>
<t:block id="ajaxResponse">