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