Bug 29407: Make the pickup locations dropdown JS reusable
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / cart.js
1 /* global __ dataTablesDefaults showMore showLess delSelRecords addSelToShelf sendBasket printBasket delBasket openBiblio selRecord */
2
3 function placeHold () {
4     var checkedItems = $("input:checkbox:checked");
5     if ($(checkedItems).size() === 0) {
6         alert( __("No item was selected") );
7         return false;
8     }
9
10     var newloc;
11
12     if ($(checkedItems).size() > 1) {
13         var bibs = "";
14         $(checkedItems).each(function() {
15             var bib = $(this).val();
16             bibs += bib + "/";
17         });
18
19         newloc = "/cgi-bin/koha/reserve/request.pl?biblionumbers=" + bibs + "&multi_hold=1";
20     } else {
21         var bib = checkedItems[0].value;
22         newloc = "/cgi-bin/koha/reserve/request.pl?biblionumber=" + bib;
23     }
24
25     window.opener.location = newloc;
26     window.close();
27 }
28
29 function batchDelete(){
30     var checkedItems = $("input:checkbox:checked");
31     if ($(checkedItems).size() === 0) {
32         alert( __("No item was selected") );
33         return false;
34     }
35     var newloc;
36
37     var bibs = "";
38     checkedItems.each(function() {
39         var bib = $(this).val();
40         bibs += bib + "/";
41     });
42
43     newloc = "/cgi-bin/koha/tools/batch_delete_records.pl?op=list&type=biblio&bib_list=" + bibs;
44
45     window.opener.location = newloc;
46     window.close();
47 }
48
49 function batchModify(){
50     var checkedItems = $("input:checkbox:checked");
51     if ($(checkedItems).size() === 0) {
52         alert( __("No item was selected") );
53         return false;
54     }
55     var newloc;
56
57     var bibs = "";
58     $(checkedItems).each(function() {
59         var bib = $(this).val();
60         bibs += bib + "/";
61     });
62     newloc = "/cgi-bin/koha/tools/batch_record_modification.pl?op=list&bib_list=" + bibs + "&type=biblio";
63
64     window.opener.location = newloc;
65     window.close();
66 }
67
68 $(document).ready(function(){
69     $("#items-popover").popover();
70
71     $("#CheckAll").click(function (e) {
72         e.preventDefault();
73         $(".select_record").each(function () {
74             $(this).prop("checked", true).change();
75         });
76     });
77
78     $("#CheckNone").click(function (e) {
79         e.preventDefault();
80         $(".select_record").each(function () {
81             $(this).prop("checked", false).change();
82         });
83     });
84
85     $(".holdsep").text("| ");
86     $(".hold").text( __("Place hold") );
87     $("#downloadcartc").empty();
88
89     $("#itemst").dataTable($.extend(true, {}, dataTablesDefaults, {
90         "sDom": 't',
91         "aoColumnDefs": [
92             { "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
93             { "sType": "anti-the", "aTargets" : [ "anti-the" ] },
94             { "sType": "callnumbers", "aTargets" : [ "callnumbers"] }
95         ],
96         "aaSorting": [[ 1, "asc" ]],
97         "bPaginate": false
98     }));
99
100     $(".showdetails").on("click",function(e){
101         e.preventDefault();
102         if( $(this).hasClass("showmore") ){
103             showMore();
104         } else {
105             showLess();
106         }
107     });
108
109     $("#batch_modify").on("click",function(e){
110         e.preventDefault();
111         batchModify();
112     });
113     $("#batch_delete").on("click",function(e){
114         e.preventDefault();
115         batchDelete();
116     });
117
118     $("#remove_from_cart").on("click",function(e){
119         e.preventDefault();
120         delSelRecords();
121     });
122
123     $("#add_to_list").on("click",function(e){
124         e.preventDefault();
125         addSelToShelf();
126     });
127
128     $("#place_hold").on("click",function(e){
129         e.preventDefault();
130         placeHold();
131     });
132
133     $("#send_cart").on("click",function(e){
134         e.preventDefault();
135         sendBasket();
136     });
137
138     $("#print_cart").on("click",function(e){
139         e.preventDefault();
140         printBasket();
141     });
142
143     $("#empty_cart").on("click",function(e){
144         e.preventDefault();
145         delBasket('popup');
146     });
147     $(".title").on("click",function(e){
148         e.preventDefault();
149         openBiblio( this.href );
150     });
151     $(".select_record").on("change",function(){
152         selRecord( this.value, this.checked );
153     });
154 });