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