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 2012/03/07 14:04:57 UTC

git commit: WICKET-2249 Modal Window: add overridable wantUnloadConfirmation() method

Updated Branches:
  refs/heads/master c58fbc1bc -> 5a6cec68f


WICKET-2249 Modal Window: add overridable wantUnloadConfirmation() method


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

Branch: refs/heads/master
Commit: 5a6cec68f3a84b5cdef530e6d69811dd0c77e65e
Parents: c58fbc1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Wed Mar 7 15:04:23 2012 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Mar 7 15:04:23 2012 +0200

----------------------------------------------------------------------
 .../ajax/markup/html/modal/ModalWindow.java        |   26 +++++++++++++++
 .../extensions/ajax/markup/html/modal/res/modal.js |    9 +++--
 2 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/5a6cec68/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
index 9e9f692..fc76865 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/ModalWindow.java
@@ -153,6 +153,7 @@ public class ModalWindow extends Panel
 	private IModel<String> title = null;
 	private MaskType maskType = MaskType.SEMI_TRANSPARENT;
 	private boolean autoSize = false;
+	private boolean unloadConfirmation = true;
 
 	private PageCreator pageCreator = null;
 	private CloseButtonCallback closeButtonCallback = null;
@@ -627,6 +628,30 @@ public class ModalWindow extends Panel
 	}
 
 	/**
+	 * Sets a flag whether to ask the user before leaving the page.
+	 *
+	 * @param unloadConfirmation
+	 *            a flag whether to ask the user before leaving the page
+	 * @return {@code this} instance, for chaining
+	 */
+	public ModalWindow showUnloadConfirmation(final boolean unloadConfirmation)
+	{
+		this.unloadConfirmation = unloadConfirmation;
+		return this;
+	}
+
+	/**
+	 * Returns whether the user should be asked before leaving the page.
+	 *
+	 * @return {@code true} if the user should be asked if the last action
+	 *  causes leaving the page, {@code false} otherwise
+	 */
+	public boolean showUnloadConfirmation()
+	{
+		return unloadConfirmation;
+	}
+
+	/**
 	 * Sets the CSS unit used for initial window width. This is only applicable when the window is
 	 * not resizable.
 	 * 
@@ -1099,6 +1124,7 @@ public class ModalWindow extends Panel
 
 		appendAssignment(buffer, "settings.autoSize", autoSize);
 
+		appendAssignment(buffer, "settings.unloadConfirmation", showUnloadConfirmation());
 
 		// set true if we set a windowclosedcallback
 		boolean haveCloseCallback = false;

http://git-wip-us.apache.org/repos/asf/wicket/blob/5a6cec68/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
----------------------------------------------------------------------
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
index 1aa8208..11bade1 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/modal/res/modal.js
@@ -194,6 +194,7 @@ Wicket.Window = Wicket.Class.create();
 
 /**
  * Display confirmation dialog if the user is about to leave a page (IE and FF).
+ * @deprecated Use the settings instead. TODO Removed for/after Wicket 7.0
  */
 Wicket.Window.unloadConfirmation = true;
 
@@ -214,7 +215,7 @@ Wicket.Window.create = function(settings) {
 		} catch (ignore) {		
 		}
 	}
-	
+
 	// no parent...
 	if (typeof(win) == "undefined") {
 		win = Wicket.Window;
@@ -734,8 +735,10 @@ Wicket.Window.prototype = {
 		
 		// preserve old beforeunload handler
 		this.old_onbeforeunload = window.onbeforeunload;
-		
-		if (Wicket.Window.unloadConfirmation == true) {
+
+		// Wicket.Window.unloadConfirmation is deprecated but we need to check it
+		// for backward compatibility. Remove it after Wicket 7.0
+		if (this.settings.unloadConfirmation && Wicket.Window.unloadConfirmation) {
 			// new beforeunload handler - ask user before reloading window
 			window.onbeforeunload = function() {
 				return "Reloading this page will cause the modal window to disappear.";