Bug 19878: Move template JavaScript to the footer: UNIMARC editor plugins, part 7
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / audio_alerts.js
blob997c72a41207adfbcef9b249e05872d0de6c5f12
1 $( document ).ready(function() {
2     var checkboxes = $("#delete-alert-form input[type='checkbox']");
3     var checkedcheckboxes = 0;
4     checkboxes.on("change",function(){
5         if( $("#delete-alert-form").find("input:checked").length > 0){
6             checkedcheckboxes = 1;
7             $("#delete-alerts").removeClass("disabled");
8         } else {
9             checkedcheckboxes = 0;
10             $("#delete-alerts").addClass("disabled");
11         }
12     });
14     var soundfield = $("#sound");
15     var playsound = $('#play-sound');
17     soundfield.on("change",function(){
18         enablePlayButton($(this).val(),playsound);
19     });
21     $(".edit-alert").hide();
22     $("#new-alert-form").hide();
24     $("#newalert").on("click",function(e){
25         e.preventDefault();
26         $("#new-alert-form").show();
27         $("#toolbar, #delete-alert-form").hide();
28     });
30     $('#koha-sounds').on('change', function() {
31         soundfield.val( this.value );
32         enablePlayButton($(this).val(),playsound);
33     });
35     playsound.on('click', function(e) {
36         e.preventDefault();
37         if( soundfield.val() !== '' ){
38             playSound( soundfield.val() );
39         } else {
40             alert( MSG_AUDIO_EMPTY_SOUND );
41         }
42     });
44     $('#cancel-edit').on('click', function(e) {
45         e.preventDefault();
47         enablePlayButton("",playsound);
48         $("#id").val("");
49         $("#selector").val("");
50         soundfield.val("");
51         $("#koha-sounds").val("");
53         $("#toolbar").show();
54         $(".edit-alert").hide();
55         $(".create-alert").show();
56         $("#new-alert-form").hide();
57         $("#delete-alert-form").show();
58     });
60     $('#delete-alert-form').on('submit', function() {
61         if( checkedcheckboxes == 1 ){
62             return confirm( MSG_AUDIO_CONFIRM_DELETE );
63         } else {
64             alert( MSG_AUDIO_CHECK_CHECKBOXES );
65             return false;
66         }
67     });
69     $(".edit").on("click",function(e){
70         e.preventDefault();
71         var elt = this;
72         var id = $(this).data("soundid");
73         var precedence = $(this).data("precedence");
74         var selector = $(this).data("selector");
75         var sound = $(this).data("sound");
76         EditAlert( elt, id, precedence, selector, sound );
77     });
78 });
80 function enablePlayButton(sound_field_value,playbutton){
81     if( sound_field_value !== '' ){
82         playbutton.removeClass("disabled");
83     } else {
84         playbutton.addClass("disabled");
85     }
88 function EditAlert( elt, id, precedence, selector, sound ) {
89     $("#new-alert-form").show();
90     $("#delete-alert-form").hide();
91     $("#toolbar").hide();
92     $(".create-alert").hide();
93     $(".edit-alert").show();
94     $("#id").val(id);
95     $("#selector").val(selector);
96     $("#sound").val(sound);
97     $("#koha-sounds").val(sound);
98     enablePlayButton(sound,$('#play-sound'));