Good catch, I'll work on the test.

Sven

On 08.07.2015 12:05, Martin Grigorov wrote:
Hi Sven,

On Wed, Jul 8, 2015 at 12:58 PM, <[email protected]> wrote:

Repository: wicket
Updated Branches:
   refs/heads/wicket-6.x 6fa8616f4 -> 051bb4d08


WICKET-5945 /ajax/call/done

Conflicts:

wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/051bb4d0
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/051bb4d0
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/051bb4d0

Branch: refs/heads/wicket-6.x
Commit: 051bb4d08cbf13ec85e434f37df2fcf380987d60
Parents: 6fa8616
Author: Sven Meier <[email protected]>
Authored: Wed Jul 8 11:41:27 2015 +0200
Committer: Sven Meier <[email protected]>
Committed: Wed Jul 8 11:57:17 2015 +0200

----------------------------------------------------------------------
  .../ajax/AbstractDefaultAjaxBehavior.java       |  8 ++++
  .../ajax/attributes/AjaxAttributeName.java      |  7 ++++
  .../ajax/attributes/AjaxCallListener.java       | 40 ++++++++++++++++++++
  .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 18 ++++-----
  .../wicket/ajax/res/js/wicket-event-jquery.js   |  1 +
  .../ajax/attributes/AjaxAttributeNameTest.java  |  3 +-
  6 files changed, 66 insertions(+), 11 deletions(-)
----------------------------------------------------------------------



http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
----------------------------------------------------------------------
diff --git
a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
index d95330d..06d52cd 100644
---
a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
+++
b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java
@@ -72,6 +72,7 @@ public abstract class AbstractDefaultAjaxBehavior
extends AbstractAjaxBehavior
         private static final String BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE
= "function(attrs, jqXHR, settings){%s}";
         private static final String BEFORE_HANDLER_FUNCTION_TEMPLATE =
"function(attrs){%s}";
         private static final String INIT_HANDLER_FUNCTION_TEMPLATE =
"function(attrs){%s}";
+       private static final String DONE_HANDLER_FUNCTION_TEMPLATE =
"function(attrs){%s}";

         /**
          * Subclasses should call super.onBind()
@@ -313,6 +314,13 @@ public abstract class AbstractDefaultAjaxBehavior
extends AbstractAjaxBehavior
                                         CharSequence precondition =
ajaxCallListener.getPrecondition(component);

appendListenerHandler(precondition, attributesJson,

AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
+
+                                       if (ajaxCallListener instanceof
AjaxCallListener) {
+                                               CharSequence doneHandler =
((AjaxCallListener) ajaxCallListener).getDoneHandler(component);
+
  appendListenerHandler(doneHandler, attributesJson,
+
  AjaxAttributeName.DONE_HANDLER.jsonName(),
+
  DONE_HANDLER_FUNCTION_TEMPLATE);
+                                       }
                                 }
                         }



http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java
----------------------------------------------------------------------
diff --git
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java
index 12edc71..bea715d 100644
---
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java
+++
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxAttributeName.java
@@ -181,6 +181,13 @@ public enum AjaxAttributeName {
         INIT_HANDLER("ih"),

         /**
+        * done handler (dh)
+        *
+        * @see
AjaxCallListener#getDoneHandler(org.apache.wicket.Component)
+        */
+       DONE_HANDLER("dh"),
+
+       /**
          * the indicator id, if any found (i)
          *
          * @see AbstractDefaultAjaxBehavior#findIndicatorId()


http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
----------------------------------------------------------------------
diff --git
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
index 927c4d7..3ba3fa7 100644
---
a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
+++
b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxCallListener.java
@@ -36,6 +36,7 @@ public class AjaxCallListener implements
IAjaxCallListener, IComponentAwareHeade
         private StringBuilder after;
         private StringBuilder complete;
         private StringBuilder precondition;
+       private StringBuilder done;

         /**
          * Sets the JavaScript code that will be returned by {@link
#getInitHandler(Component)}.
@@ -59,6 +60,27 @@ public class AjaxCallListener implements
IAjaxCallListener, IComponentAwareHeade
         }

         /**
+        * Sets the JavaScript code that will be returned by {@link
#getDoneHandler(Component)}.
+        * If this code was already set, the new one will be appended to
the existing one.
+        *
+        * @param init
+        *                      the JavaScript code for the corresponding
handler
+        * @return This
+        */
+       public AjaxCallListener onDone(final CharSequence done)
+       {
+               if (Strings.isEmpty(done) == false)
+               {
+                       if (this.done == null)
+                       {
+                               this.done = new StringBuilder();
+                       }
+                       this.done.append(done);
+               }
+               return this;
+       }
+
+       /**
          * Sets the JavaScript code that will be returned by {@link
#getBeforeHandler(Component)}.
          * If this code was already set, the new one will be appended to
the existing one.
          *
@@ -255,6 +277,24 @@ public class AjaxCallListener implements
IAjaxCallListener, IComponentAwareHeade
                 return precondition;
         }

+
+       /**
+        * The JavaScript that will be executed after the Ajax call is
done, regardless whether it was
+        * sent or not. The script will be executed in a function that
receives the following
+        * parameters:
+        * <ol>
+        * <li>attrs - the AjaxRequestAttributes as JSON</li>
+        * </ol>
+        * TODO Wicket 7: pull up into IAjaxCallListener
+        *
+        * @param component
+        *            the Component with the Ajax behavior
+        * @return the JavaScript that will be executed after the Ajax
call is done.
+        */
+       public CharSequence getDoneHandler(Component component) {
+               return done;
+       }
+
         @Override
         public void renderHead(Component component, IHeaderResponse
response)
         {


http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
----------------------------------------------------------------------
diff --git
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
index 794c2ef..44de5f0 100644
---
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
+++
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js
@@ -550,9 +550,6 @@
                  */
                 doAjax: function (attrs) {

-                       // keep channel for done()
-                       this.channel = attrs.ch;
-
                         var
                                 // the headers to use for each Ajax request
                                 headers = {
@@ -611,7 +608,7 @@
                                         }
                                         if (result === false) {
                                                 Wicket.Log.info("Ajax
request stopped because of precondition check, url: " + attrs.u);
-                                               self.done();
+                                               self.done(attrs);
                                                 return false;
                                         }
                                 }
@@ -702,7 +699,7 @@

self._executeHandlers(attrs.coh, attrs, jqXHR, textStatus);

we.publish(topic.AJAX_CALL_COMPLETE, attrs, jqXHR, textStatus);

-                                               self.done();
+                                               self.done(attrs);
                                                 return
FunctionsExecuter.DONE;
                                         }, self));

@@ -759,7 +756,7 @@
                                         // In case the page isn't really
redirected. For example say the redirect is to an octet-stream.
                                         // A file download popup will
appear but the page in the browser won't change.
                                         this.success(context);
-                                       this.done();
+                                       this.done(context.attrs);

                                         var rhttp  = /^http:\/\//,  //
checks whether the string starts with http://
                                             rhttps = /^https:\/\//; //
checks whether the string starts with https://
@@ -930,7 +927,7 @@
                                 this._executeHandlers(attrs.coh, attrs,
null, null);

Wicket.Event.publish(Wicket.Event.Topic.AJAX_CALL_COMPLETE, attrs, null,
null);

-                               this.done();
+                               this.done(attrs);
                                 return FunctionsExecuter.DONE;
                         }, this);

@@ -1112,8 +1109,11 @@
                         }, this));
                 },

-               done: function () {
-                       Wicket.channelManager.done(this.channel);
+               done: function (attrs) {
+                       this._executeHandlers(attrs.dh, attrs);
+
  Wicket.Event.publish(Wicket.Event.Topic.AJAX_CALL_DONE, attrs);
+
+                       Wicket.channelManager.done(attrs.channel);

s/attrs.channel/attrs.ch/


                 },

                 // Adds a closure that replaces a component


http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js
----------------------------------------------------------------------
diff --git
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js
index 248c99b..1a83c4c 100644
---
a/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js
+++
b/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-event-jquery.js
@@ -323,6 +323,7 @@
                                 AJAX_CALL_COMPLETE     :
'/ajax/call/complete',
                                 AJAX_CALL_AFTER        :
'/ajax/call/after',
                                 AJAX_CALL_FAILURE      :
'/ajax/call/failure',
+                               AJAX_CALL_DONE         : '/ajax/call/done',
                                 AJAX_HANDLERS_BOUND    :
'/ajax/handlers/bound'
                         }
                 }


http://git-wip-us.apache.org/repos/asf/wicket/blob/051bb4d0/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java
----------------------------------------------------------------------
diff --git
a/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java
b/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java
index 8a50bfe..1c9398b 100644
---
a/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java
+++
b/wicket-core/src/test/java/org/apache/wicket/ajax/attributes/AjaxAttributeNameTest.java
@@ -58,7 +58,6 @@ public class AjaxAttributeNameTest
                 }

                 Assert.assertEquals("all known json parameter names",
-
  
"tr|p|d|id|dt|wr|rt|ad|sp|ch|e|async|dep|ep|pre|coh|fh|sh|ah|bsh|bh|ih|i|sc|mp|f|c|m|u|sel|",
-                       sb.toString());
+
  
"tr|p|d|id|dt|wr|rt|ad|sp|ch|e|async|dep|ep|pre|coh|fh|sh|ah|bsh|bh|ih|dh|i|sc|mp|f|c|m|u|sel|",
sb.toString());
         }
  }


Please add JS Unit tests for the new handler.
Also add an entry to
http://ci.apache.org/projects/wicket/guide/6.x/guide/ajax.html#ajax_5

Thanks!


Reply via email to