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 var display_orgs = [];
15 // we want to display copy locations at the selected org,
16 // all parent orgs, and all child orgs.
18 function collect_child_orgs(org_id) {
19 display_orgs.push(org_id);
20 for (var id in aou_hash) { // for key in
21 if (aou_hash[id].parent_ou == org_id)
22 collect_child_orgs(id);
26 function collect_parent_orgs(org_id) {
28 display_orgs.push(org_id);
29 collect_parent_orgs(aou_hash[org_id].parent_ou);
32 display_orgs.push(org_unit.id);
33 collect_parent_orgs(org_unit.parent_ou);
34 fetch_adv_copy_locations(display_orgs);
37 function fetch_adv_copy_locations(org_ids) {
41 fields : ['name', 'id', 'owning_lib'],
42 query : {owning_lib : org_ids, opac_visible : 't', deleted : 'f'}
45 new OpenSRF.ClientSession('open-ils.fielder').request({
46 method: 'open-ils.fielder.acpl.atomic',
49 oncomplete: function(r) {
52 var list = resp.content();
53 if (list && list.length) {
54 render_adv_copy_locations(list);
55 render_adv_copy_locations_new(list);
57 dojo.addClass('adv_chunk_copy_location', 'hidden');
60 dojo.addClass('adv_chunk_copy_location', 'hidden');
66 function render_adv_copy_locations_new(locations) {
67 var sel = dojo.byId('adv_copy_location_selector_new');
70 var cgi = new openils.CGI();
72 // collect any location values from the URL to re-populate the list
73 var url_selected = cgi.param('fi:locations');
75 if (!dojo.isArray(url_selected))
76 url_selected = [url_selected];
79 dojo.removeClass('adv_chunk_copy_location', 'hidden');
82 locations = locations.sort(
83 function(a, b) {return a.name < b.name ? -1 : 1}
87 var ulist = dojo.create('ul', {class: "adv_filters"});
88 // append the new list of locations
89 dojo.forEach(locations, function(loc) {
90 var attrs = {value : loc.id, name : "fi:locations", type: "checkbox", class: "form-check-input"};
91 if (url_selected && url_selected.indexOf(''+loc.id) > -1) {
92 attrs.selected = true;
96 ulist.appendChild(dojo.create('li')).appendChild(dojo.create('div', {class: "form-check"})).appendChild(dojo.create('label', {innerHTML : loc.name, class: "form-check-label"})).prepend(dojo.create('input', attrs));
98 sel.appendChild(dojo.create("div", {class: "card-body"})).appendChild(ulist);}
103 function render_adv_copy_locations(locations) {
104 var sel = dojo.byId('adv_copy_location_selector');
108 var cgi = new openils.CGI();
110 // collect any location values from the URL to re-populate the list
111 var url_selected = cgi.param('fi:locations');
113 if (!dojo.isArray(url_selected))
114 url_selected = [url_selected];
117 dojo.removeClass('adv_chunk_copy_location', 'hidden');
120 locations = locations.sort(
121 function(a, b) {return a.name < b.name ? -1 : 1}
124 // remove the previous list of locations
127 // append the new list of locations
128 dojo.forEach(locations, function(loc) {
129 var attrs = {value : loc.id, innerHTML : loc.name};
130 if (url_selected && url_selected.indexOf(''+loc.id) > -1) {
131 attrs.selected = true;
133 sel.appendChild(dojo.create('option', attrs));
138 // load the locations on page load
139 dojo.addOnLoad(function() {
140 apply_adv_copy_locations();
141 dojo.connect(dojo.byId('adv_org_selector'),
142 'onchange', apply_adv_copy_locations);