From 2b86c83135facdb385a7095fdf9f7c7f32ccde53 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Thu, 2 Feb 2023 20:26:08 -0800 Subject: [PATCH] Remove dojo from copyloc.js --- Open-ILS/web/js/ui/default/opac/copyloc.js | 94 ++++++++++++++++-------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/Open-ILS/web/js/ui/default/opac/copyloc.js b/Open-ILS/web/js/ui/default/opac/copyloc.js index 0c55ccdc09..42ce54c420 100644 --- a/Open-ILS/web/js/ui/default/opac/copyloc.js +++ b/Open-ILS/web/js/ui/default/opac/copyloc.js @@ -1,28 +1,15 @@ -dojo.require("DojoSRF"); -dojo.require("openils.CGI"); - +$.getScript('/js/dojo/openils/CGI.js'); +$.getScript('/opac/common/js/DojoSRF.js'); // 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]; + const selected_id = document.getElementById('adv_org_selector').value; + const org_unit = aou_hash[selected_id]; 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); @@ -54,30 +41,30 @@ function fetch_adv_copy_locations(org_ids) { render_adv_copy_locations(list); render_adv_copy_locations_new(list); } else { - dojo.addClass('adv_chunk_copy_location', 'hidden'); + document.getElementById('adv_chunk_copy_location').classList.add('hidden'); } } else { - dojo.addClass('adv_chunk_copy_location', 'hidden'); + document.getElementById('adv_chunk_copy_location').classList.add('hidden'); } } }).send(); } function render_adv_copy_locations_new(locations) { - var sel = dojo.byId('adv_copy_location_selector_new'); + var sel = document.getElementById('adv_copy_location_selector_new'); if(sel) { - dojo.empty(sel); + sel.replaceChildren(); 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)) + if (!url_selected.isArray()) url_selected = [url_selected]; } - dojo.removeClass('adv_chunk_copy_location', 'hidden'); + document.getElementById('adv_chunk_copy_location').classList.remove('hidden'); // sort by name locations = locations.sort( @@ -85,24 +72,44 @@ function render_adv_copy_locations_new(locations) { ); - var ulist = dojo.create('ul', {class: "adv_filters"}); + let ulist = document.createElement('ul'); + ulist.classList.add('adv_filters'); // append the new list of locations - dojo.forEach(locations, function(loc) { - var attrs = {value : loc.id, name : "fi:locations", type: "checkbox", class: "form-check-input"}; + locations.forEach(function(loc) { + // The following should create + //
  • + // + let li = document.createElement('li'); + li.classList.add('form-check'); + + let label = document.createElement('label'); + label.classList.add('form-check-label'); + + let input = document.createElement('input'); + input.setAttribute('value', loc.id); + input.setAttribute('name', 'fi:locations'); + input.setAttribute('type', 'checkbox'); + input.classList.add('form-check-input'); if (url_selected && url_selected.indexOf(''+loc.id) > -1) { - attrs.selected = true; + input.setAttribute('selected', true); } - - - 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)); + + label.appendChild(input); + label.append(loc.name); + li.appendChild(label); + ulist.appendChild(li); }); - sel.appendChild(dojo.create("div", {class: "card-body"})).appendChild(ulist);} + let cardBody = document.createElement('div'); + cardBody.classList.add('card-body'); + cardBody.appendChild(ulist); + sel.appendChild(cardBody); +} } function render_adv_copy_locations(locations) { - var sel = dojo.byId('adv_copy_location_selector'); + const sel = document.getElementById('adv_copy_location_selector'); if(sel){ @@ -111,11 +118,11 @@ function render_adv_copy_locations(locations) { // 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)) + if (!url_selected.isArray()) url_selected = [url_selected]; } - dojo.removeClass('adv_chunk_copy_location', 'hidden'); + document.getElementById('adv_chunk_copy_location').classList.remove('hidden'); // sort by name locations = locations.sort( @@ -123,23 +130,24 @@ function render_adv_copy_locations(locations) { ); // remove the previous list of locations - dojo.empty(sel); + sel.replaceChildren(); // append the new list of locations - dojo.forEach(locations, function(loc) { - var attrs = {value : loc.id, innerHTML : loc.name}; + locations.forEach((loc) => { + let option = document.createElement('option'); + option.setAttribute('value', loc.id); + option.innerHTML = loc.name; if (url_selected && url_selected.indexOf(''+loc.id) > -1) { - attrs.selected = true; + option.setAttribute('selected', true); } - sel.appendChild(dojo.create('option', attrs)); + sel.appendChild(option); }); } } // load the locations on page load -dojo.addOnLoad(function() { +window.addEventListener('DOMContentLoaded', () => { apply_adv_copy_locations(); - dojo.connect(dojo.byId('adv_org_selector'), - 'onchange', apply_adv_copy_locations); -}); + document.getElementById('adv_org_selector').addEventListener('change', apply_adv_copy_locations); +}) -- 2.11.0