From 12a18aa623528dca466f47cba8c48a8f3273d426 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 4 Oct 2011 14:39:27 -0400 Subject: [PATCH] Can have copies checks code improvement. Add can have copies check to create_mfhd() in opac.js. Rearrange the code a bit to be more concise and to eliminate the can_have_copies variable. Signed-off-by: Jason Stephenson --- .../xul/staff_client/chrome/content/cat/opac.js | 45 +++++++++++++++++----- Open-ILS/xul/staff_client/server/cat/bib_brief.js | 18 ++++----- 2 files changed, 45 insertions(+), 18 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 2bf5ab5224..a07b9a4a90 100644 --- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js +++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js @@ -557,6 +557,32 @@ function set_serctrl_view() { } function create_mfhd() { + // Check if the source is allowed to have copies, first. + 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() ] + ); + + if (cbsObj.can_have_copies() != get_db_true()) { + alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); + return; + } + } catch(E) { + g.error.sdump('D_ERROR','can have copies check: ' + E); + alert('Error in chrome/content/cat/opac.js, create_mfhd(): ' + E); + return; + } + try { JSAN.use('util.window'); var win = new util.window(); var select_aou_window = win.open( @@ -906,31 +932,32 @@ function add_volumes() { return; // no read-only view for this interface } - var can_have_copies = true; - var cbsObj; + // Check if the source is allowed to have copies. 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]; - cbsObj = g.network.request( + + var cbsObj = g.network.request( api.FM_CBS_RETRIEVE_VIA_PCRUD.app, api.FM_CBS_RETRIEVE_VIA_PCRUD.method, [ ses(), bibObj.source() ] ); - can_have_copies = (cbsObj.can_have_copies() == get_db_true()); + + if (cbsObj.can_have_copies() != get_db_true()) { + alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); + return; + } } catch(E) { g.error.sdump('D_ERROR','can have copies check: ' + E); + alert('Error in chrome/content/cat/opac.js, add_volumes(): ' + E); return; } - if (!can_have_copies) { - alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); - return false; - } - var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]); var url; 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 4be0fb2a78..189d52391c 100644 --- a/Open-ILS/xul/staff_client/server/cat/bib_brief.js +++ b/Open-ILS/xul/staff_client/server/cat/bib_brief.js @@ -170,31 +170,31 @@ function add_volumes() { return; // no read-only view for this interface } - var can_have_copies = true; - var cbsObj; 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]; - cbsObj = g.network.request( + + var cbsObj = g.network.request( api.FM_CBS_RETRIEVE_VIA_PCRUD.app, api.FM_CBS_RETRIEVE_VIA_PCRUD.method, [ ses(), bibObj.source() ] ); - can_have_copies = (cbsObj.can_have_copies() == get_db_true()); + + if (cbsObj.can_have_copies() != get_db_true()) { + alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); + return; + } } catch(E) { g.error.sdump('D_ERROR','can have copies check: ' + E); + alert('Error in server/cat/bib_brief.js, add_volumes(): ' + E); return; } - if (!can_have_copies) { - alert(document.getElementById('offlineStrings').getFormattedString('staff.cat.bib_source.can_have_copies.false', [cbsObj.source()])); - return false; - } - var title = document.getElementById('offlineStrings').getFormattedString('staff.circ.copy_status.add_volumes.title', [docid]); var url; -- 2.11.0