From fa29ec5eda036f51135e4f231ff62b0ebe96cad9 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 29 Jan 2024 14:11:34 +0100 Subject: [PATCH] Bug 31610: Set messaging preferences in the new guarantee form On patron detail page, if the patron is an adult, there is a button "Add guarantee". It takes you to the patron creation form. In this form one of the "can be guarantee" category will be automatically selected, but the messaging preferences will not be automatically set to the default messaging preferences for this category. This patch fixes that. Test plan: 1. Make sure all the "can be guarantee" categories have default messaging preferences. The category dropdown list is not sorted so it's not always the same category that appear first and is automatically selected. Also make sure that preference borrowerRelationship is not empty 2. Find a patron whose category's type is Adult and go to its detail page 3. Click on "Add guarantee" in the toolbar 4. Verify that the messaging preferences are automatically set and match the selected category. --- .../intranet-tmpl/prog/js/messaging-preference-form.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 5fdc5c1917f..8f311fa3532 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js +++ b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js @@ -11,11 +11,14 @@ $(document).ready(function(){ } if( $("#messaging_prefs_loading").length ){ // This element only appears in the template if op=add - $('#categorycode_entry').change(function() { + $('#categorycode_entry').change(() => { update_messaging_prefs() }); + update_messaging_prefs(); + + function update_messaging_prefs () { 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(); + var categorycode = $('#categorycode_entry').val(); if (message_prefs_dirty) { if (!confirm( __("Change messaging preferences to default for this category?") )) { // Not loading messaging defaults. Hide loading indicator @@ -51,7 +54,7 @@ $(document).ready(function(){ // Loaded messaging defaults. Hide loading indicator messaging_prefs_loading.hide(); }); - }); + } } function toggle_digest(id){ -- 2.30.2