have lock_tab cause warning prompts for logoff attempts and application shutdown
authorphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 16:58:14 +0000 (16:58 +0000)
committerphasefx <phasefx@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 7 Dec 2010 16:58:14 +0000 (16:58 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18927 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/chrome/content/auth/controller.js
Open-ILS/xul/staff_client/chrome/content/main/main.js
Open-ILS/xul/staff_client/chrome/content/main/menu.js
Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties

index 2e41ef5..9905185 100644 (file)
@@ -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 */
 
index 7abcd42..290fd33 100644 (file)
@@ -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); }
index 233e075..2318c22 100644 (file)
@@ -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() {
index cee3330..2ccd17d 100644 (file)
@@ -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?