From 6c0e430e5d90173de675e671230481f2ad3f5516 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 13 Aug 2013 14:39:00 -0400 Subject: [PATCH] LP 1084732 TPAC copy location selector Copy location filter selector for the TPAC advanced search interface. The behavior is the same as the analogous JSPAC feature. The interface components are hidden by default, so non-JS browsers will be none the wiser. A number of small tweaks to related code were needed and are included in this commit: 1. Make copy locations field_safe in the IDL so they can be retrieved and parsed without the IDL 2. Insert a (full) hash-based org unit tree as inline JS at the bottom of js.tt2 so JS will have access to the whole tree without having to load the IDL to understand it. 3. Fix a bug in openils.CGI : decodeURIComponent parameter names Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- Open-ILS/examples/fm_IDL.xml | 2 +- .../templates/opac/parts/advanced/search.tt2 | 13 ++- Open-ILS/src/templates/opac/parts/config.tt2 | 3 +- Open-ILS/src/templates/opac/parts/js.tt2 | 19 ++++ Open-ILS/web/js/dojo/openils/CGI.js | 1 + Open-ILS/web/js/ui/default/opac/copyloc.js | 107 ++++++++++++++++++ 6 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 Open-ILS/web/js/ui/default/opac/copyloc.js diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 2fe07f9dfc..0064b76d48 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -4216,7 +4216,7 @@ SELECT usr, - + diff --git a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 index ad8cc4404a..56fd012123 100644 --- a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 +++ b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 @@ -42,14 +42,16 @@ [% END; %] - + [% adv_chunk.adv_label %]
[% IF adv_chunk.adv_special; SWITCH adv_chunk.adv_special; CASE "lib_selector"; PROCESS "opac/parts/org_selector.tt2"; - INCLUDE build_org_selector show_loc_groups=1; %] + INCLUDE build_org_selector show_loc_groups=1 id="adv_org_selector" %]
+ + [% END; ELSIF adv_chunk.adv_attr; INCLUDE "opac/parts/coded_value_selector.tt2" diff --git a/Open-ILS/src/templates/opac/parts/config.tt2 b/Open-ILS/src/templates/opac/parts/config.tt2 index bc046bdbfd..d798fb92b8 100644 --- a/Open-ILS/src/templates/opac/parts/config.tt2 +++ b/Open-ILS/src/templates/opac/parts/config.tt2 @@ -115,7 +115,8 @@ search.adv_config = [ {adv_label => l("Audience"), adv_attr => ["audience_group", "audience"], adv_break => 1}, {adv_label => l("Video Format"), adv_attr => "vr_format"}, {adv_label => l("Bib Level"), adv_attr => "bib_level"}, - {adv_label => l("Literary Form"), adv_attr => "lit_form", adv_break => 1}, + {adv_label => l("Literary Form"), adv_attr => "lit_form"}, + {adv_label => l("Shelving Location"), adv_special => "copy_location", js_only => 1, adv_break => 1}, {adv_label => l("Search Library"), adv_special => "lib_selector"}, {adv_label => l("Publication Year"), adv_special => "pub_year"}, {adv_label => l("Sort Results"), adv_special => "sort_selector"}, diff --git a/Open-ILS/src/templates/opac/parts/js.tt2 b/Open-ILS/src/templates/opac/parts/js.tt2 index 071ce21a36..67d09fb263 100644 --- a/Open-ILS/src/templates/opac/parts/js.tt2 +++ b/Open-ILS/src/templates/opac/parts/js.tt2 @@ -84,5 +84,24 @@ [% INCLUDE "opac/parts/acjs.tt2" IF ctx.page == 'record' %] [% INCLUDE "opac/parts/ac_google_books.tt2" IF ctx.page == 'record' AND ctx.google_books_preview %] +[% IF ctx.page == 'advanced' %] + +[% END %] + + + [%- END; # want_dojo -%] diff --git a/Open-ILS/web/js/dojo/openils/CGI.js b/Open-ILS/web/js/dojo/openils/CGI.js index d79c825ee4..e353e4e5dc 100644 --- a/Open-ILS/web/js/dojo/openils/CGI.js +++ b/Open-ILS/web/js/dojo/openils/CGI.js @@ -62,6 +62,7 @@ if(!dojo._hasResource["openils.CGI"]) { if(c == "&" || c == ";") { inkey = 1; invalue = 0; + key = decodeURIComponent(key); if( ! this.data[key] ) this.data[key] = []; this.data[key].push(decodeURIComponent(value)); this._keys.push(key); diff --git a/Open-ILS/web/js/ui/default/opac/copyloc.js b/Open-ILS/web/js/ui/default/opac/copyloc.js new file mode 100644 index 0000000000..1eaae20c3f --- /dev/null +++ b/Open-ILS/web/js/ui/default/opac/copyloc.js @@ -0,0 +1,107 @@ +dojo.require("DojoSRF"); +dojo.require("openils.CGI"); + +// called on initial page load and when the advance search org unit +// selector is changed. +function apply_adv_copy_locations() { + + // patron selected org + var sel = dojo.byId('adv_org_selector'); + var selected_id = sel.options[sel.selectedIndex].getAttribute('value'); + var org_unit = aou_hash[selected_id]; + + if (org_unit.can_have_vols != 't') { + dojo.addClass('adv_chunk_copy_location', 'hidden'); + return; + } + + var display_orgs = []; + + // we want to display copy locations at the selected org, + // all parent orgs, and all child orgs. + + function collect_child_orgs(org_id) { + display_orgs.push(org_id); + for (var id in aou_hash) { // for key in + if (aou_hash[id].parent_ou == org_id) + collect_child_orgs(id); + } + } + + function collect_parent_orgs(org_id) { + if (!org_id) return; + display_orgs.push(org_id); + collect_parent_orgs(aou_hash[org_id].parent_ou); + } + + collect_child_orgs(org_unit.id); + collect_parent_orgs(org_unit.parent_ou); + fetch_adv_copy_locations(display_orgs); +} + +function fetch_adv_copy_locations(org_ids) { + + var params = [{ + cache : 1, + fields : ['name', 'id', 'owning_lib'], + query : {owning_lib : org_ids, opac_visible : 't'} + }]; + + new OpenSRF.ClientSession('open-ils.fielder').request({ + method: 'open-ils.fielder.acpl.atomic', + params: params, + async: true, + oncomplete: function(r) { + var resp = r.recv(); + if (resp) { + var list = resp.content(); + if (list && list.length) { + render_adv_copy_locations(list); + } else { + dojo.addClass('adv_chunk_copy_location', 'hidden'); + } + } else { + dojo.addClass('adv_chunk_copy_location', 'hidden'); + } + } + }).send(); +} + +function render_adv_copy_locations(locations) { + var sel = dojo.byId('adv_copy_location_selector'); + var cgi = new openils.CGI(); + + // collect any location values from the URL to re-populate the list + var url_selected = cgi.param('fi:locations'); + if (url_selected) { + if (!dojo.isArray(url_selected)) + url_selected = [url_selected]; + } + + dojo.removeClass('adv_chunk_copy_location', 'hidden'); + + // sort by name + locations = locations.sort( + function(a, b) {return a.name < b.name ? -1 : 1} + ); + + // remove the previous list of locations + dojo.empty(sel); + + // append the new list of locations + dojo.forEach(locations, function(loc) { + var attrs = {value : loc.id, innerHTML : loc.name}; + if (url_selected && url_selected.indexOf(''+loc.id) > -1) { + attrs.selected = true; + } + sel.appendChild(dojo.create('option', attrs)); + }); +} + +// load the locations on page load +dojo.addOnLoad(function() { + apply_adv_copy_locations(); + dojo.connect(dojo.byId('adv_org_selector'), + 'onchange', apply_adv_copy_locations); +}); + -- 2.43.2