LP1282277_LP1282286_Unitialized_Vars_FIx user/ldw/Unintialized_Vars_Fix
authorLiam Whalen <liam.whalen@bc.libraries.coop>
Sun, 13 Jul 2014 17:49:07 +0000 (10:49 -0700)
committerLiam Whalen <liam.whalen@bc.libraries.coop>
Sun, 13 Jul 2014 17:51:07 +0000 (10:51 -0700)
The commit to prompt users if they are going to lose data in MARC edit
added some new variables (tabs, and tab) in various files.  If the MARC
edit window does not appear in a tab, then these variables remain
unitialzed and cause problems for MARC edits that appear in their own
window.  By checking for the existence of the variables before MARC
edito loads in its own windown, the problems are resolved.

Signed-off-by: Liam Whalen <liam.whalen@bc.libraries.coop>
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/server/cat/marcedit.js

index 5df5771..10432ae 100644 (file)
                 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;
+                    if (tab) {
+                        tab.marc_edit_changed = true;
+                        tab.marc_edit_allow_multiple_locks = false;
+                    }
                 }
                 window.oils_lock++; // different window scope than the chrome of xulG.lock_tab
             } else {
index a765a69..673eede 100644 (file)
@@ -61,9 +61,11 @@ function default_focus() {
 function opac_wrapper_set_help_context() {
     try {
         var tabs = window.parent.document.getElementById('main_tabs');
-        var idx = tabs.selectedIndex;
-        var tab = tabs.childNodes[idx];
-        tab.in_marc_edit = false;
+        if (tabs) {
+            var idx = tabs.selectedIndex;
+            var tab = tabs.childNodes[idx];
+            tab.in_marc_edit = false;
+        }
         dump('Entering opac.js, opac_wrapper_set_help_context\n');
         var cw = bottom_pane.get_contentWindow();
         if (cw && typeof cw['location'] != 'undefined') {
@@ -84,7 +86,9 @@ function opac_wrapper_set_help_context() {
             }
             var marceditRe = /\/marcedit.xul$/;
             if (marceditRe.exec(cw.location)) {
-                tab.in_marc_edit = true;
+                if (tab) {
+                    tab.in_marc_edit = true;
+                }
             }
         } else {
             dump('opac.js: problem in opac_wrapper_set_help_context(): bottom_pane = ' + bottom_pane + ' cw = ' + cw + '\n');
@@ -1180,12 +1184,14 @@ function record_action(action_function) {
         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 (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;
+                if (tab.marc_edit_changed) {
+                    xulG.lock_tab();
+                    tab.marc_edit_allow_multiple_locks = false;
+                }
             }
         }
             
@@ -1203,32 +1209,35 @@ function safe_to_proceed() {
     var marc_edit_changed;
 
     var tabs = window.parent.document.getElementById('main_tabs');
-    var idx = tabs.selectedIndex;
-    var tab = tabs.childNodes[idx];
 
-    in_marc_edit = tab.in_marc_edit;
-    marc_edit_changed = tab.marc_edit_changed;
+    if (tabs) {
+        var idx = tabs.selectedIndex;
+        var tab = tabs.childNodes[idx];
 
-    if ((in_marc_edit != true) || (marc_edit_changed != true)) {
-        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'
-        )
-    );
+        in_marc_edit = tab.in_marc_edit;
+        marc_edit_changed = tab.marc_edit_changed;
 
-    //If we are confirming from within MARC edit then
-    //drop the tab locks.  Otherwise the locks get dropped
-    //in cmd_search_tcn
-    if (r) {
-        if (typeof xulG.unlock_tab === 'function') {
-            while ( xulG.unlock_tab() > 0 ) {};
+        if ((in_marc_edit != true) || (marc_edit_changed != true)) {
+            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'
+            )
+        );
 
-        return true;
-    } else {
-        return false;
+        //If we are confirming from within MARC edit then
+        //drop the tab locks.  Otherwise the locks get dropped
+        //in cmd_search_tcn
+        if (r) {
+            if (typeof xulG.unlock_tab === 'function') {
+                while ( xulG.unlock_tab() > 0 ) {};
+            }
+
+            return true;
+        } else {
+            return false;
+        }
     }
 }
index 691eeaa..922fe6f 100644 (file)
@@ -567,8 +567,11 @@ function setFocusToNextTag (row, direction) {
 function set_lock_on_keypress(ev) {
     try {
         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];
+        }
         //dump('keypress: isChar = ' + ev.isChar + ' char = ' + ev.char + ' charCode = ' + ev.charCode + ' key = ' + ev.key + ' keyCode = ' + ev.keyCode + '\n');
         if (! /* NOT */(
                 ev.altKey
@@ -1217,15 +1220,20 @@ function fastItemAdd_attempt(doc_id) {
 function save_attempt(xml_string) {
     try {
         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];
+        }
         var result = window.xulG.save.func( xml_string );
         // I'd prefer to pass on_complete on through to fast_item_add,
         // but with the way these window scopes get destroyed with
         // tab replacement, maybe not a good idea
         var replace_on_complete = false;
         if (result) {
-            tab.marc_edit_changed = false;
+            if (tab) {
+                tab.marc_edit_changed = false;
+            }
             oils_unlock_page();
             if (result.id) {
                 replace_on_complete = fastItemAdd_attempt(result.id);
@@ -1350,10 +1358,13 @@ function marcSubfield (sf) {
 function loadRecord() {
     try {
             var tabs = window.parent.parent.document.getElementById('main_tabs');
-            var idx = tabs.selectedIndex;
-            var tab = tabs.childNodes[idx];
-            tab.marc_edit_changed = false;
-            tab.marc_edit_allow_multiple_locks = true;
+
+            if (tabs) {
+                var idx = tabs.selectedIndex;
+                var tab = tabs.childNodes[idx];
+                tab.marc_edit_changed = false;
+                tab.marc_edit_allow_multiple_locks = true;
+            }
 
             var grid_rows = document.getElementById('recGrid').lastChild;