LP1282277 & LP1282286 MARC edit TCN search lose data prompts user/ldw/LP1282277_LP1282286_for_testing
authorLiam Whalen <whalen.ld@gmail.com>
Thu, 13 Mar 2014 17:37:25 +0000 (10:37 -0700)
committerLiam Whalen <whalen.ld@gmail.com>
Thu, 13 Mar 2014 17:37:25 +0000 (10:37 -0700)
This commit modifies my previous commits.  The code now uses the
previous versions code to mark a tab as locked and to record that data
is saved or not saved.  However, when a user returns to the MARC edit
screen, if there are changes still present, then the code now locks the
tab again and records that there is unsaved data.  This should allow all
previous functionality to remain while providing the proper warnings
when within the MARC editor.

Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js
Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Open-ILS/xul/staff_client/chrome/content/main/menu.js

index 79152f7..96688d0 100644 (file)
@@ -11,7 +11,7 @@
         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
         data.stash_retrieve();
         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
-        //we allow unsaved data to be incremented a single time from marc edit
+        //We allow unsaved data to be incremented only a single time from marc edit
         if (tab.marc_edit_allow_multiple_locks || tab.in_marc_edit == false) {
             data.unsaved_data++;
             window.oils_lock++;
         //because we might come back and edit it later, and the window.oils_lock
         //prevents us from closing the window and losing data.  If the marc
         //data is not changed and we have a window lock, then we can decerment it
-        if (tab.in_marc_edit == false || tab.marc_edit_changed == false) {
-            window.oils_lock -= count;
-            if (window.oils_lock < 0) { window.oils_lock = 0; }
-        }
+        window.oils_lock -= count;
+        if (window.oils_lock < 0) { window.oils_lock = 0; }
         JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.stash_retrieve();
         data.stash_retrieve();
         if (typeof data.unsaved_data == 'undefined') { data.unsaved_data = 0; }
         dump('decrementing data.unsaved_data by ' + count + '\n');
-        if (tab.in_marc_edit == false || tab.marc_edit_changed == false) {
-            data.unsaved_data -= count;
-        }
+        data.unsaved_data -= count;
         if (data.unsaved_data < 0) { data.unsaved_data = 0; }
         data.stash('unsaved_data');
         dump('\twindow.oils_lock == ' + window.oils_lock + '\n');
index 70154d5..a765a69 100644 (file)
@@ -1178,6 +1178,17 @@ function gen_statusbar_click_handler(data_key) {
 function record_action(action_function) {
     if (safe_to_proceed()) {
         var args = Array.prototype.slice.call(arguments, 1);
+        if (action_function.name == 'set_marc_edit') {
+            var tabs = window.parent.document.getElementById('main_tabs');
+            var idx = tabs.selectedIndex;
+            var tab = tabs.childNodes[idx];
+
+            if (tab.marc_edit_changed) {
+                xulG.lock_tab();
+                tab.marc_edit_allow_multiple_locks = false;
+            }
+        }
+            
         return action_function.apply(null, args);
     }
 }
index b8836fc..711fe84 100644 (file)
@@ -423,6 +423,8 @@ main.menu.prototype = {
 
                         if (typeof obj.tab_semaphores[id] != 'undefined') {
                             if (obj.tab_semaphores[id] > 0) {
+                                //If confirmation has not been defined yet
+                                //make sure we prompt for possible loss of data
                                 if (typeof confirmation == undefined) {
                                     confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning'));
                                 }
@@ -2469,14 +2471,18 @@ commands:
                 obj.tab_semaphores[id] = 0;
             }
 
-                       //If we are in marc edit, then unlock is only calld when saving
-                       //the edits.  So, drop all locks in this case.
-                       //Otherwise leave the code as is because I am not sure how other parts
-                       if (tab.in_marc_edit) {
-                               obj.tab_semaphores[id] = 0;
-                       } else {
-                               obj.tab_semaphores[id]--;
-                       }
+            //If we are in marc edit, then unlock is only calld when saving
+            //the edits.  So, drop all locks in this case.
+            //Otherwise leave the code as is because I am not sure how other parts
+            //of the staff client interact with the tab locking
+            if (tab.in_marc_edit) {
+                obj.tab_semaphores[id] = 0;
+                //allow multiple locks again, so if we
+                //return to marc edit we can put a lock on it again
+                tab.marc_edit_allow_multiple_locks = true;
+            } else {
+                obj.tab_semaphores[id]--;
+            }
             if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } 
             oils_unsaved_data_P();
             return obj.tab_semaphores[id];