Bug 19641: Move patron templates to the footer
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / members-menu.js
1 /* global borrowernumber advsearch dateformat _ CAN_user_borrowers_edit_borrowers NorwegianPatronDBEnable CATCODE_MULTI catcode 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         if( NorwegianPatronDBEnable == 1 ){
35             $("#deletepatronlocal").click(function(){
36                 confirm_local_deletion();
37                 $(".btn-group").removeClass("open");
38                 return false;
39             });
40             $("#deletepatronremote").click(function(){
41                 confirm_remote_deletion();
42                 $(".btn-group").removeClass("open");
43                 return false;
44             });
45             $("#deletepatronboth").click(function(){
46                 confirm_both_deletion();
47                 $(".btn-group").removeClass("open");
48                 return false;
49             });
50         } else {
51             $("#deletepatron").click(function(){
52                 window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber;
53             });
54         }
55         $("#renewpatron").click(function(){
56             confirm_reregistration();
57             $(".btn-group").removeClass("open");
58             return false;
59         });
60         $("#updatechild").click(function(){
61             update_child();
62             $(".btn-group").removeClass("open");
63         });
64     }
65
66     $("#updatechild, #patronflags, #renewpatron, #deletepatron, #exportbarcodes").tooltip();
67     $("#exportcheckins").click(function(){
68         export_barcodes();
69         $(".btn-group").removeClass("open");
70         return false;
71     });
72     $("#printsummary").click(function(){
73         printx_window("page");
74         $(".btn-group").removeClass("open");
75         return false;
76     });
77     $("#printslip").click(function(){
78         printx_window("slip");
79         $(".btn-group").removeClass("open");
80         return false;
81     });
82     $("#printquickslip").click(function(){
83         printx_window("qslip");
84         $(".btn-group").removeClass("open");
85         return false;
86     });
87     $("#print_overdues").click(function(){
88         window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=" + borrowernumber, "printwindow");
89         $(".btn-group").removeClass("open");
90         return false;
91     });
92     $("#searchtohold").click(function(){
93         searchToHold();
94         return false;
95     });
96     $("#select_patron_messages").on("change",function(){
97         $("#borrower_message").val( $(this).val() );
98     });
99 });
100 function confirm_local_deletion() {
101     var is_confirmed = window.confirm(_("Are you sure you want to delete this patron from the local database? This cannot be undone."));
102     if (is_confirmed) {
103         window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=true&deleteremote=false';
104     }
105 }
106 function confirm_remote_deletion() {
107     var is_confirmed = window.confirm(_("Are you sure you want to delete this patron from the Norwegian national patron database? This cannot be undone."));
108     if (is_confirmed) {
109         window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=false&deleteremote=true';
110     }
111 }
112 function confirm_both_deletion() {
113     var is_confirmed = window.confirm(_("Are you sure you want to delete this patron both from the local database and from the Norwegian national patron database? This cannot be undone."));
114     if (is_confirmed) {
115         window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber + '&deletelocal=true&deleteremote=true';
116     }
117 }
118
119 function confirm_updatechild() {
120     var is_confirmed = window.confirm(_("Are you sure you want to update this child to an Adult category?  This cannot be undone."));
121     if (is_confirmed) {
122         window.location='/cgi-bin/koha/members/update-child.pl?op=update&borrowernumber=' + borrowernumber + '&catcode=' + catcode + '&catcode_multi=' + CATCODE_MULTI;
123     }
124 }
125
126 function update_child() {
127     if( CATCODE_MULTI ){
128         window.open('/cgi-bin/koha/members/update-child.pl?op=multi&borrowernumber=' + borrowernumber,'UpdateChild','width=400,height=300,toolbar=no,scrollbars=yes,resizable=yes');
129     } else {
130         confirm_updatechild();
131     }
132 }
133
134 function confirm_reregistration() {
135     var is_confirmed = window.confirm(_("Are you sure you want to renew this patron's registration?"));
136     if (is_confirmed) {
137         window.location = '/cgi-bin/koha/members/setstatus.pl?borrowernumber=' + borrowernumber + '&destination=' + destination + '&reregistration=y';
138     }
139 }
140 function export_barcodes() {
141     window.open('/cgi-bin/koha/members/readingrec.pl?borrowernumber=' + borrowernumber + '&op=export_barcodes');
142 }
143 var slip_re = /slip/;
144 function printx_window(print_type) {
145     var handler = print_type.match(slip_re) ? "printslip" : "summary-print";
146     window.open("/cgi-bin/koha/members/" + handler + ".pl?borrowernumber=" + borrowernumber + "&print=" + print_type, "printwindow");
147     return false;
148 }
149 function searchToHold(){
150     var date = new Date();
151     date.setTime(date.getTime() + (10 * 60 * 1000));
152     $.cookie("holdfor", borrowernumber, { path: "/", expires: date });
153     location.href="/cgi-bin/koha/catalogue/search.pl";
154 }