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) {
}
}
+/* 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;
+}
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) {