Bug 26334: Move translatable strings out of members-menu.inc into members-menu.js
[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     $("#printclearscreen").click(function(){
75         printx_window("slip");
76         window.location.replace("/cgi-bin/koha/circ/circulation.pl");
77     });
78     $("#searchtohold").click(function(){
79         searchToHold();
80         return false;
81     });
82     $("#select_patron_messages").on("change",function(){
83         $("#borrower_message").val( $(this).val() );
84     });
85
86     $(".edit-patronimage").on("click", function(e){
87         e.preventDefault();
88         var borrowernumber = $(this).data("borrowernumber");
89         $.get("/cgi-bin/koha/members/moremember.pl", { borrowernumber : borrowernumber }, function( data ){
90             var image_form = $(data).find("#picture-upload");
91             image_form.show().find(".cancel").remove();
92             $("#patronImageEdit .modal-body").html( image_form );
93         });
94         var modalTitle = $(this).attr("title");
95         $("#patronImageEdit .modal-title").text(modalTitle);
96         $("#patronImageEdit").modal("show");
97     });
98
99 });
100
101
102
103 function searchfield_date_tooltip(filter) {
104     var field = "#searchmember" + filter;
105     var type = "#searchfieldstype" + filter;
106     if ( $(type).val() == 'dateofbirth' ) {
107         var MSG_DATE_FORMAT = "";
108         if( dateformat == 'us' ){
109             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'MM/DD/YYYY'");
110         } else if( dateformat == 'iso' ){
111             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'YYYY-MM-DD'");
112         } else if( dateformat == 'metric' ){
113             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD/MM/YYYY'");
114         } else if( dateformat == 'dmydot' ){
115             MSG_DATE_FORMAT = __("Dates of birth should be entered in the format 'DD.MM.YYYY'");
116         }
117         $(field).attr("title", MSG_DATE_FORMAT).tooltip('show');
118     } else {
119         $(field).tooltip('destroy');
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;
127     }
128 }
129
130 function update_child() {
131     if( number_of_adult_categories > 1 ){
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 }