From 2755e14e3f2aee3f85044efde51973462b1bc2dc Mon Sep 17 00:00:00 2001 From: pines Date: Thu, 28 Sep 2006 21:55:53 +0000 Subject: [PATCH] show correctly copy locations in copy editor git-svn-id: svn://svn.open-ils.org/ILS/trunk@6257 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../staff_client/chrome/content/util/fm_utils.js | 82 +++++++++++++++++++++- .../xul/staff_client/server/cat/copy_editor.js | 35 +++++---- 2 files changed, 104 insertions(+), 13 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 95c838ab62..1d7a850f11 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' ]; +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_TAGS = { ':all' : util.fm_utils.EXPORT_OK }; util.fm_utils.flatten_ou_branch = function(branch) { @@ -65,3 +65,83 @@ util.fm_utils.sort_func_aou_by_depth_and_then_string = function(a,b) { return 0; } } + +util.fm_utils.find_common_aou_ancestor = function(orgs) { + try { + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); + + var candidates = {}; + for (var i = 0; i < orgs.length; i++) { + + var node = orgs[i]; + + while (node) { + + if (typeof node != 'object') node = data.hash.aou[ node ]; + if (!node) continue; + + if ( candidates[node.id()] ) { + + candidates[node.id()]++; + + } else { + + candidates[node.id()] = 1; + } + + if (candidates[node.id()] == orgs.length) return node; + + node = node.parent_ou(); + } + + } + + return null; + + } catch(E) { + alert('error in util.fm_utils.find_common_aou_ancestor: ' + E); + return null; + } +} + +util.fm_utils.find_common_aou_ancestors = function(orgs) { + try { + JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'}); + + var candidates = {}; var winners = []; + for (var i = 0; i < orgs.length; i++) { + + var node = orgs[i]; + + while (node) { + + if (typeof node != 'object') node = data.hash.aou[ node ]; + if (!node) continue; + + if ( candidates[node.id()] ) { + + candidates[node.id()]++; + + } else { + + candidates[node.id()] = 1; + } + + node = node.parent_ou(); + } + + } + + for (var i in candidates) { + + if (candidates[i] == orgs.length) winners.push( i ); + } + + return winners; + + } catch(E) { + alert('error in util.fm_utils.find_common_aou_ancestors: ' + E); + return []; + } +} + diff --git a/Open-ILS/xul/staff_client/server/cat/copy_editor.js b/Open-ILS/xul/staff_client/server/cat/copy_editor.js index 00fef0ebd1..5de34d636a 100644 --- a/Open-ILS/xul/staff_client/server/cat/copy_editor.js +++ b/Open-ILS/xul/staff_client/server/cat/copy_editor.js @@ -393,7 +393,9 @@ g.populate_alert_message_input = function(tb) { g.get_acpl_list = function() { try { - function get(lib_id) { + JSAN.use('util.functional'); + + function get(lib_id,only_these) { g.data.stash_retrieve(); var label = 'acpl_list_for_lib_'+lib_id; if (typeof g.data[label] == 'undefined') { @@ -406,28 +408,37 @@ g.get_acpl_list = function() { g.data.hash.acpl[ my_acpl.id() ] = my_acpl; g.data.list.acpl.push( my_acpl ); } - temp_list.push( my_acpl ); + if (only_these.indexOf( String( my_acpl.owning_lib() ) ) != -1) { + temp_list.push( my_acpl ); + } } g.data[label] = temp_list; g.data.stash(label,'hash','list'); } return g.data[label]; } - var seen = {}; seen[ g.data.list.au[0].ws_ou() ] = true; - var list = get( g.data.list.au[0].ws_ou() ); //g.data.list.acpl; + var libs = []; var map_acn = {}; for (var i = 0; i < g.copies.length; i++) { var cn_id = g.copies[i].call_number(); if (cn_id > 0) { - var my_acn = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]); - var lib = my_acn.owning_lib(); - if ( typeof seen[lib] == 'undefined' ) { - seen[lib] = true; - var r = get(my_acn.owning_lib()); - list = list.concat( r ); + if (! map_acn[ cn_id ]) { + map_acn[ cn_id ] = g.network.simple_request('FM_ACN_RETRIEVE',[ cn_id ]); + libs.push( map_acn[ cn_id ].owning_lib() ); } - } + } } - return list; + JSAN.use('util.fm_utils'); + var ancestor = util.fm_utils.find_common_aou_ancestor( libs ); + if (typeof ancestor == 'object') ancestor = ancestor.id(); + + var ancestors = util.fm_utils.find_common_aou_ancestors( libs ); + + if (ancestor) { + return get(ancestor, ancestors); + } else { + return []; + } + } catch(E) { g.error.standard_unexpected_error_alert('get_acpl_list',E); return list; -- 2.11.0