You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2015/05/30 14:53:13 UTC

[1/2] wicket git commit: WICKET-5901 Leaving veil when ajax processing ends with redirect

Repository: wicket
Updated Branches:
  refs/heads/wicket-6.x eff2b2509 -> 22e6f69b3


WICKET-5901 Leaving veil when ajax processing ends with redirect

Do not hide the Ajax indicator if there is a redirect to another page


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

Branch: refs/heads/wicket-6.x
Commit: ad89910da115454f0f54cc33f9a14a6fc4a41e52
Parents: eff2b25
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri May 22 23:53:31 2015 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri May 22 23:53:31 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js  | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/ad89910d/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 a68d510..13163d5 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
@@ -695,7 +695,7 @@
 				complete: function (jqXHR, textStatus) {
 
 					context.steps.push(jQuery.proxy(function (notify) {
-						if (attrs.i) {
+						if (attrs.i && context.isRedirecting !== true) {
 							Wicket.DOM.hideIncrementally(attrs.i);
 						}
 
@@ -766,6 +766,7 @@
 
 					// 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;
 						window.location = redirectUrl;
 					}
 					else {
@@ -790,6 +791,7 @@
 							calculatedRedirect = window.location.protocol + "//" + window.location.host + calculatedRedirect;
 						}
 
+						context.isRedirecting = true;
 						window.location = calculatedRedirect;
 					}
 				}
@@ -920,7 +922,7 @@
 				}, 0);
 
 				var attrs = context.attrs;
-				if (attrs.i) {
+				if (attrs.i && context.isRedirecting !== true) {
 					// hide the indicator
 					Wicket.DOM.hideIncrementally(attrs.i);
 				}
@@ -1242,6 +1244,7 @@
 		processRedirect: function (context, node) {
 			var text = Wicket.DOM.text(node);
 			Wicket.Log.info("Redirecting to: " + text);
+			context.isRedirecting = true;
 			window.location = text;
 		},
 


[2/2] wicket git commit: WICKET-5901 Leaving veil when ajax processing ends with redirect

Posted by mg...@apache.org.
WICKET-5901 Leaving veil when ajax processing ends with redirect

Add unit tests for preserving the ajax indicator until page unload (if there is redirect)


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

Branch: refs/heads/wicket-6.x
Commit: 22e6f69b3896c011f113f6d97957e6cd46304223
Parents: ad89910
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Sat May 30 15:51:03 2015 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Sat May 30 15:51:03 2015 +0300

----------------------------------------------------------------------
 .../wicket/ajax/res/js/wicket-ajax-jquery.js    | 15 ++++--
 wicket-core/src/test/js/ajax.js                 | 54 ++++++++++++++++++++
 wicket-core/src/test/js/all.html                |  2 +
 .../test/js/data/ajax/redirectAjaxResponse.xml  | 18 +++++++
 4 files changed, 86 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/22e6f69b/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 13163d5..794c2ef 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
@@ -767,7 +767,7 @@
 					// 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;
-						window.location = redirectUrl;
+						Wicket.Ajax.redirect(redirectUrl);
 					}
 					else {
 						var urlDepth = 0;
@@ -792,7 +792,7 @@
 						}
 
 						context.isRedirecting = true;
-						window.location = calculatedRedirect;
+						Wicket.Ajax.redirect(calculatedRedirect);
 					}
 				}
 				else {
@@ -1245,7 +1245,7 @@
 			var text = Wicket.DOM.text(node);
 			Wicket.Log.info("Redirecting to: " + text);
 			context.isRedirecting = true;
-			window.location = text;
+			Wicket.Ajax.redirect(text);
 		},
 
 		// mark the focused component so that we know if it has been replaced by response
@@ -1976,6 +1976,15 @@
 			process: function(data) {
 				var call = new Wicket.Ajax.Call();
 				call.process(data);
+			},
+
+			/**
+			 * An abstraction over native window.location.replace() to be able to suppress it for unit tests
+			 *
+			 * @param url The url to redirect to
+			 */
+			redirect: function(url) {
+				window.location = url;
 			}
 		},
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/22e6f69b/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 26d46b4..ff0b952 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1289,5 +1289,59 @@ 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',
+				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);
+
+			var attrs = {
+				u: 'data/ajax/emptyAjaxResponse.xml',
+				e: 'event1',
+				i: 'ajaxIndicator',
+				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("0", indicatorEl.getAttribute("showIncrementallyCount"));
+					start();
+				}]
+			};
+
+			Wicket.Ajax.ajax(attrs);
+			var target = jQuery(window);
+			target.triggerHandler("event1");
+			target.off("event1");
+		});
+
 	}
 });

http://git-wip-us.apache.org/repos/asf/wicket/blob/22e6f69b/wicket-core/src/test/js/all.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/all.html b/wicket-core/src/test/js/all.html
index b58688f..6a03f52 100644
--- a/wicket-core/src/test/js/all.html
+++ b/wicket-core/src/test/js/all.html
@@ -169,6 +169,8 @@
 		<div id="usedAsContextWicket5025"></div>
 
 		<input type="text" id="inputChangeInput">
+
+		<div id="ajaxIndicator"></div>
 	</div>
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/22e6f69b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
new file mode 100644
index 0000000..19d89e7
--- /dev/null
+++ b/wicket-core/src/test/js/data/ajax/redirectAjaxResponse.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+        http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+<ajax-response><redirect><![CDATA[http://127.0.0.1]]></redirect></ajax-response>