Refactor retrieval of cbs object into cat.util.get_cbs_for_bre_id().
authorJason Stephenson <jstephenson@mvlc.org>
Wed, 16 Nov 2011 00:31:12 +0000 (19:31 -0500)
committerDan Scott <dscott@laurentian.ca>
Mon, 5 Dec 2011 18:27:56 +0000 (13:27 -0500)
Avoid code duplication.

Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
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/util.js

index 189d523..df04c3d 100644 (file)
@@ -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;
index 90cad41..046c88e 100644 (file)
@@ -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) {
index 5719987..046c20f 100644 (file)
@@ -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');