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