This is an automated email from the ASF dual-hosted git repository.

reiern70 pushed a commit to branch 
improvement/reiern70/abort-ajax-qeruest-in-a-channel
in repository https://gitbox.apache.org/repos/asf/wicket.git

commit 1b43e87c59ddf02c4020149b898758a0f1c6125e
Author: reiern70 <[email protected]>
AuthorDate: Sun Feb 23 09:08:57 2020 +0200

    [NO_ISSUE] allow to abort currently executing request for an Ajax channel
---
 .../wicket/ajax/res/js/wicket-ajax-jquery.js       | 34 +++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

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 3ee9f3b..c786b91 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
@@ -278,6 +278,15 @@
                        }
                },
 
+               // aborts current request is there is any running
+               abort: function () {
+                       if (isUndef(this.jqXHR)) {
+                               Wicket.Log.debug("There is no executing request 
fro channel " + this.name)
+                       } else {
+                               this.jqXHR.abort();
+                       }
+               },
+
                done: function () {
                        var callback = null;
 
@@ -319,6 +328,26 @@
                        return c.schedule(callback);
                },
 
+               // register AJAX request
+               registerCurrentAjaxRequest: function(name, jqXHR) {
+                       var c = this.channels[name];
+                       if (isUndef(c)) {
+                               Wicket.Log.error("No channel with name " + name)
+                       } else {
+                               c.jqXHR = jqXHR;
+                       }
+               },
+
+               // aborts the current request for channel with name name
+               abortCurrentQuestForChannel(name) {
+                       var c = this.channels[name];
+                       if (isUndef(c)) {
+                               Wicket.Log.error("No channel with name " + name)
+                       } else {
+                               c.abort();
+                       }
+               },
+
                // Tells the ChannelManager that the current callback in 
channel with given name
                // has finished processing and another scheduled callback can 
be executed (if any).
                done: function (channel) {
@@ -549,7 +578,10 @@
                        this._initializeDefaults(attrs);
 
                        var res = Wicket.channelManager.schedule(attrs.ch, 
Wicket.bind(function () {
-                               this.doAjax(attrs);
+                               var jqXHR = this.doAjax(attrs);
+                               if (attrs.async) {
+                                       
Wicket.ChannelManager.registerCurrentAjaxRequest(attrs.c, jqXHR);
+                               }
                        }, this));
                        return res !== null ? res: true;
                },

Reply via email to