Repository: wicket
Updated Branches:
  refs/heads/master 20cf8ee34 -> c107120f0


Revert "WICKET-6075 Error page redirection for Autocomplete field response"

This reverts commit 83a7284587f4ddb05ed05a842bec2119fa4eecaa.


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

Branch: refs/heads/master
Commit: c107120f0f3600db2b531f54438550c1404cb891
Parents: 20cf8ee
Author: Andrea Del Bene <[email protected]>
Authored: Wed Apr 20 00:34:57 2016 +0200
Committer: Andrea Del Bene <[email protected]>
Committed: Wed Apr 20 00:34:57 2016 +0200

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 127 ++++++++-----------
 wicket-core/src/test/js/ajax.js                 |  30 -----
 2 files changed, 55 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/c107120f/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 18be42e..55e6e61 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
@@ -704,7 +704,6 @@
                                        if (attrs.wr) {
                                                self.processAjaxResponse(data, 
textStatus, jqXHR, context);
                                        } else {
-                                               self.handleRedirection(jqXHR, 
context);
                                                self._executeHandlers(attrs.sh, 
attrs, jqXHR, data, textStatus);
                                                
we.publish(topic.AJAX_CALL_SUCCESS, attrs, jqXHR, data, textStatus);
                                        }
@@ -755,68 +754,6 @@
                },
 
                /**
-                * Method checks for 'Ajax-Location' header, if available, 
handles redirection to that URL.
-                * 
-                * @param jqXHR {Object} - the jQuery wrapper around 
XMLHttpRequest
-                * @param context {Object} - the request context with the Ajax 
request attributes and the FunctionExecuter's steps
-                * 
-                * @return boolean - returns 'true' if 'Ajax-Location' header 
is found redirection is handled, 'false' otherwise.
-                */
-               handleRedirection : function (jqXHR, context) {
-
-                       // first try to get the redirect header
-                       var redirectUrl;
-                       try {
-                               redirectUrl = 
jqXHR.getResponseHeader('Ajax-Location');
-                       } catch (ignore) { // might happen in older mozilla
-                       }
-
-                       // the redirect header was not set, just return
-                       if (typeof(redirectUrl) === "undefined" || redirectUrl 
=== null || redirectUrl === "") {
-                               return false;
-                       }
-
-                       // 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);
-
-                       var rhttp  = /^http:\/\//,  // checks whether the 
string starts with http://
-                           rhttps = /^https:\/\//; // checks whether the 
string starts with https://
-
-                       // support/check for non-relative redirectUrl like as 
provided and needed in a portlet context
-                       if (redirectUrl.charAt(0) === '/' || 
rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
-                               context.isRedirecting = true;
-                               Wicket.Ajax.redirect(redirectUrl);
-                       }
-                       else {
-                               var urlDepth = 0;
-                               while (redirectUrl.substring(0, 3) === "../") {
-                                       urlDepth++;
-                                       redirectUrl = redirectUrl.substring(3);
-                               }
-                               // Make this a string.
-                               var calculatedRedirect = 
window.location.pathname;
-                               while (urlDepth > -1) {
-                                       urlDepth--;
-                                       var i = 
calculatedRedirect.lastIndexOf("/");
-                                       if (i > -1) {
-                                               calculatedRedirect = 
calculatedRedirect.substring(0, i);
-                                       }
-                               }
-                               calculatedRedirect += "/" + redirectUrl;
-
-                               if (Wicket.Browser.isGecko()) {
-                                       // firefox 3 has problem with 
window.location setting relative url
-                                       calculatedRedirect = 
window.location.protocol + "//" + window.location.host + calculatedRedirect;
-                               }
-
-                               context.isRedirecting = true;
-                               Wicket.Ajax.redirect(calculatedRedirect);
-                       }
-                       return context.isRedirecting;
-               },
-
-               /**
                 * Method that processes the <ajax-response> in the context of 
an XMLHttpRequest.
                 *
                 * @param data {XmlDocument} - the <ajax-response> XML document
@@ -828,19 +765,65 @@
 
                        if (jqXHR.readyState === 4) {
 
-                               if (this.handleRedirection(jqXHR, context)) {
-                                       return; // 'Ajax-Location' header is 
set - redirected to it
+                               // first try to get the redirect header
+                               var redirectUrl;
+                               try {
+                                       redirectUrl = 
jqXHR.getResponseHeader('Ajax-Location');
+                               } catch (ignore) { // might happen in older 
mozilla
                                }
 
-                               // no redirect, just regular response
-                               if (Wicket.Log.enabled()) {
-                                       var responseAsText = jqXHR.responseText;
-                                       Wicket.Log.info("Received ajax response 
(" + responseAsText.length + " characters)");
-                                       Wicket.Log.info("\n" + responseAsText);
+                               // the redirect header was set, go to new url
+                               if (typeof(redirectUrl) !== "undefined" && 
redirectUrl !== null && redirectUrl !== "") {
+
+                                       // 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);
+
+                                       var rhttp  = /^http:\/\//,  // checks 
whether the string starts with http://
+                                           rhttps = /^https:\/\//; // checks 
whether the string starts with https://
+
+                                       // support/check for non-relative 
redirectUrl like as provided and needed in a portlet context
+                                       if (redirectUrl.charAt(0) === '/' || 
rhttp.test(redirectUrl) || rhttps.test(redirectUrl)) {
+                                               context.isRedirecting = true;
+                                               
Wicket.Ajax.redirect(redirectUrl);
+                                       }
+                                       else {
+                                               var urlDepth = 0;
+                                               while (redirectUrl.substring(0, 
3) === "../") {
+                                                       urlDepth++;
+                                                       redirectUrl = 
redirectUrl.substring(3);
+                                               }
+                                               // Make this a string.
+                                               var calculatedRedirect = 
window.location.pathname;
+                                               while (urlDepth > -1) {
+                                                       urlDepth--;
+                                                       var i = 
calculatedRedirect.lastIndexOf("/");
+                                                       if (i > -1) {
+                                                               
calculatedRedirect = calculatedRedirect.substring(0, i);
+                                                       }
+                                               }
+                                               calculatedRedirect += "/" + 
redirectUrl;
+
+                                               if (Wicket.Browser.isGecko()) {
+                                                       // firefox 3 has 
problem with window.location setting relative url
+                                                       calculatedRedirect = 
window.location.protocol + "//" + window.location.host + calculatedRedirect;
+                                               }
+
+                                               context.isRedirecting = true;
+                                               
Wicket.Ajax.redirect(calculatedRedirect);
+                                       }
                                }
+                               else {
+                                       // no redirect, just regular response
+                                       if (Wicket.Log.enabled()) {
+                                               var responseAsText = 
jqXHR.responseText;
+                                               Wicket.Log.info("Received ajax 
response (" + responseAsText.length + " characters)");
+                                               Wicket.Log.info("\n" + 
responseAsText);
+                                       }
 
-                               // invoke the loaded callback with an xml 
document
-                               return this.loadedCallback(data, context);
+                                       // invoke the loaded callback with an 
xml document
+                                       return this.loadedCallback(data, 
context);
+                               }
                        }
                },
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/c107120f/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index 21c37a8..bdd772f 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1359,36 +1359,6 @@ jQuery(document).ready(function() {
                        target.off("event1");
                });
 
-               asyncTest('Do not hide the indicator if redirecting.', function 
() {
-
-                       expect(2);
-
-                       var oldRedirect = Wicket.Ajax.redirect;
-                       Wicket.Ajax.redirect = function() {};
-
-                       var attrs = {
-                               u: 'data/ajax/redirectAjaxResponse.xml',
-                               e: 'event1',
-                               i: 'ajaxIndicator',
-                               wr: false,
-                               sh: [function(attrs, jqXHR, data, textStatus) {
-                                       var indicatorEl = Wicket.$(attrs.i);
-                                       equal("1", 
indicatorEl.getAttribute("showIncrementallyCount"));
-                               }],
-                               coh: [function(attrs, jqXHR, textStatus) {
-                                       var indicatorEl = Wicket.$(attrs.i);
-                                       equal("1", 
indicatorEl.getAttribute("showIncrementallyCount"));
-                                       Wicket.Ajax.redirect = oldRedirect;
-                                       start();
-                               }]
-                       };
-
-                       Wicket.Ajax.ajax(attrs);
-                       var target = jQuery(window);
-                       target.triggerHandler("event1");
-                       target.off("event1");
-               });
-
                asyncTest('Do hide the indicator if not redirecting.', function 
() {
 
                        expect(2);

Reply via email to