Bug 13613: Move similar JS code to a function

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2021-05-10 11:52:12 +02:00
parent 5d176758fe
commit ac1fd207ae
2 changed files with 18 additions and 37 deletions

View File

@ -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();

View File

@ -250,36 +250,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){