From d2fd2441a841b1fa1d29bc4f55ebefc0f89f126a Mon Sep 17 00:00:00 2001
From: Dan Briem <dbriem@wlsmail.org>
Date: Sat, 20 Nov 2021 15:14:36 -0500
Subject: [PATCH] LP#1939426 Traditional Catalog Holds: Patron Info Not
 Populating

When no hold groups exist, its interface isn't present. When
placing volume holds, the advanced link isn't present.

This checks that those elements exist before accessing their
attributes and adds a missing name attribute to the Bootstrap
catalog to display the email address.

Signed-off-by: Dan Briem <dbriem@wlsmail.org>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
---
 .../src/templates-bootstrap/opac/parts/place_hold.tt2 |  2 +-
 Open-ILS/web/js/ui/default/opac/staff.js              | 19 ++++++++++++-------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/Open-ILS/src/templates-bootstrap/opac/parts/place_hold.tt2 b/Open-ILS/src/templates-bootstrap/opac/parts/place_hold.tt2
index b4dc99b897..7af5d42848 100755
--- a/Open-ILS/src/templates-bootstrap/opac/parts/place_hold.tt2
+++ b/Open-ILS/src/templates-bootstrap/opac/parts/place_hold.tt2
@@ -242,7 +242,7 @@ function maybeToggleNumCopies(obj) {
                 <label class="form-check-label" for="email_notify">
                    [% l('Yes, by Email') %]
 
-                     [% IF !ctx.user.email and !ctx.is_staff; l('<br>No configured Email address. See "My Account" for setting your Email address.'); ELSE; %] : <span id="email_address"><b>[% ctx.user.email %]</b></span>[% END %]
+                     [% IF !ctx.user.email and !ctx.is_staff; l('<br>No configured Email address. See "My Account" for setting your Email address.'); ELSE; %] : <span id="email_address"><b name="email_address">[% ctx.user.email %]</b></span>[% END %]
                 </label>
             </div>
 
diff --git a/Open-ILS/web/js/ui/default/opac/staff.js b/Open-ILS/web/js/ui/default/opac/staff.js
index 525b8d5a57..e6da418eb0 100644
--- a/Open-ILS/web/js/ui/default/opac/staff.js
+++ b/Open-ILS/web/js/ui/default/opac/staff.js
@@ -57,10 +57,12 @@ function no_hold_submit(event) {
 function toggleMROptions(on) {
     var anchor = document.getElementById("advanced_hold_link");
     // Check for not equal to block so it works on first click.
-    if (on) {
-        anchor.style.display = "inline";
-    } else {
-        anchor.style.display = "none";
+    if (anchor) {
+        if (on) {
+            anchor.style.display = "inline";
+        } else {
+            anchor.style.display = "none";
+        }
     }
 }
 
@@ -91,13 +93,14 @@ function staff_hold_usr_barcode_changed(isload) {
 
     if (!window.xulG) return;
  
+    var sub_el = document.getElementById('hold_usr_is_subscription');
     var adv_link = document.getElementById('advanced_hold_link');
     if (adv_link) {
         adv_link.setAttribute('href', adv_link.getAttribute('href').replace(/&?is_requestor=[012]/,''));
         var is_requestor = 0;
         if (document.getElementById('hold_usr_is_requestor').checked) {
             is_requestor = 1;
-        } else if (document.getElementById('hold_usr_is_subscription').checked) {
+        } else if (sub_el && sub_el.checked) {
             is_requestor = 2;
         }
         adv_link.setAttribute('href', adv_link.getAttribute('href') + '&is_requestor=' + is_requestor.toString());
@@ -107,7 +110,6 @@ function staff_hold_usr_barcode_changed(isload) {
     var barcode = isload;
     if(!barcode || barcode === true) barcode = document.getElementById('staff_barcode').value;
     var only_settings = true;
-    var sub_el = document.getElementById('hold_usr_is_subscription');
 
     toggleOnSubscription(false);
     if(sub_el && sub_el.checked) {
@@ -250,7 +252,10 @@ window.onload = function() {
             var is_req = is_req_match.exec(loc).toString();
             is_req = is_req.replace(/is_requestor=/, '');
             if (is_req == "2") {
-                document.getElementById('hold_usr_is_subscription').checked = 'checked';
+                var sub_el = document.getElementById('hold_usr_is_subscription');
+                if (sub_el) {
+                    sub_el.checked = 'checked';
+                }
                 document.getElementById('hold_usr_input').disabled = true;
             } else if (is_req == "1") {
                 document.getElementById('hold_usr_is_requestor').checked = 'checked';
-- 
2.11.0