Bug 32618: Add 'page-section' to various administration pages
[koha.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     $(".cancel_edit").on("click",function(e){
24         e.preventDefault();
25         cancel_edit();
26     });
27 });
28
29 function clear_form(){
30     $("#id,#name,#domain").val("");
31 }
32
33 function add_provider(){
34     clear_form();
35     $(".dialog").hide();
36     $("legend").text( __("Add an SMS cellular provider") );
37     $("#toolbar,#submit_update,#providers").hide();
38     $("#sms_add_form,#submit_save").show();
39     $("#name").focus();
40 }
41
42 function edit_provider( id ) {
43     clear_form();
44     $("legend").text( __("Edit provider %s").format($("#name_" + id).text()) );
45     $("#sms_add_form,#submit_update").show();
46
47     $("#id").val( id );
48     $("#name").val( $("#name_" + id).text() );
49     $("#domain").val( $("#domain_" + id).text() );
50
51     $("#toolbar,#submit_save,#providers").hide();
52
53     $("#name").focus();
54 }
55
56
57 function cancel_edit() {
58     clear_form();
59     $(".dialog").show();
60     $("#sms_add_form,#submit_update").hide();
61     $("#toolbar,#submit_save,#providers").show();
62 }
63
64 function delete_provider( id, users ) {
65     var c;
66     if ( users ) {
67         c = confirm( __("Are you sure you want to delete %s? %s patron(s) are using it!").format($("#name_" + id).html(), users) );
68     } else {
69         c = confirm( __("Are you sure you want to delete %s?").format($("#name_" + id).html()) );
70     }
71
72     if ( c ) {
73         $("#op").val('delete');
74         $("#id").val( id );
75         $("#sms_form").submit();
76     }
77 }