LP1902272-Bootstrap opac needs to prompt on notification preference update
authorGarry Collum <gcollum@gmail.com>
Tue, 2 Aug 2022 19:35:39 +0000 (19:35 +0000)
committerMichele Morgan <mmorgan@noblenet.org>
Tue, 27 Sep 2022 20:13:41 +0000 (16:13 -0400)
Adds the prompting of updating holds when default notification preferences
are updated in the Bootstrap opac.

To Test:
1. Place a few holds for a patron.
2. Login to the opac and change some default notification methods.
3. The opac does not prompt to update the holds.
4. Apply the patch.
5. The patron should now be prompted to update holds when default
notification methods are changed.

Signed-off-by: Garry Collum <gcollum@gmail.com>
Signed-off-by: John Amundson <jamundson@cwmars.org>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

Open-ILS/src/templates-bootstrap/opac/myopac/prefs_notify.tt2
Open-ILS/src/templates-bootstrap/opac/myopac/prefs_notify_changed_holds.tt2 [new file with mode: 0644]

index e7c8b80..348bd45 100755 (executable)
     WRAPPER "opac/parts/myopac/base.tt2";
     myopac_page = "prefs_notify";
     parent="prefs";
-    prefs_page = 'prefs_notify' %]
+    prefs_page = 'prefs_notify'
+%]
 
 <h3>[% l('Notification Preferences') %]</h3>
-<form method='post'>
-    [% setting = 'opac.hold_notify' %]
-    <input name='[% setting %]' type="hidden"
-        [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %]/>
 
-    <table class="full-width table" id="acct_search_main"
-        title="[% l('Notification Preferences') %]">
-        <tbody>
+    [% IF ctx.affectedChgs %]
+        [% # get hash of sms cariers keyed by id:
+           temp = ctx.search_csc('active','t');
+           tcos = { '0' => 'None' };
+           FOR o IN temp;
+               id = o.id;
+               tcos.$id = o;
+           END;
+        %]
 
-            [% IF ctx.updated_user_settings %]
-            <tr><td colspan='2'>
-                <div class='renew-summary'>
-                    [% l('Account Successfully Updated') %]
-                </div>
-            </td></tr>
-            [% END %]
+  <h4 class="">[% l('You have updated notification preferences. Those changes only affect future holds. Would you like to update existing holds to use the new information?') %]</h4>
+    <form id="hold_updates_form" name="hold_updates_form" method='post' action="./prefs_notify_changed_holds" onsubmit='return updateHoldsCheck()'>
+        <table class="full-width table" id="acct_search_main" 
+            title="[% l('Notification Preferences') %]">
+            <tbody>
+        [% SET blnk = l('Blank') %]
+        [% FOR c IN ctx.affectedChgs %]
+            <tr>
+              <td>
+                [% IF c.2 == 'sms_info' %]
+                <input type='hidden' name="[% c.2 %][]" value="[% c.0.carrier _ ',' _ c.0.sms | html %]" />
+                <input type='hidden' name="[% c.2 %][]" value="[% c.1.carrier _ ',' _ c.1.sms | html %]" />
+                [% ELSE %]
+                <input type='hidden' name="[% c.2 %][]" value="[% c.0 %]" />
+                <input type='hidden' name="[% c.2 %][]" value="[% c.1 %]" />
+                [% END %]
+                <input type='hidden' name="[% c.2 %][]" value="[% c.2 %]" />
+                <input type='hidden' name="[% c.2 %][]" value="[% FOREACH i IN c.3 %][% i %],[% END %]" />
+                <input id="[% c %]" type="checkbox" onchange="canSubmit(event)" name="[% c.2 %][]"/>
+                [% IF c.2 == 'sms_info' %]
+                    [% SET disp_name = l('SMS carrier/number') %]
+                    <label for="[% c %]">[% c.3.size %] hold(s) currently with [% disp_name %] set to '[% old = c.0.carrier; tcos.$old.name() ? tcos.$old.name() : blnk | html %]/[% c.0.sms ? c.0.sms : blnk | html %]'. Update to '[% new = c.1.carrier; tcos.$new.name()  ? tcos.$new.name() : blnk | html %]/[% c.1.sms ? c.1.sms : blnk | html %]'?</label>
+                [% ELSIF c.2.match('_notify') %]
+                    [% SET f_name = c.2.replace("_", " "); Y = l('YES'); N = l('NO') %]
+                    <label for="[% c %]">[% c.3.size %] hold(s) currently with [% f_name %] set to [% c.0 == 'false' ? N : Y %]. Update to [% c.1 == 'false' ? N : Y %]?</label>
+                [% ELSE %]
+                    [% SET f_name = c.2.replace("_", " ") %]
+                    <label for="[% c %]">[% c.3.size %] hold(s) currently with [% f_name %] set to '[% c.0 ? c.0 : blnk %]'. Update to '[% c.1 ? c.1 : blnk %]'?</label>
+                [% END %]
+              </td>
+            </tr>
+        [% END %]
+            </tbody>
+        </table>
+        <input type='submit' disabled value="[% l('Update') %]" class="opac-button" />
+        <a href='/eg/opac/myopac/prefs_notify'>[% l('Continue without updating') %]</a>
+    </form>
 
+    [% ELSE %]
+        <form id="hold_notify_form" name="hold_notify_form" method='post'>
             [% setting = 'opac.hold_notify' %]
-            <tr>
-                [%# WCAG insists that labels for checkboxes contain the input
-                    or directly follow the input, which would not look right
-                    with the rest of the table.  As an alternative, we can
-                    repeat the label as a title attr.
-                    http://www.w3.org/TR/WCAG20-TECHS/H44.html %]
-                [% email_label = l('Notify by Email by default when a hold is ready for pickup?') %]
+            <input name='[% setting %]' type="hidden"
+                [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %]/>
 
-                <td><label for='[% setting %].email'>[% email_label %]</label></td>
-                <td>
-                    <input id='[% setting %].email' name='[% setting %].email'
-                        type="checkbox" title="[% email_label %]"
-                        [% IF (matches = ctx.user_setting_map.$setting.match('email')); %] checked='checked' [% END %]/>
-                </td>
-            </tr>
-            [%- IF allow_phone_notifications == 'true';
-                setting = 'opac.hold_notify';
-            -%]
-            <tr>
-                [% phone_label = l('Notify by Phone by default when a hold is ready for pickup?') %]
-                <td><label for='[% setting %].phone'>[% phone_label %]</label></td>
-                <td>
-                    <input id='[% setting %].phone' name='[% setting %].phone'
-                        type="checkbox" title="[% phone_label %]"
-                        [% IF (matches = ctx.user_setting_map.$setting.match('phone')); %] checked='checked' [% END %]/>
-                </td>
-            </tr>
-            [% setting = 'opac.default_phone' %]
-            <tr>
-                <td><label for='[% setting %]'>[% l('Default Phone Number') %]</label></td>
-                <td>
-                    <input id='[% setting %]' name='[% setting %]' type="text"
-                        [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %] class="form-control"/>
-                </td>
-            </tr>
-            [%- END %]
-            [%- IF ctx.get_org_setting(ctx.search_ou, 'sms.enable') == 1;
-               setting = 'opac.hold_notify';
-            -%]
-            <tr>
-                [% sms_label = l('Notify by Text by default when a hold is ready for pickup?') %]
-                <td><label for='[% setting %].sms'>[% sms_label %]</label></td>
-                <td>
-                    <input id='[% setting %].sms' name='[% setting %].sms'
-                        type="checkbox" title="[% sms_label %]"
-                        [% IF (matches = ctx.user_setting_map.$setting.match('sms')); %] checked='checked' [% END %]/>
-                </td>
-            </tr>
-            <tr>
-                <td>[% l('Default Mobile Carrier') %]</td>
-                <td>[% INCLUDE "opac/parts/sms_carrier_selector.tt2" sms_carrier_hide_label="true" %]</td>
-            </tr>
-            [% setting = 'opac.default_sms_notify' %]
-            <tr>
-                <td><label for='[% setting %]'>[% l('Default Mobile Number') %]</label></td>
-                <td>
-                    <input id='[% setting %]' name='[% setting %]' type="text"
-                        [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %]/>
-                    [% l('Hint: use the full 10 digits of your phone #, no spaces, no dashes'); %]
-                </td>
-            </tr>
-            [% END %]
-            [% FOR optin IN ctx.opt_in_settings %]
-            <tr>
-                <td><label for='[% optin.cust.name | uri %]'>[% optin.cust.label | html %]</label></td>
-                <td>
-                    <input type='checkbox' name='setting'
-                        value='[% optin.cust.name | uri %]'
-                        id='[% optin.cust.name | uri %]'
-                        title="[% optin.cust.label | html %]"
-                        [% IF optin.value %] checked='checked' [% END %]/>
-                </td>
-            </tr>
-            [% END %]
-        </tbody>
-    </table>
+            <table class="full-width table" id="acct_search_main" 
+                title="[% l('Notification Preferences') %]">
+                <tbody>
+
+                    [% IF ctx.updated_user_settings %]
+                    <tr><td colspan='2'>
+                        <div class='renew-summary'>
+                            [% l('Account Successfully Updated') %]
+                        </div>
+                    </td></tr>
+                    [% END %]
+
+                    [% setting = 'opac.hold_notify' %]
+                    <tr>
+                        [%# WCAG insists that labels for checkboxes contain the input
+                            or directly follow the input, which would not look right
+                            with the rest of the table.  As an alternative, we can
+                            repeat the label as a title attr.
+                            http://www.w3.org/TR/WCAG20-TECHS/H44.html %]
+                        [% email_label = l('Notify by Email by default when a hold is ready for pickup?') %]
+
+                        <td><label for='[% setting %].email'>[% email_label %]</label></td>
+                        <td>
+                            <input onchange="record_change(event)" id='[% setting %].email' name='[% setting %].email'
+                                type="checkbox" title="[% email_label %]"
+                                [% IF (matches = ctx.user_setting_map.$setting.match('email')); %] checked='checked' [% END %]/>
+                        </td>
+                    </tr>
+                    [%- IF allow_phone_notifications == 'true';
+                        setting = 'opac.hold_notify'; 
+                    -%]
+                    <tr>
+                        [% phone_label = l('Notify by Phone by default when a hold is ready for pickup?') %]
+                        <td><label for='[% setting %].phone'>[% phone_label %]</label></td>
+                        <td>
+                            <input onchange="record_change(event)" id='[% setting %].phone' name='[% setting %].phone'
+                                type="checkbox" title="[% phone_label %]"
+                                [% IF (matches = ctx.user_setting_map.$setting.match('phone')); %] checked='checked' [% END %]/>
+                        </td>
+                    </tr>
+                    [% setting = 'opac.default_phone' %]
+                    <tr>
+                        <td><label for='[% setting %]'>[% l('Default Phone Number') %]</label></td>
+                        <td>
+                            <input onchange="record_change(event)" id='[% setting %]' name='[% setting %]' type="text"
+                                [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %]/>
+                        </td>
+                    </tr>
+                    [%- END %]
+                    [%- IF ctx.get_org_setting(ctx.search_ou, 'sms.enable') == 1;
+                       setting = 'opac.hold_notify';
+                    -%]
+                    <tr>
+                        [% sms_label = l('Notify by Text by default when a hold is ready for pickup?') %]
+                        <td><label for='[% setting %].sms'>[% sms_label %]</label></td>
+                        <td>
+                            <input onchange="record_change(event)" id='[% setting %].sms' name='[% setting %].sms'
+                                type="checkbox" title="[% sms_label %]"
+                                [% IF (matches = ctx.user_setting_map.$setting.match('sms')); %] checked='checked' [% END %]/>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td>[% l('Default Mobile Carrier') %]</td>
+                        <td>[% INCLUDE "opac/parts/sms_carrier_selector.tt2" sms_carrier_hide_label="true" %]</td>
+                    </tr>
+                    [% setting = 'opac.default_sms_notify' %]
+                    <tr id="test_notification_banner" style="display:none">
+                        <td colspan="4">
+                            [% INCLUDE "opac/myopac/test_notification.tt2" message_type = "sms" %]
+                        </td>
+                    </tr>
+                    <tr>
+                        <td><label for='[% setting %]'>[% l('Default Mobile Number') %]</label></td>
+                        <td>
+                            <input onchange="record_change(event)" id='[% setting %]' name='[% setting %]' type="text"
+                                [% IF ctx.user_setting_map.$setting; %] value='[% ctx.user_setting_map.$setting | html %]' [% END %]/>
+                            [% IF ctx.user_setting_map.$setting; %]
+                            <a href="#" onclick="sendTestSMS(
+                            [% ctx.user.id %], '[% ctx.authtoken %]'
+                            )"
+                            title="[% l('Send Test Text Message') %]">[% l('Send Test Text Message') %]</a><br />
+                            [% l('Hint: use the full 10 digits of your phone #, no spaces, no dashes'); %]
+                            [% END %]
+                        </td>
+                    </tr>
+                    [% END %]
+                    [% FOR optin IN ctx.opt_in_settings %]
+                    <tr>
+                        <td><label for='[% optin.cust.name | uri %]'>[% optin.cust.label | html %]</label></td>
+                        <td>
+                            <input type='checkbox' name='setting' 
+                                value='[% optin.cust.name | uri %]' 
+                                id='[% optin.cust.name | uri %]' 
+                                title="[% optin.cust.label | html %]"
+                                [% IF optin.value %] checked='checked' [% END %]/>
+                        </td>
+                    </tr>
+                    [% END %]
+                </tbody>
+            </table>
 
     <button type='submit' class="btn btn-confirm"><i class="fas fa-save"></i> [% l('Save') %]</button>
 </form>
+  [% END %]
 [% END %]
 
 
diff --git a/Open-ILS/src/templates-bootstrap/opac/myopac/prefs_notify_changed_holds.tt2 b/Open-ILS/src/templates-bootstrap/opac/myopac/prefs_notify_changed_holds.tt2
new file mode 100644 (file)
index 0000000..0a33c3f
--- /dev/null
@@ -0,0 +1,29 @@
+[%  PROCESS "opac/parts/header.tt2";
+    WRAPPER "opac/parts/myopac/prefs_base.tt2";
+    myopac_page = "prefs";
+    prefs_page = 'prefs_notify' %]
+
+<h3 class="sr-only">[% l('Affected Holds') %]</h3>
+<div id="update_hold_notify_confirm" >
+    [% IF ctx.updated %]
+        <p>[% l('Hold Notification Information Updated.') %]</p>
+<!--
+        <ul>
+        [% FOREACH c IN ctx.updated %]
+            <li>
+            [% l('Holds updated: ') %]
+                [% FOREACH i IN c %]
+                    [% i %]
+                [% END %]
+            </li>
+        [% END %]
+        </ul>
+-->
+    [% ELSE %]
+    <p>[% l('No changes') %].</p>
+    [% END %]
+    <a href='/eg/opac/myopac/prefs_notify'>[% l('Continue.') %]</a>
+</form>
+[% END %]
+
+