LP#882586: In Serial Control View, show copy templates owned by ancestors collab/senator/lp882586
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 15 Jan 2014 22:53:25 +0000 (17:53 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 15 Jan 2014 22:57:04 +0000 (17:57 -0500)
When creating/editing distributions, dropdowns for Receive Unit Template
and Bind Unit Template now show copy templates owned not only at the
distribution's holding lib, but at any of the holding lib's ancestors.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/xul/staff_client/chrome/content/util/fm_utils.js
Open-ILS/xul/staff_client/server/serial/sdist_editor.js

index e0cfe7c..34868d3 100644 (file)
@@ -3,7 +3,7 @@ dump('entering util/fm_utils.js\n');
 if (typeof util == 'undefined') var util = {};
 util.fm_utils = {};
 
-util.fm_utils.EXPORT_OK    = [ 'flatten_ou_branch', 'find_ou', 'compare_aou_a_is_b_or_ancestor', 'sort_func_aou_by_depth_and_then_string', 'find_common_aou_ancestor', 'find_common_aou_ancestors' ];
+util.fm_utils.EXPORT_OK    = [ 'flatten_ou_branch', 'find_ou', 'compare_aou_a_is_b_or_ancestor', 'sort_func_aou_by_depth_and_then_string', 'find_common_aou_ancestor', 'find_common_aou_ancestors',  'aou_get_ancestor_list_by_id' ];
 util.fm_utils.EXPORT_TAGS    = { ':all' : util.fm_utils.EXPORT_OK };
 
 util.fm_utils.flatten_ou_branch = function(branch) {
@@ -145,3 +145,19 @@ util.fm_utils.find_common_aou_ancestors = function(orgs) {
     }
 }
 
+/* There wasn't already something like this in staff client JS? Really? */
+util.fm_utils.aou_get_ancestor_list_by_id = function(aou_id) {
+    JSAN.use('OpenILS.data');
+    var data = new OpenILS.data();
+    data.stash_retrieve();
+
+    var list = [];
+
+    var aou = data.hash.aou[aou_id];
+    do {
+        list.push(aou.id());
+        aou = data.hash.aou[aou.parent_ou()];
+    } while (aou);
+
+    return list;
+}
index de14903..e63327d 100644 (file)
@@ -402,10 +402,22 @@ serial.sdist_editor.prototype = {
                 return obj.act_lists[lib_id];
             }
             
+            /* get (and cache) list of ancestors for lib_id */
+            obj.aou_ancestor_list_by_id =
+                obj.aou_ancestor_list_by_id || [];
+
+            if (!obj.aou_ancestor_list_by_id[lib_id]) {
+                JSAN.use('util.fm_utils');
+                obj.aou_ancestor_list_by_id[lib_id] = util.fm_utils.aou_get_ancestor_list_by_id(lib_id);
+
+                if (!obj.aou_ancestor_list_by_id[lib_id].length)
+                    throw "ancestor list for " + lib_id + " empty?"; /* unlikely */
+            }
+
             var act_list = obj.network.request(
                 'open-ils.pcrud',
                 'open-ils.pcrud.search.act',
-                [ ses(), {"owning_lib" : lib_id }, {"order_by" : {"act" : "name"} } ]
+                [ ses(), {"owning_lib" : obj.aou_ancestor_list_by_id[lib_id] }, {"order_by" : {"act" : "name"} } ]
             );
 
             if (act_list == null) {