Bug 21813: In-page JavaScript causes error on patron entry page
authorOwen Leonard <oleonard@myacpl.org>
Mon, 12 Nov 2018 17:35:25 +0000 (17:35 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 10 Jan 2019 13:52:23 +0000 (13:52 +0000)
This patch removes a block of JavaScript from memberentrygen.tt which
was being included in the page before jQuery is loaded. This causes a
JavaScript error.

To test, apply the patch, regenerate CSS, and clear your browser cache
if necessary.

 - In Administration -> Patron categories, confirm that you have two
    patron categories with different default messaging preferences
    defined.
 - Go to Patrons -> New patron
   - Create a new patron using one of the categories with messaging
     preferences.
   - Confirm that when you switch the category selection to the other
     patron category, the patron messaging preference checkboxes are
     changed to the default for that category.
     - A "Loading" indicator should appear above the checkboxes to show
      that an operation is in process. It should disappear when new
      default prefs are loaded.
   - Manually change one or more patron messaging preference checkboxes.
   - Switch the patron category again and confirm that you are prompted
     to confirm resetting the preferences to the default for that
     category.
 - Perform the same set of tests when editing a patron.
   - Defaults should not be loaded during the edit process.
 - Confirm that there are no other JavaScript errors in the console.
 - Test again with EnhancedMessagingPreferences disabled.

Signed-off-by: Pierre-Marc Thibault <pierre-marc.thibault@inLibro.com>

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 3607fdfe7966b4db8cb69331f097278d09363fd2)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js

index 2bd4df8..e17071b 100644 (file)
@@ -3882,6 +3882,15 @@ span {
     }
 }
 
+
+.form-message {
+    background-color: #FFF;
+    border: 1px solid #A4BEDD;
+    border-radius: 5px;
+    margin: 1em;
+    padding: .5em;
+}
+
 .modal-textarea {
     width: 98%;
 }
index 143af0a..fe33188 100644 (file)
 [% IF ( step_5 ) %][% IF ( EnhancedMessagingPreferences ) %]
   <fieldset class="rows" id="memberentry_messaging_prefs">
     <legend id="patron_messaging_prefs_lgd">Patron messaging preferences</legend>
-    [% IF ( opadd ) %]
-    <!-- handle changing prefs if creating new patron and changing
-         the patron category
-    -->
-    <script type="text/javascript">//<![CDATA[
-       $(document).ready(function(){
-            var message_prefs_dirty = false;
-            $('#memberentry_messaging_prefs > *').change(function() {
-                message_prefs_dirty = true;
-            });
-            $('#categorycode_entry').change(function() {
-                var categorycode = $(this).val();
-                if (message_prefs_dirty) {
-                    if (!confirm(_("Change messaging preferences to default for this category?"))) {
-                        return;
-                    }
-                }
-                $.getJSON('/cgi-bin/koha/members/default_messageprefs.pl?categorycode=' + categorycode,
-                    function(data) {
-                        $.each(data.messaging_preferences, function(i, item) {
-                            var attrid = item.message_attribute_id;
-                            var transports = ['email', 'rss', 'sms'];
-                            $.each(transports, function(j, transport) {
-                                if (item['transports_' + transport] == 1) {
-                                    $('#' + transport + attrid).prop('checked', true);
-                                } else {
-                                    $('#' + transport + attrid).prop('checked', false);
-                                }
-                            });
-                            if (item.digest && item.digest != ' ') {
-                                $('#digest' + attrid).prop('checked', true);
-                            } else {
-                                $('#digest' + attrid).prop('checked', false);
-                            }
-                            if (item.takes_days == '1') {
-                                $('[name=' + attrid + '-DAYS]').val('' + item.days_in_advance);
-                            }
-                        });
-                        message_prefs_dirty = false;
-                    }
-                );
-            });
-        });
-    //]]>
-    </script>
-    [% END %]
+    <div id="messaging_prefs_loading" class="form-message" style="display:none">
+        <img src="[% interface | html %]/[% theme | html %]/img/spinner-small.gif" alt="" /> Loading new messaging defaults
+    </div>
     <input type="hidden" name="setting_messaging_prefs" value="1" />
     [% INCLUDE 'messaging-preference-form.inc' %]
     [% IF ( SMSSendDriver ) %]
         var LABEL_CHANGE = _("Change");
         var LABEL_SET_TO_PATRON = _("Set to patron");
         var LABEL_AGE = _("Age");
+        var MSG_MESSAGING_DFEAULTS = _("Change messaging preferences to default for this category?");
 
         [% IF quickadd && opadd  && !check_member %]
             $(document).ready(function () {
index 67a580b..93f1ce3 100644 (file)
@@ -17,4 +17,52 @@ $(document).ready(function(){
         }
     });
     $("#info_digests").tooltip();
+
+    var message_prefs_dirty = false;
+    $('#memberentry_messaging_prefs > *').change(function() {
+        message_prefs_dirty = true;
+    });
+
+    if( $("#messaging_prefs_loading").length ){ // This element only appears in the template if op=add
+        $('#categorycode_entry').change(function() {
+            var messaging_prefs_loading = $("#messaging_prefs_loading");
+            // Upon selecting a new patron category, show "Loading" message for messaging defaults
+            messaging_prefs_loading.show();
+            var categorycode = $(this).val();
+            if (message_prefs_dirty) {
+                if (!confirm( MSG_MESSAGING_DFEAULTS )) {
+                    // Not loading messaging defaults. Hide loading indicator
+                    messaging_prefs_loading.hide();
+                    return;
+                }
+            }
+            $(".none").prop("checked", false); // When loading default prefs the "Do not notify" boxes should be cleared
+            var jqxhr = $.getJSON('/cgi-bin/koha/members/default_messageprefs.pl?categorycode=' + categorycode, function(data) {
+                $.each(data.messaging_preferences, function(i, item) {
+                    var attrid = item.message_attribute_id;
+                    var transports = ['email', 'rss', 'sms'];
+                    $.each(transports, function(j, transport) {
+                        if (item['transports_' + transport] == 1) {
+                            $('#' + transport + attrid).prop('checked', true);
+                        } else {
+                            $('#' + transport + attrid).prop('checked', false);
+                        }
+                    });
+                    if (item.digest && item.digest != ' ') {
+                        $('#digest' + attrid).prop('checked', true);
+                    } else {
+                        $('#digest' + attrid).prop('checked', false);
+                    }
+                    if (item.takes_days == '1') {
+                        $('[name=' + attrid + '-DAYS]').val('' + item.days_in_advance);
+                    }
+                });
+                message_prefs_dirty = false;
+            })
+                .always(function() {
+                    // Loaded messaging defaults. Hide loading indicator
+                    messaging_prefs_loading.hide();
+                });
+        });
+    }
 });