Browse files

Capture the click event and use it again after confirming the action

Fixes #29
  • Loading branch information...
1 parent f314e45 commit 6dea8b11b88dc55dc4ccd7e71da094e71059add7 @hlship committed Jun 20, 2011
View
5 tapx-core/src/main/resources/com/howardlewisship/tapx/core/tapx.js
@@ -349,6 +349,7 @@ Tapx.extendInitializer(function() {
var type = element.type;
var interceptClickEvent = true;
+ var capturedClickEvent;
/*
* Replace the normal click event, knowing that in most cases, the
@@ -359,7 +360,7 @@ Tapx.extendInitializer(function() {
function doAction() {
if ($T(element).hasAction) {
- element.fire(Tapestry.ACTION_EVENT, event);
+ element.fire(Tapestry.ACTION_EVENT, capturedClickEvent);
return;
}
@@ -387,6 +388,8 @@ Tapx.extendInitializer(function() {
if (interceptClickEvent) {
event.stop();
+
+ capturedClickEvent = event;
if ($(element).hasClassName('tx-disable-confirm')) {
doAction();
View
59 tapx-core/src/test/java/core/demo/pages/ConfirmDemo.java
@@ -1,4 +1,4 @@
-// Copyright 2010 Howard M. Lewis Ship
+// Copyright 2010, 2011 Howard M. Lewis Ship
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -20,32 +20,33 @@
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
-public class ConfirmDemo
-{
- @Property
- @Persist(PersistenceConstants.FLASH)
- private String message;
-
- @InjectComponent
- private Zone zone;
-
- void onActionFromLink1()
- {
- message = "update from link1";
- }
-
- Object onActionFromLink2()
- {
- return zone.getBody();
- }
-
- void onSuccessFromForm()
- {
- message = "update via form submit";
- }
-
- void onActionFromLink3()
- {
- message = "update from link3";
- }
+public class ConfirmDemo {
+ @Property
+ @Persist(PersistenceConstants.FLASH)
+ private String message;
+
+ @InjectComponent
+ private Zone zone, messageZone;
+
+ void onActionFromLink1() {
+ message = "update from link1";
+ }
+
+ Object onActionFromLink2() {
+ return zone.getBody();
+ }
+
+ void onSuccessFromForm() {
+ message = "update via form submit";
+ }
+
+ Object onSuccessFromZoneForm() {
+ message = "update via zone form submit";
+
+ return messageZone.getBody();
+ }
+
+ void onActionFromLink3() {
+ message = "update from link3";
+ }
}
View
55 tapx-core/src/test/resources/core/demo/pages/ConfirmDemo.tml
@@ -1,27 +1,38 @@
-<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:tx="tapestry-library:tapx">
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
+ xmlns:tx="tapestry-library:tapx">
- <p id="message">${message}</p>
+ <t:zone id="messageZone" t:id="messageZone">
+ <p id="message">${message}</p>
+ </t:zone>
- <ul>
- <li>
- <t:actionlink t:id="link1" t:mixins="tapx/confirm">actionlink</t:actionlink>
- </li>
- <li>
- <t:actionlink t:id="link2" zone="zone" t:mixins="tapx/confirm" title="Update zone?"
- message="Custom message?">zone update link</t:actionlink>
- </li>
- <li>
- <t:actionlink class="tx-disable-confirm" t:id="link3" t:mixins="tapx/confirm">confirm disabled
+ <ul>
+ <li>
+ <t:actionlink t:id="link1" t:mixins="tapx/confirm">actionlink
+ </t:actionlink>
+ </li>
+ <li>
+ <t:actionlink t:id="link2" zone="zone" t:mixins="tapx/confirm"
+ title="Update zone?" message="Custom message?">zone update link</t:actionlink>
+ </li>
+ <li>
+ <t:actionlink class="tx-disable-confirm" t:id="link3"
+ t:mixins="tapx/confirm">confirm disabled
</t:actionlink>
- </li>
- <li>
- <t:form t:id="form">
- <t:submit value="Form Submit" t:mixins="tapx/confirm"/>
- </t:form>
- </li>
- </ul>
+ </li>
+ <li>
+ <t:form t:id="form">
+ <t:submit value="Form Submit" t:mixins="tapx/confirm" />
+ </t:form>
+ </li>
+ <li>
+ <t:form t:id="zoneForm" zone="messageZone">
+ <t:submit value="Zone Form Submit" t:mixins="tapx/confirm" mode="cancel"/>
+ </t:form>
+ </li>
- <t:zone t:id="zone" id="zone" visible="false">
- <p id="zone-message">Zone link was clicked.</p>
- </t:zone>
+ </ul>
+
+ <t:zone t:id="zone" id="zone" visible="false">
+ <p id="zone-message">Zone link was clicked.</p>
+ </t:zone>
</t:layout>

0 comments on commit 6dea8b1

Please sign in to comment.