Bug 18729: Add PUT /holds/{hold_id}/pickup_location
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / audio_alerts.js
1 /* global __ */
2
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     });
15
16     var soundfield = $("#sound");
17     var playsound = $('#play-sound');
18
19     soundfield.on("change",function(){
20         enablePlayButton($(this).val(),playsound);
21     });
22
23     $(".edit-alert").hide();
24     $("#new-alert-form").hide();
25
26     $("#newalert").on("click",function(e){
27         e.preventDefault();
28         $("#new-alert-form").show();
29         $("#toolbar, #delete-alert-form").hide();
30     });
31
32     $('#koha-sounds').on('change', function() {
33         soundfield.val( this.value );
34         enablePlayButton($(this).val(),playsound);
35     });
36
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     });
45
46     $('#cancel-edit').on('click', function(e) {
47         e.preventDefault();
48
49         enablePlayButton("",playsound);
50         $("#id").val("");
51         $("#selector").val("");
52         soundfield.val("");
53         $("#koha-sounds").val("");
54
55         $("#toolbar").show();
56         $(".edit-alert").hide();
57         $(".create-alert").show();
58         $("#new-alert-form").hide();
59         $("#delete-alert-form").show();
60     });
61
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     });
70
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 });
81
82 function enablePlayButton(sound_field_value,playbutton){
83     if( sound_field_value !== '' ){
84         playbutton.removeClass("disabled");
85     } else {
86         playbutton.addClass("disabled");
87     }
88 }
89
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'));
101 }