Remove dojo from copyloc.js
authorJane Sandberg <sandbergja@gmail.com>
Fri, 3 Feb 2023 04:26:08 +0000 (20:26 -0800)
committerJane Sandberg <js7389@princeton.edu>
Fri, 3 Feb 2023 19:51:56 +0000 (11:51 -0800)
Open-ILS/web/js/ui/default/opac/copyloc.js

index 0c55ccd..42ce54c 100644 (file)
@@ -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
+        //  <li><label><input></label></li>
+        //
+        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);
+})