LP1282277 & LP1282286 Fixed error with Copy Editor user/ldw/LP1282277_LP1282286_MARC_edit_TCN_warning
authorLiam Whalen <liam.whalen@bc.libraries.coop>
Sat, 28 Jun 2014 20:52:45 +0000 (13:52 -0700)
committerLiam Whalen <liam.whalen@bc.libraries.coop>
Tue, 8 Jul 2014 00:41:21 +0000 (17:41 -0700)
With the previous fix applied, it is impossible to edit values within the copy
editor. A javascript error occurs.  This commit fixes that problem.

Signed-off-by: Liam Whalen <liam.whalen@bc.libraries.coop>
Open-ILS/xul/staff_client/chrome/content/OpenILS/global_util.js

index 655008f..5df5771 100644 (file)
@@ -6,16 +6,27 @@
 
     function oils_unsaved_data_V() {
         var tabs = window.parent.parent.document.getElementById('main_tabs');
-        var idx = tabs.selectedIndex;
-        var tab = tabs.childNodes[idx];
+
+        if (tabs) {
+            var idx = tabs.selectedIndex;
+            var tab = tabs.childNodes[idx];
+        }
+
         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 only a single time from marc edit
-        if (tab.marc_edit_allow_multiple_locks || tab.in_marc_edit == false) {
+        //If there are tabs, we allow unsaved data to be incremented only a single time from marc edit.
+        //If there are not tabs, then we are in a new window like the Copy Editor (so retain original locking).
+        if (tab) {
+            if (tab.marc_edit_allow_multiple_locks || tab.in_marc_edit == false) {
+                data.unsaved_data++;
+                window.oils_lock++;
+            }
+        } else {
             data.unsaved_data++;
             window.oils_lock++;
         }
+
         data.stash('unsaved_data');
         dump('\n=-=-=-=-=\n');
         dump('oils_unsaved_data_V for ' + location.href + '\n');
@@ -26,9 +37,6 @@
     }
 
     function oils_unsaved_data_P(count) {
-        var tabs = window.parent.parent.document.getElementById('main_tabs');
-        var idx = tabs.selectedIndex;
-        var tab = tabs.childNodes[idx];
         dump('\n=-=-=-=-=\n');
         dump('oils_unsaved_data_P for ' + location.href + '\n');
         if (!count) { count = 1; }
             }
         }
         var tabs = window.parent.parent.document.getElementById('main_tabs');
-        var idx = tabs.selectedIndex;
-        var tab = tabs.childNodes[idx];
+
+        if (tabs) {
+            var idx = tabs.selectedIndex;
+            var tab = tabs.childNodes[idx];
+        }
+
         if (typeof xulG != 'undefined') {
             if (typeof xulG.unlock_tab == 'function') {
                 dump('\twith xulG.lock_tab\n');
@@ -65,6 +77,8 @@
                 //make sure we are not in the marc edit window
                 var marceditRe = /\/marcedit.xul$/;
                 if (marceditRe.exec(window.document.location)) {
+                    //We do not have to check for tab here because
+                    //the MARC editor is explicitly in a tabbed window
                     tab.marc_edit_changed = true;
                     tab.marc_edit_allow_multiple_locks = false;
                 }
     function oils_unlock_page(params) {
         dump('\n=-=-=-=-=\n');
         dump('oils_unlock_page for ' + location.href + '\n');
-        var marceditRe = /\/marcedit.xul$/;
-        var tabs = window.parent.parent.document.getElementById('main_tabs');
-        var idx = tabs.selectedIndex;
-        var tab = tabs.childNodes[idx];
+
         if (typeof xulG != 'undefined') {
             if (typeof xulG.unlock_tab == 'function') {
                 dump('\twith xulG.unlock_tab\n');