Bug 30952: Staff interface redesign (header)
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / members-menu.js
1 /* global borrowernumber advsearch dateformat __ CAN_user_borrowers_delete_borrowers CAN_user_borrowers_edit_borrowers number_of_adult_categories destination Sticky Cookies*/
2
3 $(document).ready(function(){
4     searchfield_date_tooltip("");
5     searchfield_date_tooltip('_filter');
6     $("#searchfieldstype").change(function() {
7         searchfield_date_tooltip("");
8     });
9     $("#searchfieldstype_filter").change(function() {
10         searchfield_date_tooltip('_filter');
11     });
12
13     if( CAN_user_borrowers_delete_borrowers ){
14         $("#deletepatron").click(function(){
15             window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber;
16         });
17     }
18     if( CAN_user_borrowers_edit_borrowers ){
19         $("#renewpatron").click(function(){
20             confirm_reregistration();
21             $(".btn-group").removeClass("open");
22             return false;
23         });
24         $("#updatechild").click(function(e){
25             if( $(this).data("toggle") == "tooltip"){ // Disabled menu option has tooltip attribute
26                 e.preventDefault();
27             } else {
28                 update_child();
29                 $(".btn-group").removeClass("open");
30             }
31         });
32     }
33
34     $(".delete_message").click(function(){
35         return window.confirm( __("Are you sure you want to delete this message? This cannot be undone.") );
36     });
37
38     $("#updatechild, #patronflags, #renewpatron, #deletepatron, #exportbarcodes").tooltip();
39     $("#exportcheckins").click(function(){
40         export_barcodes();
41         $(".btn-group").removeClass("open");
42         return false;
43     });
44     $("#printsummary").click(function(){
45         printx_window("page");
46         $(".btn-group").removeClass("open");
47         return false;
48     });
49     $("#printslip").click(function(){
50         printx_window("slip");
51         $(".btn-group").removeClass("open");
52         return false;
53     });
54     $("#printquickslip").click(function(){
55         printx_window("qslip");
56         $(".btn-group").removeClass("open");
57         return false;
58     });
59     $("#print_overdues").click(function(){
60         window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=" + borrowernumber, "printwindow");
61         $(".btn-group").removeClass("open");
62         return false;
63     });
64     $("#printcheckinslip").click(function(){
65         printx_window("checkinslip");
66         $(".btn-group").removeClass("open");
67         return false;
68     });
69     $("#printclearscreen").click(function(){
70         printx_window("slip");
71         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
72     });
73     $("#printclearscreenq").click(function(){
74         printx_window("qslip");
75         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
76     });
77     $("#searchtohold").click(function(){
78         searchToHold();
79         return false;
80     });
81     $("#select_patron_messages").on("change",function(){
82         $("#borrower_message").val( $(this).val() );
83     });
84
85     $("#patronImageEdit").on("shown.bs.modal", function(){
86         startup();
87     });
88
89     $(".edit-patronimage").on("click", function(e){
90         e.preventDefault();
91         var borrowernumber = $(this).data("borrowernumber");
92         var cardnumber = $(this).data("cardnumber");
93         var modalTitle = $(this).attr("title");
94         $("#patronImageEdit .modal-title").text(modalTitle);
95         $("#patronImageEdit").modal("show");
96         $("#patronImageEdit").on("hidden.bs.modal", function(){
97             /* Stop using the user's camera when modal is closed */
98             let viewfinder = document.getElementById("viewfinder");
99             if( viewfinder.srcObject ){
100                 viewfinder.srcObject.getTracks().forEach( track => {
101                     if( track.readyState == 'live' && track.kind === 'video'){
102                         track.stop();
103                     }
104                 });
105             }
106         });
107     });
108 });
109
110 function searchfield_date_tooltip(filter) {
111     var field = "#searchmember" + filter;
112     var type = "#searchfieldstype" + filter;
113     if ( $(type).val() == 'dateofbirth' ) {
114         var MSG_DATE_FORMAT = "";
115         if( dateformat == 'us' ){
116             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'MM/DD/YYYY'");
117         } else if( dateformat == 'iso' ){
118             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'YYYY-MM-DD'");
119         } else if( dateformat == 'metric' ){
120             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD/MM/YYYY'");
121         } else if( dateformat == 'dmydot' ){
122             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD.MM.YYYY'");
123         }
124         $(field).attr("title", MSG_DATE_FORMAT).tooltip('show');
125     } else {
126         $(field).tooltip('destroy');
127     }
128 }
129
130 function confirm_updatechild() {
131     var is_confirmed = window.confirm( __("Are you sure you want to update this child to an Adult category? This cannot be undone.") );
132     if (is_confirmed) {
133         window.location='/cgi-bin/koha/members/update-child.pl?op=update&borrowernumber=' + borrowernumber;
134     }
135 }
136
137 function update_child() {
138     if( number_of_adult_categories > 1 ){
139         window.open('/cgi-bin/koha/members/update-child.pl?op=multi&borrowernumber=' + borrowernumber,'UpdateChild','width=400,height=300,toolbar=no,scrollbars=yes,resizable=yes');
140     } else {
141         confirm_updatechild();
142     }
143 }
144
145 function confirm_reregistration() {
146     var is_confirmed = window.confirm( __("Are you sure you want to renew this patron's registration?") );
147     if (is_confirmed) {
148         window.location = '/cgi-bin/koha/members/setstatus.pl?borrowernumber=' + borrowernumber + '&destination=' + destination + '&reregistration=y';
149     }
150 }
151 function export_barcodes() {
152     window.open('/cgi-bin/koha/members/readingrec.pl?borrowernumber=' + borrowernumber + '&op=export_barcodes');
153 }
154 var slip_re = /slip/;
155 function printx_window(print_type) {
156     var handler = print_type.match(slip_re) ? "printslip" : "summary-print";
157     window.open("/cgi-bin/koha/members/" + handler + ".pl?borrowernumber=" + borrowernumber + "&print=" + print_type, "printwindow");
158     return false;
159 }
160 function searchToHold(){
161     var date = new Date();
162     date.setTime(date.getTime() + (10 * 60 * 1000));
163     Cookies.set("holdfor", borrowernumber, { path: "/", expires: date, sameSite: 'Lax'  });
164     location.href="/cgi-bin/koha/catalogue/search.pl";
165 }