Reload the OPAC via Holdings Maintenance
authorJason Etheridge <jason@esilibrary.com>
Thu, 8 Mar 2012 19:51:32 +0000 (14:51 -0500)
committerMike Rylander <mrylander@gmail.com>
Fri, 23 Mar 2012 20:30:29 +0000 (16:30 -0400)
Makes reloading a page wrapped in util.browser more accessible to foreign
window contexts.  Gives all the interfaces hanging off the chrome OPAC wrapper
the ability to reload the OPAC frame via xulG.reload_opac().  Have Holdings
Maintenance do this whenever its list is refreshed.  And "Add Volumes", whether
invoked from Actions for this Record, or from the click link in the record
summary pane.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/xul/staff_client/chrome/content/cat/opac.js
Open-ILS/xul/staff_client/chrome/content/util/browser.js
Open-ILS/xul/staff_client/server/cat/bib_brief.js
Open-ILS/xul/staff_client/server/cat/copy_browser.js
Open-ILS/xul/staff_client/server/cat/volume_copy_creator.js

index 52c84ef..d1e0d02 100644 (file)
@@ -1,4 +1,4 @@
-var docid; var marc_html; var top_pane; var bottom_pane; var opac_frame; var opac_url;
+var docid; var marc_html; var top_pane; var bottom_pane; var opac_browser; var opac_url;
 
 var marc_view_reset = true;
 var marc_edit_reset = true;
@@ -106,7 +106,7 @@ function set_brief_view() {
         "set_patron_tab", "volume_item_creator", "get_new_session",
         "holdings_maintenance_tab", "open_chrome_window", "url_prefix",
         "network_meter", "page_meter", "set_statusbar", "set_help_context",
-        "get_barcode"
+        "get_barcode", "reload_opac"
     ].forEach(function(k) { content_params[k] = xulG[k]; });
 
     top_pane.set_iframe( 
@@ -240,7 +240,9 @@ function set_marc_edit() {
                                 );
 
                             } else {
-                                return cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+                                var x = cat.util.spawn_copy_editor( { 'handle_update' : 1, 'edit' : 1, 'docid' : doc_id, 'copies' : [ copy_obj ] });
+                                xulG.reload_opac();
+                                return x;
                             }
 
                         } catch(E) {
@@ -260,6 +262,7 @@ function set_marc_edit() {
                         marc_view_reset = true;
                         copy_browser_reset = true;
                         hold_browser_reset = true;
+                        xulG.reload_opac();
                         if (typeof r.ilsevent != 'undefined') {
                             throw(r);
                         } else {
@@ -325,7 +328,7 @@ function open_acq_orders() {
             "set_patron_tab", "volume_item_creator", "get_new_session",
             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
             "url_prefix", "network_meter", "page_meter", "set_statusbar",
-            "set_help_context", "get_barcode"
+            "set_help_context", "get_barcode", "reload_opac"
         ].forEach(function(k) { content_params[k] = xulG[k]; });
 
         var loc = urls.XUL_BROWSER + "?url=" + window.escape(
@@ -359,7 +362,7 @@ function open_alt_serial_mgmt() {
             "set_patron_tab", "volume_item_creator", "get_new_session",
             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
             "url_prefix", "network_meter", "page_meter", "set_statusbar",
-            "set_help_context", "get_barcode"
+            "set_help_context", "get_barcode", "reload_opac"
         ].forEach(function(k) { content_params[k] = xulG[k]; });
 
         var loc = urls.XUL_BROWSER + "?url=" + window.escape(
@@ -556,8 +559,18 @@ function set_opac() {
     } catch(E) {
         g.error.sdump('D_ERROR','set_opac: ' + E);
     }
-    opac_wrapper_set_help_context(); 
-    bottom_pane.get_contentWindow().addEventListener('load',opac_wrapper_set_help_context,false);
+    opac_wrapper_set_help_context();
+    opac_browser = bottom_pane.get_contentWindow();
+    opac_browser.addEventListener('load',opac_wrapper_set_help_context,false);
+}
+
+xulG.reload_opac = function() {
+    try {
+        JSAN.use('util.widgets');
+        opac_browser.g.browser.reload();
+    } catch(E) {
+        g.error.sdump("D_ERROR", 'error reloading opac: ' + E + '\n');
+    }
 }
 
 function set_serctrl_view() {
@@ -616,7 +629,7 @@ function create_mfhd() {
             throw(r);
         }
         alert("MFHD record created."); //TODO: better success message
-        browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
+        xulG.reload_opac(); // browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
     } catch(E) {
         g.error.standard_unexpected_error_alert("Create MFHD failed", E); //TODO: better error handling
     }
@@ -638,7 +651,7 @@ function delete_mfhd(sre_id) {
             alert(document.getElementById('offlineStrings').getFormattedString('cat.opac.record_deleted.error',  [docid, robj.textcode, robj.desc]) + '\n');
         } else {
             alert(document.getElementById('offlineStrings').getString('cat.opac.record_deleted'));
-            browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
+            xulG.reload_opac(); // browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand();
         }
     }
 }
@@ -672,6 +685,7 @@ function open_marc_editor(rec, label) {
                     'open-ils.permacrud', method,
                     [ses(), rec]
                 );
+                xulG.reload_opac();
             }
         }
     };
@@ -716,7 +730,7 @@ function batch_receive_in_new_tab() {
             "set_patron_tab", "volume_item_creator", "get_new_session",
             "holdings_maintenance_tab", "set_tab_name", "open_chrome_window",
             "url_prefix", "network_meter", "page_meter", "set_statusbar",
-            "set_help_context", "get_barcode"
+            "set_help_context", "get_barcode", "reload_opac"
         ].forEach(function(k) { content_params[k] = xulG[k]; });
 
         xulG.new_tab(
@@ -986,7 +1000,7 @@ function add_volumes() {
         var w = xulG.new_tab(
             url,
             { 'tab_name' : title },
-            { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
+            { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ], 'reload_opac' : xulG.reload_opac }
         );
     } catch(E) {
         alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E);
index f0b4cd9..37f0466 100644 (file)
@@ -132,17 +132,7 @@ util.browser.prototype = {
                             ['command'],
                             function() {
                                 try {
-                                    if (obj.lock_reload) {
-                                        if (window.confirm( $('offlineStrings').getString('browser.reload.unsaved_data_warning') )) {
-                                            obj.lock_reload = false;
-                                            window.xulG.unlock_tab();
-                                        } else {
-                                            return;
-                                        }
-                                    }
-                                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-                                    var n = obj.getWebNavigation();
-                                    n.reload( Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE );
+                                    obj.reload();
                                 } catch(E) {
                                     var err = 'cmd_reload: ' + E;
                                     obj.error.sdump('D_ERROR',err);
@@ -182,6 +172,21 @@ util.browser.prototype = {
         }
     },
 
+    'reload' : function() {
+        var obj = this;
+        if (obj.lock_reload) {
+            if (window.confirm( $('offlineStrings').getString('browser.reload.unsaved_data_warning') )) {
+                obj.lock_reload = false;
+                window.xulG.unlock_tab();
+            } else {
+                return;
+            }
+        }
+        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+        var n = obj.getWebNavigation();
+        n.reload( Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE );
+    },
+
     'find' : function(text) {
         var obj = this;
         try {
index face076..3f36c65 100644 (file)
@@ -196,7 +196,7 @@ function add_volumes() {
         var w = xulG.new_tab(
             url,
             { 'tab_name' : title },
-            { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ] }
+            { 'doc_id' : docid, 'ou_ids' : [ ses('ws_ou') ], 'reload_opac' : xulG.reload_opac }
         );
     } catch(E) {
         alert('Error in server/cat/bib_brief.js, add_volumes(): ' + E);
index d60a119..19fc6d7 100644 (file)
@@ -1998,7 +1998,14 @@ cat.copy_browser.prototype = {
             obj.org_ids = util.functional.map_list( obj.org_ids, function (o) { return Number(o); });
             obj.show_my_libs( obj.default_lib.id() );
             // FIXME - we get a null from the copy_count call if we call it too quickly here
-            setTimeout( function() { obj.show_consortial_count(); }, 2000 );
+            setTimeout(
+                function() {
+                    obj.show_consortial_count();
+                    if (typeof xulG.reload_opac == 'function') {
+                        xulG.reload_opac();
+                    }
+                }, 2000
+            );
         } catch(E) {
             this.error.standard_unexpected_error_alert(document.getElementById('catStrings').getString('staff.cat.copy_browser.refresh_list.error'),E);
         }
index d41b824..913fef6 100644 (file)
@@ -1208,6 +1208,9 @@ g.stash_and_close = function(param) {
             xulG.unlock_copy_editor();
         }
 
+        if (typeof xulG.reload_opac == 'function') {
+            xulG.reload_opac();
+        }
         if (xul_param('load_opac_when_done')) {
             var opac_url = xulG.url_prefix( urls.opac_rdetail ) + g.doc_id;
             var content_params = {