Bug 22115: Format prices in table of checkouts according to CurrencyFormat setting
[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     $(".delete_message").click(function(){
51         return window.confirm( __("Are you sure you want to delete this message? This cannot be undone.") );
52     });
53
54     $("#updatechild, #patronflags, #renewpatron, #deletepatron, #exportbarcodes").tooltip();
55     $("#exportcheckins").click(function(){
56         export_barcodes();
57         $(".btn-group").removeClass("open");
58         return false;
59     });
60     $("#printsummary").click(function(){
61         printx_window("page");
62         $(".btn-group").removeClass("open");
63         return false;
64     });
65     $("#printslip").click(function(){
66         printx_window("slip");
67         $(".btn-group").removeClass("open");
68         return false;
69     });
70     $("#printquickslip").click(function(){
71         printx_window("qslip");
72         $(".btn-group").removeClass("open");
73         return false;
74     });
75     $("#print_overdues").click(function(){
76         window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=" + borrowernumber, "printwindow");
77         $(".btn-group").removeClass("open");
78         return false;
79     });
80     $("#printcheckinslip").click(function(){
81         printx_window("checkinslip");
82         $(".btn-group").removeClass("open");
83         return false;
84     });
85     $("#printclearscreen").click(function(){
86         printx_window("slip");
87         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
88     });
89     $("#printclearscreenq").click(function(){
90         printx_window("qslip");
91         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
92     });
93     $("#searchtohold").click(function(){
94         searchToHold();
95         return false;
96     });
97     $("#select_patron_messages").on("change",function(){
98         $("#borrower_message").val( $(this).val() );
99     });
100
101     $("#patronImageEdit").on("shown.bs.modal", function(){
102         startup();
103     });
104
105     $(".edit-patronimage").on("click", function(e){
106         e.preventDefault();
107         var borrowernumber = $(this).data("borrowernumber");
108         var cardnumber = $(this).data("cardnumber");
109         var modalTitle = $(this).attr("title");
110         $("#patronImageEdit .modal-title").text(modalTitle);
111         $("#patronImageEdit").modal("show");
112         $("#patronImageEdit").on("hidden.bs.modal", function(){
113             /* Stop using the user's camera when modal is closed */
114             let viewfinder = document.getElementById("viewfinder");
115             if( viewfinder.srcObject ){
116                 viewfinder.srcObject.getTracks().forEach( track => {
117                     if( track.readyState == 'live' && track.kind === 'video'){
118                         track.stop();
119                     }
120                 });
121             }
122         });
123     });
124 });
125
126 function searchfield_date_tooltip(filter) {
127     var field = "#searchmember" + filter;
128     var type = "#searchfieldstype" + filter;
129     if ( $(type).val() == 'dateofbirth' ) {
130         var MSG_DATE_FORMAT = "";
131         if( dateformat == 'us' ){
132             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'MM/DD/YYYY'");
133         } else if( dateformat == 'iso' ){
134             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'YYYY-MM-DD'");
135         } else if( dateformat == 'metric' ){
136             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD/MM/YYYY'");
137         } else if( dateformat == 'dmydot' ){
138             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD.MM.YYYY'");
139         }
140         $(field).attr("title", MSG_DATE_FORMAT).tooltip('show');
141     } else {
142         $(field).tooltip('destroy');
143     }
144 }
145
146 function confirm_updatechild() {
147     var is_confirmed = window.confirm( __("Are you sure you want to update this child to an Adult category? This cannot be undone.") );
148     if (is_confirmed) {
149         window.location='/cgi-bin/koha/members/update-child.pl?op=update&borrowernumber=' + borrowernumber;
150     }
151 }
152
153 function update_child() {
154     if( number_of_adult_categories > 1 ){
155         window.open('/cgi-bin/koha/members/update-child.pl?op=multi&borrowernumber=' + borrowernumber,'UpdateChild','width=400,height=300,toolbar=no,scrollbars=yes,resizable=yes');
156     } else {
157         confirm_updatechild();
158     }
159 }
160
161 function confirm_reregistration() {
162     var is_confirmed = window.confirm( __("Are you sure you want to renew this patron's registration?") );
163     if (is_confirmed) {
164         window.location = '/cgi-bin/koha/members/setstatus.pl?borrowernumber=' + borrowernumber + '&destination=' + destination + '&reregistration=y';
165     }
166 }
167 function export_barcodes() {
168     window.open('/cgi-bin/koha/members/readingrec.pl?borrowernumber=' + borrowernumber + '&op=export_barcodes');
169 }
170 var slip_re = /slip/;
171 function printx_window(print_type) {
172     var handler = print_type.match(slip_re) ? "printslip" : "summary-print";
173     window.open("/cgi-bin/koha/members/" + handler + ".pl?borrowernumber=" + borrowernumber + "&print=" + print_type, "printwindow");
174     return false;
175 }
176 function searchToHold(){
177     var date = new Date();
178     date.setTime(date.getTime() + (10 * 60 * 1000));
179     Cookies.set("holdfor", borrowernumber, { path: "/", expires: date, sameSite: 'Lax'  });
180     location.href="/cgi-bin/koha/catalogue/search.pl";
181 }