Permalink
Browse files

Changed unbeforeunload event (unsaved text) from utility.js to be att…

…ached rather than set.

Added unbeforeunload event (unsaved orders) in form.js which is also attached.
  • Loading branch information...
1 parent 57410df commit 8380941c66498b3c38db178ff0673118740a29e4 @deltachemist deltachemist committed Apr 16, 2016
Showing with 39 additions and 1 deletion.
  1. +28 −0 javascript/orders/form.js
  2. +11 −1 javascript/utility.js
@@ -177,11 +177,13 @@ function OrdersHTMLFormClass() {
if( MyOrders.pluck('isChanged').any(function(c){return c;}) )
{
this.ordersChanged=true;
+ window.ordersChanged = true;
this.buttonOn('UpdateButton');
}
else
{
this.ordersChanged=false;
+ window.ordersChanged=false;
this.buttonOff('UpdateButton');
}
@@ -195,3 +197,29 @@ function OrdersHTMLFormClass() {
function loadOrdersForm() {
OrdersHTML = new OrdersHTMLFormClass();
}
+
+if(window.addEventListener){
+ window.addEventListener('beforeunload',onbeforeunload_unsavedorders,false);
+ console.log("Added onbeforeunload_unsavedorders listener via addEventListener");
+}else{
+ window.attachEvent('onbeforeunload',onbeforeunload_unsavedorders);
+ console.log("Added onbeforeunload_unsavedorders listener via attachEvent");
+}
+
+window.ordersChanged = false;
+
+// When the window is about to change make sure there are no unsubmitted messages around
+function onbeforeunload_unsavedorders(e) {
+
+ // Don't give a warning dialog if no orders were changed
+ if( !window.ordersChanged ) return;
+
+ var str=l_t("You seem to have unsubmitted orders.");
+ var e = e || window.event;
+
+ // For IE and Firefox
+ if (e) e.returnValue = str;
+
+ //For Safari
+ return str;
+};
View
@@ -60,12 +60,22 @@ var inErrorCode=0;
};
*/
+// Attach the method to the unbeforeunload event
+if(window.addEventListener){
+ window.addEventListener('beforeunload',onbeforeunload_unsubmittedtext,false);
+ console.log("Added onbeforeunload_unsubmittedtext listener via addEventListener");
+}else{
+ window.attachEvent('onbeforeunload',onbeforeunload_unsubmittedtext);
+ console.log("Added onbeforeunload_unsubmittedtext listener via attachEvent");
+}
+
// If false it's okay to leave the page. makeFormsSafe sets this to true, and runs code which makes only
// certain forms safe.
window.leavepagedanger=false;
// When the window is about to change make sure there are no unsubmitted messages around
-window.onbeforeunload = function (e) {
+function onbeforeunload_unsubmittedtext(e) {
+
// Don't give a warning dialog if we are submitting the text
if( !window.leavepagedanger ) return;

0 comments on commit 8380941

Please sign in to comment.