unsaved data loophole
authorJason Etheridge <jason@esilibrary.com>
Fri, 30 Mar 2012 19:32:53 +0000 (15:32 -0400)
committerJason Etheridge <jason@esilibrary.com>
Mon, 23 Apr 2012 17:50:35 +0000 (13:50 -0400)
The Start/Previous/Next/End/Search Results buttons in the staff client OPAC
wrapper do not fire unsaved data warnings for the MARC editor when changing
records. This plugs that hole, but it's not a complete solution, as you can
still move away from the record by clicking on hyperlinks in the OPAC View,
though that's less likely to happen.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Michael Peters <mrpeters@library.in.gov>
Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Open-ILS/xul/staff_client/chrome/content/main/menu.js
Open-ILS/xul/staff_client/chrome/content/util/browser.js
Open-ILS/xul/staff_client/chrome/locale/en-US/offline.properties

index 14c4cd3..7b98020 100644 (file)
@@ -439,44 +439,70 @@ function set_opac() {
                 $('record_back_to_results').disabled = true;
                 $('record_pos').setAttribute('value','');
 
+                function safe_to_proceed() {
+                    if (typeof xulG.is_tab_locked == 'undefined') { return true; }
+                    if (! xulG.is_tab_locked()) { return true; }
+                    var r = window.confirm(
+                        document.getElementById('offlineStrings').getString(
+                           'generic.unsaved_data_warning'
+                        )
+                    );
+                    if (r) {
+                        while ( xulG.unlock_tab() > 0 ) {};
+                        return true;
+                    } else {
+                        return false;
+                    }
+                }
+
                 win.attachEvt("rdetail", "nextPrevDrawn",
                     function(rIndex,rCount){
                         $('record_pos').setAttribute('value', document.getElementById('offlineStrings').getFormattedString('cat.record.counter', [(1+rIndex), rCount ? rCount : 1]));
                         if (win.rdetailNext) {
-                            g.f_record_next = function() { 
-                                g.view_override = g.view; 
-                                win.rdetailNext(); 
+                            g.f_record_next = function() {
+                                if (safe_to_proceed()) {
+                                    g.view_override = g.view;
+                                    win.rdetailNext();
+                                }
                             }
                             $('record_next').disabled = false;
                         }
                         if (win.rdetailPrev) {
-                            g.f_record_prev = function() { 
-                                g.view_override = g.view; 
-                                win.rdetailPrev(); 
+                            g.f_record_prev = function() {
+                                if (safe_to_proceed()) {
+                                    g.view_override = g.view;
+                                    win.rdetailPrev();
+                                }
                             }
                             $('record_prev').disabled = false;
                         }
                         if (win.rdetailStart) {
                             g.f_record_start = function() { 
-                                g.view_override = g.view; 
-                                win.rdetailStart(); 
+                                if (safe_to_proceed()) {
+                                    g.view_override = g.view;
+                                    win.rdetailStart();
+                                }
                             }
                             $('record_start').disabled = false;
                         }
                         if (win.rdetailEnd) {
                             g.f_record_end = function() { 
-                                g.view_override = g.view; 
-                                win.rdetailEnd(); 
+                                if (safe_to_proceed()) {
+                                    g.view_override = g.view;
+                                    win.rdetailEnd();
+                                }
                             }
                             $('record_end').disabled = false;
                         }
                         if (win.rdetailBackToResults) {
                             g.f_record_back_to_results = function() {
-                                g.view_override = g.view;
-                                win.rdetailBackToResults();
-                                if (g.view != "opac") {
-                                    set_opac();
-                                    opac_wrapper_set_help_context();
+                                if (safe_to_proceed()) {
+                                    g.view_override = g.view;
+                                    win.rdetailBackToResults();
+                                    if (g.view != "opac") {
+                                        set_opac();
+                                        opac_wrapper_set_help_context();
+                                    }
                                 }
                             }
                             $('record_back_to_results').disabled = false;
@@ -531,6 +557,7 @@ function set_opac() {
         content_params.lock_tab = xulG.lock_tab;
         content_params.unlock_tab = xulG.unlock_tab;
         content_params.inspect_tab = xulG.inspect_tab;
+        content_params.is_tab_locked = xulG.is_tab_locked;
         content_params.new_patron_tab = xulG.new_patron_tab;
         content_params.set_patron_tab = xulG.set_patron_tab;
         content_params.volume_item_creator = xulG.volume_item_creator;
@@ -709,6 +736,7 @@ function bib_in_new_tab() {
         content_params.lock_tab = xulG.lock_tab;
         content_params.unlock_tab = xulG.unlock_tab;
         content_params.inspect_tab = xulG.inspect_tab;
+        content_params.is_tab_locked = xulG.is_tab_locked;
         content_params.new_patron_tab = xulG.new_patron_tab;
         content_params.set_patron_tab = xulG.set_patron_tab;
         content_params.volume_item_creator = xulG.volume_item_creator;
index 113ea93..c004f05 100644 (file)
@@ -2240,6 +2240,14 @@ commands:
         var panel = this.controller.view.panels.childNodes[ idx ];
         while ( panel.lastChild ) panel.removeChild( panel.lastChild );
 
+        content_params.is_tab_locked = function() {
+            dump('is_tab_locked\n');
+            var id = tab.getAttribute('id');
+            if (typeof obj.tab_semaphores[id] == 'undefined') {
+                return false;
+            }
+            return obj.tab_semaphores[id] > 0;
+        }
         content_params.lock_tab = function() { 
             dump('lock_tab\n');
             var id = tab.getAttribute('id');
index 37f0466..88c0fe3 100644 (file)
@@ -293,6 +293,7 @@ util.browser.prototype = {
                 };
             }
             if (!cw.xulG.inspect_tab) { cw.xulG.inspect_tab = function() { return window.xulG.inspect_tab(); }; }
+            if (!cw.xulG.is_tab_locked) { cw.xulG.is_tab_locked = function() { return window.xulG.is_tab_locked(); }; }
             if (!cw.xulG.new_patron_tab) { cw.xulG.new_patron_tab = function(a,b) { return window.xulG.new_patron_tab(a,b); }; }
             if (!cw.xulG.set_patron_tab) { cw.xulG.set_patron_tab = function(a,b) { return window.xulG.set_patron_tab(a,b); }; }
             if (!cw.xulG.volume_item_creator) { cw.xulG.volume_item_creator = function(a) { return window.xulG.volume_item_creator(a); }; }
index 961ad06..23cd01a 100644 (file)
@@ -296,6 +296,7 @@ menu.tab7.accesskey=7
 menu.tab8.accesskey=8
 menu.tab9.accesskey=9
 menu.tab10.accesskey=0
+generic.unsaved_data_warning=This action may cause you to lose unsaved information in the current interface. Continue anyway?
 browser.reload.unsaved_data_warning=This page may have unsaved data. Reload it anyway?
 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?