]> git.koha-community.org Git - koha.git/blob - koha-tmpl/intranet-tmpl/prog/js/audio_alerts.js
Bug 16429 - Going to circulation from notice triggers may change logged in branch
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / audio_alerts.js
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     });
13
14     var soundfield = $("#sound");
15     var playsound = $('#play-sound');
16
17     soundfield.on("change",function(){
18         enablePlayButton($(this).val(),playsound);
19     });
20
21     $(".edit-alert").hide();
22     $("#new-alert-form").hide();
23
24     $("#newalert").on("click",function(e){
25         e.preventDefault();
26         $("#new-alert-form").show();
27         $("#toolbar, #delete-alert-form").hide();
28     });
29
30     $('#koha-sounds').on('change', function() {
31         soundfield.val( this.value );
32         enablePlayButton($(this).val(),playsound);
33     });
34
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     });
43
44     $('#cancel-edit').on('click', function(e) {
45         e.preventDefault();
46
47         enablePlayButton("",playsound);
48         $("#id").val("");
49         $("#selector").val("");
50         soundfield.val("");
51         $("#koha-sounds").val("");
52
53         $("#toolbar").show();
54         $(".edit-alert").hide();
55         $(".create-alert").show();
56         $("#new-alert-form").hide();
57         $("#delete-alert-form").show();
58     });
59
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     });
68 });
69
70 function enablePlayButton(sound_field_value,playbutton){
71     if( sound_field_value !== '' ){
72         playbutton.removeClass("disabled");
73     } else {
74         playbutton.addClass("disabled");
75     }
76 }
77
78 function EditAlert( elt, id, precedence, selector, sound ) {
79     $("#new-alert-form").show();
80     $("#delete-alert-form").hide();
81     $("#toolbar").hide();
82     $(".create-alert").hide();
83     $(".edit-alert").show();
84     $("#id").val(id);
85     $("#selector").val(selector);
86     $("#sound").val(sound);
87     $("#koha-sounds").val(sound);
88     enablePlayButton(sound,$('#play-sound'));
89 }