From: Dan Wells Date: Fri, 17 Jun 2011 19:26:39 +0000 (-0400) Subject: Better coordination of MFHD/SRE adding/deleting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9970bcb407cd6eb399077084c0d79bd21496eef3;p=evergreen%2Fpines.git Better coordination of MFHD/SRE adding/deleting Adding or deleting MFHD records from the XUL menus requires coordinating the OPAC display, the XUL menus, and the Serial Control distribution editors. The previous code frequently required some non-obvious manual refreshing to make it work. This commit keeps them in sync using custom events instead. Signed-off-by: Dan Wells Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js index 9d54056733..ceef976e5d 100644 --- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js +++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js @@ -490,6 +490,9 @@ function set_opac() { item = mfhd_delete_menu.appendItem(label); item.setAttribute('oncommand','delete_mfhd('+mfhd_details.id+')'); } + var change_event = document.createEvent("Event"); + change_event.initEvent("MFHDChange",false,false); + window.dispatchEvent(change_event); } } ); @@ -558,7 +561,7 @@ function create_mfhd() { throw(r); } alert("MFHD record created."); //TODO: better success message - //TODO: refresh opac display + 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 } @@ -580,7 +583,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')); - //TODO: refresh opac display + browser_frame.contentWindow.g.browser.controller.view.cmd_reload.doCommand(); } } } diff --git a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js index 908a90e55d..74665d8f82 100644 --- a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js +++ b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js @@ -23,24 +23,11 @@ serial.sdist_editor = function (params) { // setup sre arrays this.sre_id_map = {}; this.sres_ou_map = {}; - var parent_g = window.parent.g; - if (parent_g.mfhd) { - var mfhd_details = parent_g.mfhd.details; - for (var i = 0; i < mfhd_details.length; i++) { - var mfhd_detail = {}; - for (j in mfhd_details[i]) { - mfhd_detail[j] = mfhd_details[i][j]; - } - mfhd_detail.label = mfhd_detail.label + ' (' + (mfhd_detail.entryNum + 1) + ')'; - var sre_id = mfhd_detail.id; - var org_unit_id = mfhd_detail.owning_lib; - this.sre_id_map[sre_id] = mfhd_detail; - if (!this.sres_ou_map[org_unit_id]) { - this.sres_ou_map[org_unit_id] = []; - } - this.sres_ou_map[org_unit_id].push(mfhd_detail); - } - } + this.build_sre_maps(); + + // update sre maps on demand + var obj = this; + window.parent.addEventListener("MFHDChange", function() {obj.build_sre_maps()}, false); }; serial.sdist_editor.prototype = { @@ -293,6 +280,37 @@ serial.sdist_editor.prototype = { 'save_attributes' : serial.editor_base.editor_base_save_attributes, /******************************************************************************************************/ + /* Build maps of sre details for both display and selection purposes */ + + 'build_sre_maps' : function() { + var obj = this; + try { + obj.sre_id_map = {}; + obj.sres_ou_map = {}; + var parent_g = window.parent.g; + if (parent_g.mfhd) { + var mfhd_details = parent_g.mfhd.details; + for (var i = 0; i < mfhd_details.length; i++) { + var mfhd_detail = {}; + for (j in mfhd_details[i]) { + mfhd_detail[j] = mfhd_details[i][j]; + } + mfhd_detail.label = mfhd_detail.label + ' (' + (mfhd_detail.entryNum + 1) + ')'; + var sre_id = mfhd_detail.id; + var org_unit_id = mfhd_detail.owning_lib; + obj.sre_id_map[sre_id] = mfhd_detail; + if (!obj.sres_ou_map[org_unit_id]) { + obj.sres_ou_map[org_unit_id] = []; + } + obj.sres_ou_map[org_unit_id].push(mfhd_detail); + } + } + } catch(E) { + obj.error.standard_unexpected_error_alert('build_sre_maps',E); + } + }, + + /******************************************************************************************************/ /* This returns a list of sre details appropriate for the distributions being edited */ 'get_sre_details_list' : function() {