From d146eea5c6f4bc6bff51b3415a50a1ced7e16cc7 Mon Sep 17 00:00:00 2001 From: Sam Lau Date: Wed, 3 Jul 2024 21:49:13 +0000 Subject: [PATCH] Bug 31354: Use modal popup for messaging preferences when editing a patron's category. To test: 1) In Administration->Patron categories, edit the 'Home Bound' category and select every messaging preferences. 2) Edit the 'Patron' category and select email for the 'Item due' messaging pref. 3) Visit a patrons page from any category except Homebound. Keep note of their messaging preferences (will probably just be none) 4) Edit this patron and change their category to 'Homebound'. You should be greeted with a modal that asks if you want to "Change messaging preferences to default for this category?". Select yes. Save changes on the edit form 5) In the details page, note the messaging preferences were set to the defualt for the Homebound category (all selected) 6) Edit patron again, this time change their category to 'Patron'. 7) When the modal pops up, select no. Save the edit form. 8) In details page, the messaging prefs should not have changed. Signed-off-by: David Nind --- .../prog/en/modules/members/memberentrygen.tt | 20 ++++++ .../prog/js/messaging-preference-form.js | 65 ++++++++++--------- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index 6877ef453f..395f13aa93 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1752,6 +1752,26 @@ legend.collapsed i.fa.fa-caret-down::before { [% END %] + + + + [% MACRO jsinclude BLOCK %] [% Asset.js("lib/hc-sticky/hc-sticky.js") | $raw %] [% INCLUDE 'calendar.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js index 5fdc5c1917..362f88f3e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js +++ b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js @@ -17,40 +17,45 @@ $(document).ready(function(){ messaging_prefs_loading.show(); var categorycode = $(this).val(); if (message_prefs_dirty) { - if (!confirm( __("Change messaging preferences to default for this category?") )) { - // Not loading messaging defaults. Hide loading indicator - messaging_prefs_loading.hide(); - return; - } + $('#messagePreferencesModal').modal('show'); + // Handle confirmation Yes button click + $('#messagePreferencesConfirmBtn').on('click', function() { + loadMessagingDefaults(categorycode, messaging_prefs_loading); + $('#messagePreferencesModal').modal('hide'); + }); } - 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); - toggle_digest(attrid); - } else { - $('#' + transport + attrid).prop('checked', false); - toggle_digest(attrid); - } - }); - if (item.digest && item.digest != ' ') { - $('#digest' + attrid).prop('checked', true); + }); + } + + // Function to load messaging defaults from server + function loadMessagingDefaults(categorycode, loadingIndicator) { + 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); + toggle_digest(attrid); } else { - $('#digest' + attrid).prop('checked', false); + $('#' + transport + attrid).prop('checked', false); + toggle_digest(attrid); } - 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(); }); + 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() { + // Hide loading indicator after processing + loadingIndicator.hide(); }); } -- 2.39.2