Bug 16301 - Remove the use of "onclick" from SMS cellular providers template
[koha-ffzg.git] / koha-tmpl / intranet-tmpl / prog / js / sms_providers.js
1 $(document).ready(function() {
2     $('#submit_update').hide();
3     $("#name").focus();
4     $("#sms_add_form").hide();
5     $("#new_provider").on("click",function(){
6         add_provider();
7     });
8     $(".edit").on("click",function(e){
9         e.preventDefault();
10         var providerid = $(this).data("providerid");
11         edit_provider( providerid );
12     });
13     $(".delete").on("click",function(e){
14         e.preventDefault();
15         var providerid = $(this).data("providerid");
16         var patrons_using = $(this).data("patrons_using");
17         if( patrons_using !== "" ){
18             delete_provider( providerid, patrons_using );
19         } else {
20             delete_provider( providerid );
21         }
22     });
23 });
24
25 function clear_form(){
26     $("#id,#name,#domain").val("");
27 }
28
29 function add_provider(){
30     clear_form();
31     $(".dialog").hide();
32     $("legend").text( LABEL_SMS_ADD_PROVIDER );
33     $("#toolbar,#submit_update,#providerst").hide();
34     $("#sms_add_form,#submit_save").show();
35     $("#name").focus();
36 }
37
38 function edit_provider( id ) {
39     clear_form();
40     $("legend").text( LABEL_SMS_EDIT_PROVIDER.format( $("#name_" + id).text() ) );
41     $("#sms_add_form,#submit_update").show();
42
43     $("#id").val( id );
44     $("#name").val( $("#name_" + id).text() );
45     $("#domain").val( $("#domain_" + id).text() );
46
47     $("#toolbar,#submit_save,#providerst").hide();
48
49     $("#name").focus();
50 }
51
52
53 function cancel_edit() {
54     clear_form();
55     $(".dialog").show();
56     $("#sms_add_form,#submit_update").hide();
57     $("#toolbar,#submit_save,#providerst").show();
58 }
59
60 function delete_provider( id, users ) {
61     var c;
62     if ( users ) {
63         c = confirm( MSG_SMS_PATRONS_USING.format( $("#name_" + id).html(), users ) );
64     } else {
65         c = confirm( MSG_SMS_DELETE_CONFIRM.format( $("#name_" + id).html() ) );
66     }
67
68     if ( c ) {
69         $("#op").val('delete');
70         $("#id").val( id );
71         $("#sms_form").submit();
72     }
73 }