Bug 21333: (follow-up) Make link a button
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / members-menu.js
1 /* global borrowernumber advsearch dateformat _ CAN_user_borrowers_edit_borrowers number_of_adult_categories destination */
2
3 $(document).ready(function(){
4     $("#filteraction_off, #filteraction_on").on('click', function(e) {
5         e.preventDefault();
6         $('#filters').toggle();
7         $('.filteraction').toggle();
8     });
9     if( advsearch ){
10         $("#filteraction_on").toggle();
11         $("#filters").show();
12     } else {
13         $("#filteraction_off").toggle();
14     }
15     $("#searchfieldstype").change(function() {
16         var MSG_DATE_FORMAT = "";
17         if ( $(this).val() == 'dateofbirth' ) {
18             if( dateformat == 'us' ){
19                 MSG_DATE_FORMAT = _("Dates of birth should be entered in the format 'MM/DD/YYYY'");
20             } else if( dateformat == 'iso' ){
21                 MSG_DATE_FORMAT = _("Dates of birth should be entered in the format 'YYYY-MM-DD'");
22             } else if( dateformat == 'metric' ){
23                 MSG_DATE_FORMAT = _("Dates of birth should be entered in the format 'DD/MM/YYYY'");
24             } else if( dateformat == 'dmydot' ){
25                 MSG_DATE_FORMAT = _("Dates of birth should be entered in the format 'DD.MM.YYYY'");
26             }
27             $('#searchmember').attr("title", MSG_DATE_FORMAT).tooltip('show');
28         } else {
29             $('#searchmember').tooltip('destroy');
30         }
31     });
32
33     if( CAN_user_borrowers_edit_borrowers ){
34         $("#deletepatron").click(function(){
35             window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber;
36         });
37         $("#renewpatron").click(function(){
38             confirm_reregistration();
39             $(".btn-group").removeClass("open");
40             return false;
41         });
42         $("#updatechild").click(function(e){
43             if( $(this).data("toggle") == "tooltip"){ // Disabled menu option has tooltip attribute
44                 e.preventDefault();
45             } else {
46                 update_child();
47                 $(".btn-group").removeClass("open");
48             }
49         });
50     }
51
52     $("#updatechild, #patronflags, #renewpatron, #deletepatron, #exportbarcodes").tooltip();
53     $("#exportcheckins").click(function(){
54         export_barcodes();
55         $(".btn-group").removeClass("open");
56         return false;
57     });
58     $("#printsummary").click(function(){
59         printx_window("page");
60         $(".btn-group").removeClass("open");
61         return false;
62     });
63     $("#printslip").click(function(){
64         printx_window("slip");
65         $(".btn-group").removeClass("open");
66         return false;
67     });
68     $("#printquickslip").click(function(){
69         printx_window("qslip");
70         $(".btn-group").removeClass("open");
71         return false;
72     });
73     $("#print_overdues").click(function(){
74         window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=" + borrowernumber, "printwindow");
75         $(".btn-group").removeClass("open");
76         return false;
77     });
78     $("#searchtohold").click(function(){
79         searchToHold();
80         return false;
81     });
82     $("#select_patron_messages").on("change",function(){
83         $("#borrower_message").val( $(this).val() );
84     });
85 });
86
87 function confirm_updatechild() {
88     var is_confirmed = window.confirm(_("Are you sure you want to update this child to an Adult category?  This cannot be undone."));
89     if (is_confirmed) {
90         window.location='/cgi-bin/koha/members/update-child.pl?op=update&borrowernumber=' + borrowernumber;
91     }
92 }
93
94 function update_child() {
95     if( number_of_adult_categories > 1 ){
96         window.open('/cgi-bin/koha/members/update-child.pl?op=multi&borrowernumber=' + borrowernumber,'UpdateChild','width=400,height=300,toolbar=no,scrollbars=yes,resizable=yes');
97     } else {
98         confirm_updatechild();
99     }
100 }
101
102 function confirm_reregistration() {
103     var is_confirmed = window.confirm(_("Are you sure you want to renew this patron's registration?"));
104     if (is_confirmed) {
105         window.location = '/cgi-bin/koha/members/setstatus.pl?borrowernumber=' + borrowernumber + '&destination=' + destination + '&reregistration=y';
106     }
107 }
108 function export_barcodes() {
109     window.open('/cgi-bin/koha/members/readingrec.pl?borrowernumber=' + borrowernumber + '&op=export_barcodes');
110 }
111 var slip_re = /slip/;
112 function printx_window(print_type) {
113     var handler = print_type.match(slip_re) ? "printslip" : "summary-print";
114     window.open("/cgi-bin/koha/members/" + handler + ".pl?borrowernumber=" + borrowernumber + "&print=" + print_type, "printwindow");
115     return false;
116 }
117 function searchToHold(){
118     var date = new Date();
119     date.setTime(date.getTime() + (10 * 60 * 1000));
120     $.cookie("holdfor", borrowernumber, { path: "/", expires: date });
121     location.href="/cgi-bin/koha/catalogue/search.pl";
122 }