From cf96fd6ac17a7f8b425a2f6c27a410026b32bc52 Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Fri, 17 Jun 2011 15:26:39 -0400 Subject: [PATCH] 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 --- .../xul/staff_client/chrome/content/cat/opac.js | 7 ++- .../xul/staff_client/server/serial/sdist_editor.js | 54 ++++++++++++++-------- 2 files changed, 41 insertions(+), 20 deletions(-) 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 c4f4cdc040..5ebd6fff1e 100644 --- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js +++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js @@ -449,6 +449,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); } } ); @@ -513,7 +516,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 } @@ -535,7 +538,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 780ad866ea..2e55ca7c0d 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 = { @@ -284,6 +271,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() { -- 2.11.0