Bug 33528: (follow-up) Correct selector for event handler
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / pages / circulation.js
1 /* global borrowernumber */
2 $(document).ready(function() {
3     $("#CheckAllExports").on("click",function(){
4         $(".export:visible").prop("checked", true);
5         return false;
6     });
7     $("#UncheckAllExports").on("click",function(){
8         $(".export:visible").prop("checked", false);
9         return false;
10     });
11
12     $("#finesholdsissues a[data-toggle='tab']").on("shown.bs.tab", function(e){
13         $(this).click();
14     });
15
16     $("#borrower_messages .cancel").on("click",function(){
17         $("#add_message_form").hide();
18         $("#addmessage").show();
19     });
20
21     $("#addmessage").on("click",function(){
22         $(this).hide();
23         $("#add_message_form").show();
24      });
25
26     $("input.radio").on("click",function(){
27         radioCheckBox($(this));
28     });
29
30     $(".clear_date").on("click", function(){
31         $("#stickyduedate").prop( "checked", false );
32     });
33
34     $("#export_submit").on("click",function(){
35         export_checkouts($("#issues-table-output-format").val());
36         return false;
37     });
38
39     var circ_settings = $(".circ-settings");
40     var circ_settings_icon = $(".circ-settings-icon");
41
42     // If any checkboxes in the circ settings are selected, show the settings by default
43     if ( $(".circ-settings input:checked,#duedatespec[value!='']").length ) {
44         circ_settings.show();
45         circ_settings_icon.removeClass("fa-caret-right").addClass("fa-caret-down");
46     } else {
47         circ_settings.hide();
48         circ_settings_icon.removeClass("fa-caret-down").addClass("fa-caret-right");
49     }
50
51     $("#show-circ-settings a").on("click",function(){
52         if( circ_settings.is(":hidden")){
53             circ_settings.show();
54             circ_settings_icon.removeClass("fa-caret-right").addClass("fa-caret-down");
55         } else {
56             $("#barcode").focus();
57             circ_settings.hide();
58             circ_settings_icon.removeClass("fa-caret-down").addClass("fa-caret-right");
59         }
60     });
61
62     $(".circ_setting").on("click",function(){
63         $("#barcode").focus();
64     });
65
66     $("#itemSearchFallback").ready(function(){
67         $("#itemSearchFallback").modal("show");
68     });
69
70     // Debarments
71     $("#reldebarments_panel .remove_restriction").on("click",function(){
72         return confirm( __("Remove restriction?") );
73     });
74     var mrform = $("#manual_restriction_form");
75     var mrlink = $("#add_manual_restriction");
76     mrform.hide();
77     mrlink.on("click",function(e){
78         $(this).hide();
79         mrform.show();
80         e.preventDefault();
81     });
82     $("#cancel_manual_restriction").on("click",function(e){
83         mrlink.show();
84         mrform.hide();
85         e.preventDefault();
86     });
87     $(".clear-date").on("click",function(e){
88         e.preventDefault();
89         var fieldID = this.id.replace("clear-date-","");
90         $("#" + fieldID).val("");
91     });
92
93     /* Preselect Bootstrap tab based on location hash */
94     var hash = window.location.hash.substring(1);
95     if( hash ){
96         var activeTab = $('a[href="#' + hash + '"]');
97         activeTab && activeTab.tab('show');
98     }
99
100     if ( $('#clubs_panel').length ) {
101         $('#clubs-tab').on('click', function() {
102             $('#clubs_panel').text(_("Loading..."));
103             $('#clubs_panel').load('/cgi-bin/koha/clubs/patron-clubs-tab.pl?borrowernumber=' + borrowernumber );
104         });
105     }
106 });
107
108 function export_checkouts(format) {
109     if ($("input:checkbox[name='biblionumbers']:checked").length < 1){
110         alert( __("You must select checkout(s) to export") );
111         return;
112     }
113
114     $("input:checkbox[name='biblionumbers']").each( function(){
115         var input_item = $(this).siblings("input:checkbox");
116         if ( $(this).is(":checked") ) {
117             $(input_item).prop("checked", true);
118         } else {
119             $(input_item).prop("checked", false);
120         }
121     } );
122
123     if (format == 'iso2709_995') {
124         format = 'iso2709';
125         $("#dont_export_item").val(0);
126     } else if (format == 'iso2709') {
127         $("#dont_export_item").val(1);
128     }
129
130     document.getElementById("output_format").value = format;
131     document.issues.submit();
132 }