Bug 12224: Print a slip of borrower's checkins for today
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / members-menu.js
1 /* global borrowernumber advsearch dateformat __ CAN_user_borrowers_edit_borrowers number_of_adult_categories destination Sticky */
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_edit_borrowers ){
30         $("#deletepatron").click(function(){
31             window.location='/cgi-bin/koha/members/deletemem.pl?member=' + borrowernumber;
32         });
33         $("#renewpatron").click(function(){
34             confirm_reregistration();
35             $(".btn-group").removeClass("open");
36             return false;
37         });
38         $("#updatechild").click(function(e){
39             if( $(this).data("toggle") == "tooltip"){ // Disabled menu option has tooltip attribute
40                 e.preventDefault();
41             } else {
42                 update_child();
43                 $(".btn-group").removeClass("open");
44             }
45         });
46     }
47
48     $("#updatechild, #patronflags, #renewpatron, #deletepatron, #exportbarcodes").tooltip();
49     $("#exportcheckins").click(function(){
50         export_barcodes();
51         $(".btn-group").removeClass("open");
52         return false;
53     });
54     $("#printsummary").click(function(){
55         printx_window("page");
56         $(".btn-group").removeClass("open");
57         return false;
58     });
59     $("#printslip").click(function(){
60         printx_window("slip");
61         $(".btn-group").removeClass("open");
62         return false;
63     });
64     $("#printquickslip").click(function(){
65         printx_window("qslip");
66         $(".btn-group").removeClass("open");
67         return false;
68     });
69     $("#print_overdues").click(function(){
70         window.open("/cgi-bin/koha/members/print_overdues.pl?borrowernumber=" + borrowernumber, "printwindow");
71         $(".btn-group").removeClass("open");
72         return false;
73     });
74     $("#printcheckinslip").click(function(){
75         printx_window("checkinslip");
76         $(".btn-group").removeClass("open");
77         return false;
78     });
79     $("#printclearscreen").click(function(){
80         printx_window("slip");
81         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
82     });
83     $("#searchtohold").click(function(){
84         searchToHold();
85         return false;
86     });
87     $("#select_patron_messages").on("change",function(){
88         $("#borrower_message").val( $(this).val() );
89     });
90
91     $(".edit-patronimage").on("click", function(e){
92         e.preventDefault();
93         var borrowernumber = $(this).data("borrowernumber");
94         $.get("/cgi-bin/koha/members/moremember.pl", { borrowernumber : borrowernumber }, function( data ){
95             var image_form = $(data).find("#picture-upload");
96             image_form.show().find(".cancel").remove();
97             $("#patronImageEdit .modal-body").html( image_form );
98         });
99         var modalTitle = $(this).attr("title");
100         $("#patronImageEdit .modal-title").text(modalTitle);
101         $("#patronImageEdit").modal("show");
102     });
103
104 });
105
106
107
108 function searchfield_date_tooltip(filter) {
109     var field = "#searchmember" + filter;
110     var type = "#searchfieldstype" + filter;
111     if ( $(type).val() == 'dateofbirth' ) {
112         var MSG_DATE_FORMAT = "";
113         if( dateformat == 'us' ){
114             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'MM/DD/YYYY'");
115         } else if( dateformat == 'iso' ){
116             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'YYYY-MM-DD'");
117         } else if( dateformat == 'metric' ){
118             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD/MM/YYYY'");
119         } else if( dateformat == 'dmydot' ){
120             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD.MM.YYYY'");
121         }
122         $(field).attr("title", MSG_DATE_FORMAT).tooltip('show');
123     } else {
124         $(field).tooltip('destroy');
125     }
126 }
127
128 function confirm_updatechild() {
129     var is_confirmed = window.confirm( __("Are you sure you want to update this child to an Adult category? This cannot be undone.") );
130     if (is_confirmed) {
131         window.location='/cgi-bin/koha/members/update-child.pl?op=update&borrowernumber=' + borrowernumber;
132     }
133 }
134
135 function update_child() {
136     if( number_of_adult_categories > 1 ){
137         window.open('/cgi-bin/koha/members/update-child.pl?op=multi&borrowernumber=' + borrowernumber,'UpdateChild','width=400,height=300,toolbar=no,scrollbars=yes,resizable=yes');
138     } else {
139         confirm_updatechild();
140     }
141 }
142
143 function confirm_reregistration() {
144     var is_confirmed = window.confirm( __("Are you sure you want to renew this patron's registration?") );
145     if (is_confirmed) {
146         window.location = '/cgi-bin/koha/members/setstatus.pl?borrowernumber=' + borrowernumber + '&destination=' + destination + '&reregistration=y';
147     }
148 }
149 function export_barcodes() {
150     window.open('/cgi-bin/koha/members/readingrec.pl?borrowernumber=' + borrowernumber + '&op=export_barcodes');
151 }
152 var slip_re = /slip/;
153 function printx_window(print_type) {
154     var handler = print_type.match(slip_re) ? "printslip" : "summary-print";
155     window.open("/cgi-bin/koha/members/" + handler + ".pl?borrowernumber=" + borrowernumber + "&print=" + print_type, "printwindow");
156     return false;
157 }
158 function searchToHold(){
159     var date = new Date();
160     date.setTime(date.getTime() + (10 * 60 * 1000));
161     $.cookie("holdfor", borrowernumber, { path: "/", expires: date });
162     location.href="/cgi-bin/koha/catalogue/search.pl";
163 }