From b624cc99287a86c275671118def8a116ceaabd07 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 9 Feb 2024 16:08:49 +0000 Subject: [PATCH] Bug 34478: Manual fix - audio alerts Signed-off-by: Jonathan Druart --- admin/audio_alerts.pl | 29 ++-- .../prog/en/modules/admin/audio_alerts.tt | 127 +++++++++++------- .../intranet-tmpl/prog/js/audio_alerts.js | 57 ++++---- 3 files changed, 126 insertions(+), 87 deletions(-) diff --git a/admin/audio_alerts.pl b/admin/audio_alerts.pl index 9dad284db4..01d3f4d4ce 100755 --- a/admin/audio_alerts.pl +++ b/admin/audio_alerts.pl @@ -27,37 +27,36 @@ use Koha::AudioAlerts; my $cgi = CGI->new; +my $op = $cgi->param('op') || q{}; my $selector = $cgi->param('selector'); my $sound = $cgi->param('sound'); my $id = $cgi->param('id'); -my $action = $cgi->param('action'); my $where = $cgi->param('where'); -my @delete = $cgi->multi_param('cud-delete'); +my @delete = $cgi->multi_param('delete'); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "admin/audio_alerts.tt", - query => $cgi, - type => "intranet", - flagsrequired => { parameters => 'manage_audio_alerts' }, + template_name => "admin/audio_alerts.tt", + query => $cgi, + type => "intranet", + flagsrequired => { parameters => 'manage_audio_alerts' }, } ); -if ( $id && $action && $where && $action eq 'move' ) { +if ( $op eq 'cud-move' && $id && $where ) { Koha::AudioAlerts->find($id)->move($where); -} -elsif ( $id && $selector && $sound ) { +} elsif ( $op eq 'cud-edit' && $id && $selector && $sound ) { my $alert = Koha::AudioAlerts->find($id); - $alert->selector( $selector ); - $alert->sound( $sound ); + $alert->selector($selector); + $alert->sound($sound); $alert->store(); -} -elsif ( $selector && $sound ) { +} elsif ( $op eq 'cud-add' && $selector && $sound ) { Koha::AudioAlert->new( { selector => $selector, sound => $sound } )->store(); } -if (@delete) { - map { Koha::AudioAlerts->find($_)->delete() } @delete; +if ( $op eq 'cud-delete' ) { + @delete = grep { $_ } @delete; + Koha::AudioAlerts->search( { id => { -in => [@delete] } } )->delete(); Koha::AudioAlerts->fix_precedences(); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/audio_alerts.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/audio_alerts.tt index afed6a17db..def223a152 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/audio_alerts.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/audio_alerts.tt @@ -84,70 +84,99 @@
+ Cancel
-
- [% INCLUDE 'csrf-token.inc' %] -

Audio alerts

- [%IF !( Koha.Preference('AudioAlerts') ) %] -
-

Audio alerts are disabled

- [% IF ( CAN_user_parameters_manage_sysprefs ) %] -

Please enable system preference AudioAlerts to activate sounds.

- [% ELSE %] -

The system preference AudioAlerts must be enabled to activate sounds.

- [% END %] -
- [% END %] -
- - - - - - - - - - - +

Audio alerts

+ [%IF !( Koha.Preference('AudioAlerts') ) %] +
+

Audio alerts are disabled

+ [% IF ( CAN_user_parameters_manage_sysprefs ) %] +

Please enable system preference AudioAlerts to activate sounds.

+ [% ELSE %] +

The system preference AudioAlerts must be enabled to activate sounds.

+ [% END %] +
+ [% END %] +
+
 PrecedenceChange orderSelectorSound 
+ + + + + + + + + + - - [% FOREACH a IN audio_alerts %] - - - - + [% FOREACH a IN audio_alerts %] + + + + - - - - - [% END %] - -
 PrecedenceChange orderSelectorSound 
[% a.precedence | html %] - +
[% a.precedence | html %] + + [% INCLUDE 'csrf-token.inc' %] + + + + + - +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
- +
+ [% INCLUDE 'csrf-token.inc' %] + + + + +
- +
+ [% INCLUDE 'csrf-token.inc' %] + + + +
[% a.selector | html %][% a.sound | html %] - Edit
-
+ + + + [% a.selector | html %] + [% a.sound | html %] + + Edit + + [% END %] + + + +
+ [% INCLUDE 'csrf-token.inc' %] + [% FOREACH a IN audio_alerts %] + + [% END %]
+
diff --git a/koha-tmpl/intranet-tmpl/prog/js/audio_alerts.js b/koha-tmpl/intranet-tmpl/prog/js/audio_alerts.js index 7c27fd45e6..7ec084ee00 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/audio_alerts.js +++ b/koha-tmpl/intranet-tmpl/prog/js/audio_alerts.js @@ -1,54 +1,63 @@ /* global __ */ -$( document ).ready(function() { - var checkboxes = $("#delete-alert-form input[type='checkbox']"); +$(document).ready(function() { + var checkboxes = $(".del-checkbox"); var checkedcheckboxes = 0; - checkboxes.on("change",function(){ - if( $("#delete-alert-form").find("input:checked").length > 0){ + checkboxes.on("change", function() { + if ($(".del-checkbox:checked").length > 0) { checkedcheckboxes = 1; $("#delete-alerts").removeClass("disabled"); } else { checkedcheckboxes = 0; $("#delete-alerts").addClass("disabled"); } + + const id = $(this).val(); + const checked = this.checked; + if (checked) { + $(`#del-hidden-${id}`).val(id); + } else { + $(`#del-hidden-${id}`).val(""); + } }); var soundfield = $("#sound"); var playsound = $('#play-sound'); - soundfield.on("change",function(){ - enablePlayButton($(this).val(),playsound); + soundfield.on("change", function() { + enablePlayButton($(this).val(), playsound); }); $(".edit-alert").hide(); $("#new-alert-form").hide(); - $("#newalert").on("click",function(e){ + $("#newalert").on("click", function(e) { e.preventDefault(); - $("#new-alert-form").show( 0, function(){ + $("#new-alert-form").show(0, function() { $("#selector").focus(); }); $("#toolbar, #delete-alert-form").hide(); + $("#op-add-edit").val('cud-add'); }); $('#koha-sounds').on('change', function() { - soundfield.val( this.value ); - enablePlayButton($(this).val(),playsound); + soundfield.val(this.value); + enablePlayButton($(this).val(), playsound); }); playsound.on('click', function(e) { e.preventDefault(); - if( soundfield.val() !== '' ){ - playSound( soundfield.val() ); + if (soundfield.val() !== '') { + playSound(soundfield.val()); } else { - alert( __("Please select or enter a sound.") ); + alert(__("Please select or enter a sound.")); } }); $('#cancel-edit').on('click', function(e) { e.preventDefault(); - enablePlayButton("",playsound); + enablePlayButton("", playsound); $("#id").val(""); $("#selector").val(""); soundfield.val(""); @@ -59,37 +68,39 @@ $( document ).ready(function() { $(".create-alert").show(); $("#new-alert-form").hide(); $("#delete-alert-form").show(); + $("#op-add-edit").val('cud-add'); }); $('#delete-alert-form').on('submit', function() { - if( checkedcheckboxes == 1 ){ - return confirm( __("Are you sure you want to delete the selected audio alerts?") ); + if (checkedcheckboxes == 1) { + return confirm(__("Are you sure you want to delete the selected audio alerts?")); } else { - alert( __("Check the box next to the alert you want to delete.") ); + alert(__("Check the box next to the alert you want to delete.")); return false; } }); - $(".edit").on("click",function(e){ + $(".edit").on("click", function(e) { e.preventDefault(); var elt = this; var id = $(this).data("soundid"); var precedence = $(this).data("precedence"); var selector = $(this).data("selector"); var sound = $(this).data("sound"); - EditAlert( elt, id, precedence, selector, sound ); + EditAlert(elt, id, precedence, selector, sound); }); }); -function enablePlayButton(sound_field_value,playbutton){ - if( sound_field_value !== '' ){ +function enablePlayButton(sound_field_value, playbutton) { + if (sound_field_value !== '') { playbutton.removeClass("disabled"); } else { playbutton.addClass("disabled"); } } -function EditAlert( elt, id, precedence, selector, sound ) { +function EditAlert(elt, id, precedence, selector, sound) { + $("#op-add-edit").val('cud-edit'); $("#new-alert-form").show(); $("#delete-alert-form").hide(); $("#toolbar").hide(); @@ -99,5 +110,5 @@ function EditAlert( elt, id, precedence, selector, sound ) { $("#selector").val(selector); $("#sound").val(sound); $("#koha-sounds").val(sound); - enablePlayButton(sound,$('#play-sound')); + enablePlayButton(sound, $('#play-sound')); } -- 2.39.5