From e88968d95178c3b40b00f597f5e66efa4193c062 Mon Sep 17 00:00:00 2001 From: phasefx Date: Tue, 7 Dec 2010 16:58:14 +0000 Subject: [PATCH] have lock_tab cause warning prompts for logoff attempts and application shutdown git-svn-id: svn://svn.open-ils.org/ILS/trunk@18927 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/auth/controller.js | 23 +++++++++++- .../xul/staff_client/chrome/content/main/main.js | 24 +++++++++++++ .../xul/staff_client/chrome/content/main/menu.js | 41 ++++++++++++++++++++-- .../chrome/locale/en-US/offline.properties | 2 ++ 4 files changed, 86 insertions(+), 4 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/auth/controller.js b/Open-ILS/xul/staff_client/chrome/content/auth/controller.js index 2e41ef57bd..990518588a 100644 --- a/Open-ILS/xul/staff_client/chrome/content/auth/controller.js +++ b/Open-ILS/xul/staff_client/chrome/content/auth/controller.js @@ -511,6 +511,16 @@ auth.controller.prototype = { }, 'logoff' : function() { + + this.data.stash_retrieve(); + if (typeof this.data.unsaved_data != 'undefined') { + if (this.data.unsaved_data > 0) { + var confirmation = window.confirm( document.getElementById('offlineStrings').getString('menu.logoff.unsaved_data_warning') ); + if (!confirmation) { return; } + this.data.unsaved_data = 0; + this.data.stash('unsaved_data'); + } + } this.error.sdump('D_AUTH','logoff' + this.w + '\n'); this.controller.view.progress_bar.value = 0; @@ -552,7 +562,18 @@ auth.controller.prototype = { this.error.sdump('D_AUTH','close' + this.w + '\n'); - if (window.confirm(document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'))) { + var confirm_string = document.getElementById('authStrings').getString('staff.auth.controller.confirm_close'); + + this.data.stash_retrieve(); + if (typeof this.data.unsaved_data != 'undefined') { + if (this.data.unsaved_data > 0) { + confirm_string = document.getElementById('offlineStrings').getString('menu.shutdown.unsaved_data_warning'); + } + } + + if (window.confirm(confirm_string)) { + this.data.unsaved_data = 0; + this.data.stash('unsaved_data'); this.logoff(); this.w.close(); /* Probably won't go any further */ diff --git a/Open-ILS/xul/staff_client/chrome/content/main/main.js b/Open-ILS/xul/staff_client/chrome/content/main/main.js index 7abcd42d21..290fd3372e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/main.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/main.js @@ -541,6 +541,30 @@ function main_init() { } } + window.addEventListener( + 'close', + function(ev) { + + G.data.stash_retrieve(); + if (typeof G.data.unsaved_data != 'undefined') { + if (G.data.unsaved_data > 0) { + var confirmation = window.confirm(offlineStrings.getString('menu.shutdown.unsaved_data_warning')); + if (!confirmation) { + ev.preventDefault(); + return false; + } + } + } + G.data.unsaved_data = 0; + G.data.stash('unsaved_data'); + + return true; + + }, + false + ); + + } catch(E) { var error = offlineStrings.getFormattedString('common.exception', [E, '']); try { G.error.sdump('D_ERROR',error); } catch(E) { dump(error); } diff --git a/Open-ILS/xul/staff_client/chrome/content/main/menu.js b/Open-ILS/xul/staff_client/chrome/content/main/menu.js index 233e07544e..2318c22acc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/main/menu.js +++ b/Open-ILS/xul/staff_client/chrome/content/main/menu.js @@ -138,6 +138,12 @@ main.menu.prototype = { } } + for (var id in obj.tab_semaphores) { + if (obj.tab_semaphores[id] > 0) { + obj.global_unsaved_data_P(); + } + } + return true; }, @@ -1305,7 +1311,16 @@ main.menu.prototype = { 'cmd_shutdown' : [ ['oncommand'], function() { - if (window.confirm(offlineStrings.getString('menu.cmd_shutdown.prompt'))) { + var confirm_string = offlineStrings.getString('menu.cmd_shutdown.prompt'); + obj.data.stash_retrieve(); + if (typeof obj.data.unsaved_data != 'undefined') { + if (obj.data.unsaved_data > 0) { + confirm_string = offlineStrings.getString('menu.shutdown.unsaved_data_warning'); + } + } + if (window.confirm(confirm_string)) { + obj.data.unsaved_data = 0; // just in case the program doesn't close somehow + obj.data.stash('unsaved_data'); netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(); var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator); @@ -1371,8 +1386,9 @@ main.menu.prototype = { if (this.tab_semaphores[id] > 0) { var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning')); if (!confirmation) { return; } - delete this.tab_semaphores[id]; + obj.global_unsaved_data_P(); } + delete this.tab_semaphores[id]; } this.controller.view.tabs.removeItemAt(idx); @@ -1630,6 +1646,22 @@ main.menu.prototype = { 'tab_semaphores' : {}, + 'global_unsaved_data_V' : function() { + var obj = this; + obj.data.stash_retrieve(); + if (typeof obj.data.unsaved_data == 'undefined') { obj.data.unsaved_data = 0; } + obj.data.unsaved_data++; + obj.data.stash('unsaved_data'); + }, + 'global_unsaved_data_P' : function() { + var obj = this; + obj.data.stash_retrieve(); + if (typeof obj.data.unsaved_data == 'undefined') { obj.data.unsaved_data = 0; } + obj.data.unsaved_data++; + if (obj.data.unsaved_data < 0) { obj.data.unsaved_data = 0; } + obj.data.stash('unsaved_data'); + }, + 'set_tab' : function(url,params,content_params) { var obj = this; if (!url) url = '/xul/server/'; @@ -1646,8 +1678,9 @@ main.menu.prototype = { if (obj.tab_semaphores[id] > 0) { var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning')); if (!confirmation) { return; } - delete obj.tab_semaphores[id]; + obj.global_unsaved_data_P(); } + delete obj.tab_semaphores[id]; } } var unique_id = idx + ':' + new Date(); @@ -1662,6 +1695,7 @@ main.menu.prototype = { obj.tab_semaphores[id] = 0; } obj.tab_semaphores[id]++; + obj.global_unsaved_data_V(); return obj.tab_semaphores[id]; }; content_params.unlock_tab = function() { @@ -1671,6 +1705,7 @@ main.menu.prototype = { } obj.tab_semaphores[id]--; if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } + obj.global_unsaved_data_P(); return obj.tab_semaphores[id]; }; content_params.inspect_tab = function() { diff --git a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties index cee3330f56..2ccd17d495 100644 --- a/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties +++ b/Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties @@ -283,3 +283,5 @@ menu.tab10.accesskey=0 menu.close_tab.unsaved_data_warning=This tab may have unsaved data. Close it anyway? menu.replace_tab.unsaved_data_warning=This tab may have unsaved data. Replace it anyway? menu.close_window.unsaved_data_warning=This window may have unsaved data. Close it anyway? +menu.logoff.unsaved_data_warning=This session may have unsaved data. Logoff anyway? +menu.shutdown.unsaved_data_warning=This application may have unsaved data. Exit it anyway? -- 2.11.0