From 4d9f262a3292352d91a03b60d60c5081a5aeb13a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 10 May 2021 11:52:12 +0200 Subject: [PATCH] Bug 13613: Move similar JS code to a function Signed-off-by: Jonathan Druart (cherry picked from commit ac1fd207aec54b4a0da1f6aa00a3f4f4d0752f07) Signed-off-by: Fridolin Somers --- .../prog/js/messaging-preference-form.js | 26 +++++------------ .../bootstrap/en/modules/opac-messaging.tt | 29 +++++++------------ 2 files changed, 18 insertions(+), 37 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 716019b8a0..3babbbd1f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js +++ b/koha-tmpl/intranet-tmpl/prog/js/messaging-preference-form.js @@ -48,35 +48,25 @@ $(document).ready(function(){ }); } - // At load time, we want digest disabled if no digest using transport is enabled - $(".pmp_email").each(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("email","")); + function toggle_digest(id){ if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { $("#digest"+id).attr("disabled", false).tooltip('disable'); } else { $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); } + + } + // At load time, we want digest disabled if no digest using transport is enabled + $(".pmp_email").each(function(){ + toggle_digest(Number($(this).attr("id").replace("email", ""))); }); // If user clears all digest using transports for a notice, disable digest checkbox $(".pmp_email").click(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("email","")); - if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { - $("#digest"+id).attr("disabled", false).tooltip('disable'); - } else { - $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); - } + toggle_digest(Number($(this).attr("id").replace("email", ""))); }); $(".pmp_sms").click(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("sms","")); - if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { - $("#digest"+id).attr("disabled", false).tooltip('disable'); - } else { - $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); - } + toggle_digest(Number($(this).attr("id").replace("sms", ""))); }); // $('#memberentry_messaging_prefs [data-toggle="tooltip"][disabled]').tooltip(); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt index 568e303da2..e24860dc6d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt @@ -249,36 +249,27 @@ $(document).ready(function(){ $("#info_digests").tooltip(); - // At load time, we want digest disabled if no digest using transport is enabled - $(".pmp_email").each(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("email","")); + function toggle_digest(id){ if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { $("#digest"+id).attr("disabled", false).tooltip('disable'); } else { - $("#digest"+id).attr("disabled", true).tooltip('enable'); + $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); } + + } + // At load time, we want digest disabled if no digest using transport is enabled + $(".pmp_email").each(function(){ + toggle_digest(Number($(this).attr("id").replace("email", ""))); }); // If user clears all digest using transports for a notice, disable digest checkbox $(".pmp_email").click(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("email","")); - if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { - $("#digest"+id).attr("disabled", false).tooltip('disable'); - } else { - $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); - } + toggle_digest(Number($(this).attr("id").replace("email", ""))); }); $(".pmp_sms").click(function(){ - var rowid = $(this).attr("id"); - id = Number(rowid.replace("sms","")); - if ( $("#email"+id).prop("checked") || $("#sms"+id).prop("checked") ) { - $("#digest"+id).attr("disabled", false).tooltip('disable'); - } else { - $("#digest"+id).attr("disabled", true).prop("checked",false).tooltip('enable'); - } + toggle_digest(Number($(this).attr("id").replace("sms", ""))); }); + }); function normalizeSMS(value){ -- 2.39.5