Bug 26225: Move translatable strings out of audio_alerts.tt and into audio_alerts.js
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / audio_alerts.js
blob0fa22dc4306fd2a1cf74a1a71fb1ac8d96fe91a2
1 /* global __ */
3 $( document ).ready(function() {
4     var checkboxes = $("#delete-alert-form input[type='checkbox']");
5     var checkedcheckboxes = 0;
6     checkboxes.on("change",function(){
7         if( $("#delete-alert-form").find("input:checked").length > 0){
8             checkedcheckboxes = 1;
9             $("#delete-alerts").removeClass("disabled");
10         } else {
11             checkedcheckboxes = 0;
12             $("#delete-alerts").addClass("disabled");
13         }
14     });
16     var soundfield = $("#sound");
17     var playsound = $('#play-sound');
19     soundfield.on("change",function(){
20         enablePlayButton($(this).val(),playsound);
21     });
23     $(".edit-alert").hide();
24     $("#new-alert-form").hide();
26     $("#newalert").on("click",function(e){
27         e.preventDefault();
28         $("#new-alert-form").show();
29         $("#toolbar, #delete-alert-form").hide();
30     });
32     $('#koha-sounds').on('change', function() {
33         soundfield.val( this.value );
34         enablePlayButton($(this).val(),playsound);
35     });
37     playsound.on('click', function(e) {
38         e.preventDefault();
39         if( soundfield.val() !== '' ){
40             playSound( soundfield.val() );
41         } else {
42             alert( __("Please select or enter a sound.") );
43         }
44     });
46     $('#cancel-edit').on('click', function(e) {
47         e.preventDefault();
49         enablePlayButton("",playsound);
50         $("#id").val("");
51         $("#selector").val("");
52         soundfield.val("");
53         $("#koha-sounds").val("");
55         $("#toolbar").show();
56         $(".edit-alert").hide();
57         $(".create-alert").show();
58         $("#new-alert-form").hide();
59         $("#delete-alert-form").show();
60     });
62     $('#delete-alert-form').on('submit', function() {
63         if( checkedcheckboxes == 1 ){
64             return confirm( __("Are you sure you want to delete the selected audio alerts?") );
65         } else {
66             alert( __("Check the box next to the alert you want to delete.") );
67             return false;
68         }
69     });
71     $(".edit").on("click",function(e){
72         e.preventDefault();
73         var elt = this;
74         var id = $(this).data("soundid");
75         var precedence = $(this).data("precedence");
76         var selector = $(this).data("selector");
77         var sound = $(this).data("sound");
78         EditAlert( elt, id, precedence, selector, sound );
79     });
80 });
82 function enablePlayButton(sound_field_value,playbutton){
83     if( sound_field_value !== '' ){
84         playbutton.removeClass("disabled");
85     } else {
86         playbutton.addClass("disabled");
87     }
90 function EditAlert( elt, id, precedence, selector, sound ) {
91     $("#new-alert-form").show();
92     $("#delete-alert-form").hide();
93     $("#toolbar").hide();
94     $(".create-alert").hide();
95     $(".edit-alert").show();
96     $("#id").val(id);
97     $("#selector").val(selector);
98     $("#sound").val(sound);
99     $("#koha-sounds").val(sound);
100     enablePlayButton(sound,$('#play-sound'));