1 dojo.require("DojoSRF");
2 dojo.require("openils.CGI");
4 // called on initial page load and when the advance search org unit
5 // selector is changed.
6 function apply_adv_copy_locations() {
9 var sel = dojo.byId('adv_org_selector');
10 var selected_id = sel.options[sel.selectedIndex].getAttribute('value');
11 var org_unit = aou_hash[selected_id];
13 if (org_unit.can_have_vols != 't') {
14 dojo.addClass('adv_chunk_copy_location', 'hidden');
18 var display_orgs = [];
20 // we want to display copy locations at the selected org,
21 // all parent orgs, and all child orgs.
23 function collect_child_orgs(org_id) {
24 display_orgs.push(org_id);
25 for (var id in aou_hash) { // for key in
26 if (aou_hash[id].parent_ou == org_id)
27 collect_child_orgs(id);
31 function collect_parent_orgs(org_id) {
33 display_orgs.push(org_id);
34 collect_parent_orgs(aou_hash[org_id].parent_ou);
37 collect_child_orgs(org_unit.id);
38 collect_parent_orgs(org_unit.parent_ou);
39 fetch_adv_copy_locations(display_orgs);
42 function fetch_adv_copy_locations(org_ids) {
46 fields : ['name', 'id', 'owning_lib'],
47 query : {owning_lib : org_ids, opac_visible : 't'}
50 new OpenSRF.ClientSession('open-ils.fielder').request({
51 method: 'open-ils.fielder.acpl.atomic',
54 oncomplete: function(r) {
57 var list = resp.content();
58 if (list && list.length) {
59 render_adv_copy_locations(list);
61 dojo.addClass('adv_chunk_copy_location', 'hidden');
64 dojo.addClass('adv_chunk_copy_location', 'hidden');
70 function render_adv_copy_locations(locations) {
71 var sel = dojo.byId('adv_copy_location_selector');
72 var cgi = new openils.CGI();
74 // collect any location values from the URL to re-populate the list
75 var url_selected = cgi.param('fi:locations');
77 if (!dojo.isArray(url_selected))
78 url_selected = [url_selected];
81 dojo.removeClass('adv_chunk_copy_location', 'hidden');
84 locations = locations.sort(
85 function(a, b) {return a.name < b.name ? -1 : 1}
88 // remove the previous list of locations
91 // append the new list of locations
92 dojo.forEach(locations, function(loc) {
93 var attrs = {value : loc.id, innerHTML : loc.name};
94 if (url_selected && url_selected.indexOf(''+loc.id) > -1) {
95 attrs.selected = true;
97 sel.appendChild(dojo.create('option', attrs));
101 // load the locations on page load
102 dojo.addOnLoad(function() {
103 apply_adv_copy_locations();
104 dojo.connect(dojo.byId('adv_org_selector'),
105 'onchange', apply_adv_copy_locations);