From: Jason Stephenson Date: Wed, 16 Nov 2011 00:31:12 +0000 (-0500) Subject: Refactor retrieval of cbs object into cat.util.get_cbs_for_bre_id(). X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=86e08c1b4b92b44f5531f3fc8804c3cbece84723;p=evergreen%2Fmasslnc.git Refactor retrieval of cbs object into cat.util.get_cbs_for_bre_id(). Avoid code duplication. Signed-off-by: Jason Stephenson Signed-off-by: Dan Scott --- diff --git a/Open-ILS/xul/staff_client/server/cat/bib_brief.js b/Open-ILS/xul/staff_client/server/cat/bib_brief.js index 189d52391c..df04c3d169 100644 --- a/Open-ILS/xul/staff_client/server/cat/bib_brief.js +++ b/Open-ILS/xul/staff_client/server/cat/bib_brief.js @@ -171,20 +171,8 @@ function add_volumes() { } try { - var bibObj = g.network.request( - api.FM_BRE_RETRIEVE_VIA_ID.app, - api.FM_BRE_RETRIEVE_VIA_ID.method, - [ ses(), [docid] ] - ); - - bibObj = bibObj[0]; - - var cbsObj = g.network.request( - api.FM_CBS_RETRIEVE_VIA_PCRUD.app, - api.FM_CBS_RETRIEVE_VIA_PCRUD.method, - [ ses(), bibObj.source() ] - ); - + JSAN.use('cat.util'); + var cbsObj = cat.util.get_cbs_for_bre_id(docid); if (cbsObj.can_have_copies() != get_db_true()) { alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); return; diff --git a/Open-ILS/xul/staff_client/server/cat/copy_browser.js b/Open-ILS/xul/staff_client/server/cat/copy_browser.js index 90cad418f9..046c88e05a 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_browser.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_browser.js @@ -1855,17 +1855,8 @@ cat.copy_browser.prototype = { 'source_init' : function() { var obj = this; try { - var bibObj = obj.network.request( - api.FM_BRE_RETRIEVE_VIA_ID.app, - api.FM_BRE_RETRIEVE_VIA_ID.method, - [ ses(), [obj.docid] ] - ); - bibObj = bibObj[0]; - var cbsObj = obj.network.request( - api.FM_CBS_RETRIEVE_VIA_PCRUD.app, - api.FM_CBS_RETRIEVE_VIA_PCRUD.method, - [ ses(), bibObj.source() ] - ); + JSAN.use('cat.util'); + var cbsObj = cat.util.get_cbs_for_bre_id(obj.docid); obj.can_have_copies = (cbsObj.can_have_copies() == get_db_true()); obj.source = cbsObj.source(); } catch(E) { diff --git a/Open-ILS/xul/staff_client/server/cat/util.js b/Open-ILS/xul/staff_client/server/cat/util.js index 5719987b42..046c20f89c 100644 --- a/Open-ILS/xul/staff_client/server/cat/util.js +++ b/Open-ILS/xul/staff_client/server/cat/util.js @@ -12,7 +12,7 @@ cat.util.EXPORT_OK = [ 'render_loan_duration', 'mark_item_as_missing_pieces', 'render_callnumbers_for_bib_menu', 'render_cn_prefix_menuitems', 'render_cn_suffix_menuitems', 'render_cn_class_menu', 'render_cn_prefix_menu', 'render_cn_suffix_menu', 'transfer_specific_title_holds', - 'request_items', 'mark_for_overlay' + 'request_items', 'mark_for_overlay', 'get_cbs_for_bre_id' ]; cat.util.EXPORT_TAGS = { ':all' : cat.util.EXPORT_OK }; @@ -1263,5 +1263,22 @@ cat.util.mark_for_overlay = function(doc_id,doc_mvr) { } } +cat.util.get_cbs_for_bre_id = function(doc_id) { + try { + JSAN.use('util.network'); var network = new util.network(); + var bibObj = network.simple_request( + 'FM_BRE_RETRIEVE_VIA_ID', + [ ses(), [ doc_id ] ] + ); + bibObj = bibObj[0]; + var cbsObj = network.simple_request( + 'FM_CBS_RETRIEVE_VIA_PCRUD', + [ ses(), bibObj.source() ] + ); + return cbsObj; + } catch(E) { + alert('Error in cat.util.cbs_can_have_copies(): ' + E); + } +} dump('exiting cat/util.js\n');