From 89e6cc779711c629b97f60d917876034ab2b3242 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Wed, 15 Jan 2014 17:53:25 -0500 Subject: [PATCH] LP#882586: In Serial Control View, show copy templates owned by ancestors 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 Signed-off-by: Dan Wells --- .../chrome/content/util/fm_utils.js | 18 +++++++++++++++++- .../staff_client/server/serial/sdist_editor.js | 14 +++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/fm_utils.js b/Open-ILS/xul/staff_client/chrome/content/util/fm_utils.js index e0cfe7cb9a..34868d3214 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/fm_utils.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/fm_utils.js @@ -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; +} diff --git a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js index de149032c6..e63327d7c5 100644 --- a/Open-ILS/xul/staff_client/server/serial/sdist_editor.js +++ b/Open-ILS/xul/staff_client/server/serial/sdist_editor.js @@ -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) { -- 2.43.2