|
Lines 52-58
Link Here
|
| 52 |
<div class="col-md-2 order-sm-2 order-md-1"> |
52 |
<div class="col-md-2 order-sm-2 order-md-1"> |
| 53 |
<aside> |
53 |
<aside> |
| 54 |
<form id="available_items_filter"> |
54 |
<form id="available_items_filter"> |
| 55 |
<fieldset class="rows"> |
55 |
<fieldset class="brief"> |
| 56 |
<h4>Filter by</h4> |
56 |
<h4>Filter by</h4> |
| 57 |
<ol> |
57 |
<ol> |
| 58 |
<li> |
58 |
<li> |
|
Lines 75-81
Link Here
|
| 75 |
</li> |
75 |
</li> |
| 76 |
<li> |
76 |
<li> |
| 77 |
<label for="item_type">Item type:</label> |
77 |
<label for="item_type">Item type:</label> |
| 78 |
<select name="item_type" id="item_type" style="width: auto; min-width: 200px;"> |
78 |
<select name="item_type" id="item_type"> |
| 79 |
<option value="">Any</option> |
79 |
<option value="">Any</option> |
| 80 |
[% FOREACH itemtype IN ItemTypes.Get() %] |
80 |
[% FOREACH itemtype IN ItemTypes.Get() %] |
| 81 |
<option value="[% itemtype.itemtype | html %]">[% itemtype.description | html %]</option> |
81 |
<option value="[% itemtype.itemtype | html %]">[% itemtype.description | html %]</option> |
|
Lines 86-92
Link Here
|
| 86 |
</fieldset> |
86 |
</fieldset> |
| 87 |
<fieldset class="action"> |
87 |
<fieldset class="action"> |
| 88 |
<input type="submit" name="run_report" value="Search" class="btn btn-primary" /> |
88 |
<input type="submit" name="run_report" value="Search" class="btn btn-primary" /> |
| 89 |
<input type="reset" name="clear_form" value="Clear" class="btn btn-default" /> |
89 |
<input type="reset" name="clear_form" value="Clear" class="btn btn-default clear_search" /> |
| 90 |
</fieldset> |
90 |
</fieldset> |
| 91 |
</form> |
91 |
</form> |
| 92 |
|
92 |
|
|
Lines 102-273
Link Here
|
| 102 |
[% INCLUDE 'datatables.inc' %] |
102 |
[% INCLUDE 'datatables.inc' %] |
| 103 |
[% INCLUDE 'js-biblio-format.inc' %] |
103 |
[% INCLUDE 'js-biblio-format.inc' %] |
| 104 |
[% INCLUDE 'js-date-format.inc' %] |
104 |
[% INCLUDE 'js-date-format.inc' %] |
|
|
105 |
[% INCLUDE 'select2.inc' %] |
| 105 |
<script> |
106 |
<script> |
| 106 |
let table_settings = [% TablesSettings.GetTableSettings( 'circ', 'available-bookings', 'available-items', 'json' ) | $raw %]; |
107 |
let table_settings = [% TablesSettings.GetTableSettings( 'circ', 'available-bookings', 'available-items', 'json' ) | $raw %]; |
| 107 |
|
108 |
[% SET libraries = Branches.all %] |
| 108 |
$(document).ready(function() { |
109 |
let all_libraries = [% To.json(libraries) | $raw %].map(e => { |
| 109 |
|
110 |
e['_id'] = e.branchcode; |
|
|
111 |
e['_str'] = e.branchname; |
| 112 |
return e; |
| 113 |
}); |
| 114 |
let filters_options = {}; |
| 115 |
</script> |
| 116 |
<script> |
| 117 |
$(document).ready(function () { |
| 110 |
let additional_filters = { |
118 |
let additional_filters = { |
| 111 |
'me.holding_library_id': function() { |
119 |
"me.holding_library_id": function () { |
| 112 |
let selectedLibraries = $("#pickup_libraries").val(); |
120 |
let selectedLibraries = $("#pickup_libraries").val(); |
| 113 |
if (selectedLibraries && selectedLibraries.length > 0) { |
121 |
if (selectedLibraries && selectedLibraries.length > 0) { |
| 114 |
selectedLibraries = selectedLibraries.filter(lib => lib !== ''); |
122 |
selectedLibraries = selectedLibraries.filter(lib => lib !== ""); |
| 115 |
if (selectedLibraries.length > 0) { |
123 |
if (selectedLibraries.length > 0) { |
| 116 |
return selectedLibraries; |
124 |
return selectedLibraries; |
| 117 |
} |
125 |
} |
| 118 |
} |
126 |
} |
| 119 |
return; |
127 |
return; |
| 120 |
}, |
128 |
}, |
| 121 |
'me.item_type_id': function() { |
129 |
"me.item_type_id": function () { |
| 122 |
let itemType = $("#item_type").val(); |
130 |
let itemType = $("#item_type").val(); |
| 123 |
if (itemType && itemType !== '') { |
131 |
if (itemType && itemType !== "") { |
| 124 |
return itemType; |
132 |
return itemType; |
| 125 |
} |
133 |
} |
| 126 |
return; |
134 |
return; |
| 127 |
} |
135 |
}, |
| 128 |
}; |
136 |
}; |
| 129 |
|
137 |
|
| 130 |
[% SET libraries = Branches.all %] |
|
|
| 131 |
let all_libraries = [% To.json(libraries) | $raw %].map(e => { |
| 132 |
e['_id'] = e.branchcode; |
| 133 |
e['_str'] = e.branchname; |
| 134 |
return e; |
| 135 |
}); |
| 136 |
let filters_options = {}; |
138 |
let filters_options = {}; |
| 137 |
|
139 |
|
| 138 |
var available_items_table_url = '/api/v1/items/available_for_booking'; |
140 |
var available_items_table_url = "/api/v1/items/available_for_booking"; |
| 139 |
|
141 |
|
| 140 |
var available_items_table = $("#available_items_table").kohaTable({ |
142 |
var available_items_table = $("#available_items_table").kohaTable( |
| 141 |
"ajax": { |
|
|
| 142 |
"url": available_items_table_url |
| 143 |
}, |
| 144 |
"embed": [ |
| 145 |
"biblio", |
| 146 |
"+strings", |
| 147 |
"home_library", |
| 148 |
"holding_library", |
| 149 |
"item_type" |
| 150 |
], |
| 151 |
"order": [[ 2, "asc" ]], |
| 152 |
"columns": [{ |
| 153 |
"data": "home_library.name", |
| 154 |
"title": _("Homebranch"), |
| 155 |
"searchable": true, |
| 156 |
"orderable": true, |
| 157 |
"render": function( data, type, row, meta ) { |
| 158 |
return escape_str(row.home_library_id ? row.home_library.name : row.home_library_id); |
| 159 |
} |
| 160 |
}, |
| 161 |
{ |
| 162 |
"data": "holding_library.name", |
| 163 |
"title": _("Pickup library"), |
| 164 |
"searchable": true, |
| 165 |
"orderable": true, |
| 166 |
"render": function( data, type, row, meta ) { |
| 167 |
return escape_str(row.holding_library_id ? row.holding_library.name : row.holding_library_id); |
| 168 |
} |
| 169 |
}, |
| 170 |
{ |
143 |
{ |
| 171 |
"data": "biblio.title", |
144 |
ajax: { |
| 172 |
"title": _("Title"), |
145 |
url: available_items_table_url, |
| 173 |
"searchable": true, |
146 |
}, |
| 174 |
"orderable": true, |
147 |
embed: ["biblio", "+strings", "home_library", "holding_library", "item_type"], |
| 175 |
"render": function(data,type,row,meta) { |
148 |
order: [[2, "asc"]], |
| 176 |
if ( row.biblio ) { |
149 |
columns: [ |
| 177 |
return $biblio_to_html(row.biblio, { |
150 |
{ |
| 178 |
link: 'detail' |
151 |
data: "home_library.name", |
| 179 |
}); |
152 |
title: _("Homebranch"), |
| 180 |
} else { |
153 |
searchable: true, |
| 181 |
return 'No title'; |
154 |
orderable: true, |
| 182 |
} |
155 |
render: function (data, type, row, meta) { |
| 183 |
} |
156 |
return escape_str(row.home_library_id ? row.home_library.name : row.home_library_id); |
|
|
157 |
}, |
| 158 |
}, |
| 159 |
{ |
| 160 |
data: "holding_library.name", |
| 161 |
title: _("Pickup library"), |
| 162 |
searchable: true, |
| 163 |
orderable: true, |
| 164 |
render: function (data, type, row, meta) { |
| 165 |
return escape_str(row.holding_library_id ? row.holding_library.name : row.holding_library_id); |
| 166 |
}, |
| 167 |
}, |
| 168 |
{ |
| 169 |
data: "biblio.title", |
| 170 |
title: _("Title"), |
| 171 |
searchable: true, |
| 172 |
orderable: true, |
| 173 |
render: function (data, type, row, meta) { |
| 174 |
if (row.biblio) { |
| 175 |
return $biblio_to_html(row.biblio, { |
| 176 |
link: "detail", |
| 177 |
}); |
| 178 |
} else { |
| 179 |
return "No title"; |
| 180 |
} |
| 181 |
}, |
| 182 |
}, |
| 183 |
{ |
| 184 |
data: "item_type_id", |
| 185 |
title: _("Item type"), |
| 186 |
searchable: true, |
| 187 |
orderable: true, |
| 188 |
render: function (data, type, row, meta) { |
| 189 |
if (row.item_type && row.item_type.description) { |
| 190 |
return escape_str(row.item_type.description); |
| 191 |
} else if (row._strings && row._strings.item_type_id) { |
| 192 |
return escape_str(row._strings.item_type_id.str); |
| 193 |
} else { |
| 194 |
return escape_str(row.item_type_id || ""); |
| 195 |
} |
| 196 |
}, |
| 197 |
}, |
| 198 |
{ |
| 199 |
data: "external_id", |
| 200 |
title: _("Barcode"), |
| 201 |
searchable: true, |
| 202 |
orderable: true, |
| 203 |
}, |
| 204 |
{ |
| 205 |
data: "callnumber", |
| 206 |
title: _("Callnumber"), |
| 207 |
searchable: true, |
| 208 |
orderable: true, |
| 209 |
}, |
| 210 |
{ |
| 211 |
data: "location", |
| 212 |
title: _("Location"), |
| 213 |
searchable: true, |
| 214 |
orderable: true, |
| 215 |
render: function (data, type, row, meta) { |
| 216 |
if (row._strings && row._strings.location) { |
| 217 |
return row._strings.location.str; |
| 218 |
} else { |
| 219 |
return row.location || ""; |
| 220 |
} |
| 221 |
}, |
| 222 |
}, |
| 223 |
{ |
| 224 |
data: "localuse", |
| 225 |
title: _("Local use"), |
| 226 |
searchable: true, |
| 227 |
orderable: true, |
| 228 |
}, |
| 229 |
], |
| 184 |
}, |
230 |
}, |
| 185 |
{ |
231 |
table_settings, |
| 186 |
"data": "item_type_id", |
232 |
1, |
| 187 |
"title": _("Item type"), |
233 |
additional_filters, |
| 188 |
"searchable": true, |
234 |
filters_options |
| 189 |
"orderable": true, |
235 |
); |
| 190 |
"render": function(data,type,row,meta) { |
|
|
| 191 |
if ( row.item_type && row.item_type.description ) { |
| 192 |
return escape_str(row.item_type.description); |
| 193 |
} else if ( row._strings && row._strings.item_type_id ) { |
| 194 |
return escape_str(row._strings.item_type_id.str); |
| 195 |
} else { |
| 196 |
return escape_str(row.item_type_id || ''); |
| 197 |
} |
| 198 |
} |
| 199 |
}, |
| 200 |
{ |
| 201 |
"data": "external_id", |
| 202 |
"title": _("Barcode"), |
| 203 |
"searchable": true, |
| 204 |
"orderable": true |
| 205 |
}, |
| 206 |
{ |
| 207 |
"data": "callnumber", |
| 208 |
"title": _("Callnumber"), |
| 209 |
"searchable": true, |
| 210 |
"orderable": true |
| 211 |
}, |
| 212 |
{ |
| 213 |
"data": "location", |
| 214 |
"title": _("Location"), |
| 215 |
"searchable": true, |
| 216 |
"orderable": true, |
| 217 |
"render": function(data,type,row,meta) { |
| 218 |
if ( row._strings && row._strings.location ) { |
| 219 |
return row._strings.location.str; |
| 220 |
} else { |
| 221 |
return row.location || ''; |
| 222 |
} |
| 223 |
} |
| 224 |
}, |
| 225 |
{ |
| 226 |
"data": "localuse", |
| 227 |
"title": _("Local use"), |
| 228 |
"searchable": true, |
| 229 |
"orderable": true |
| 230 |
}] |
| 231 |
}, table_settings, 1, additional_filters, filters_options); |
| 232 |
|
236 |
|
| 233 |
$("#available_items_filter").on("submit", function(e){ |
237 |
$("#available_items_filter").on("submit", function (e) { |
| 234 |
e.preventDefault(); |
238 |
e.preventDefault(); |
| 235 |
|
239 |
|
| 236 |
if (!$("#start_date").val() || !$("#end_date").val()) { |
240 |
if (!$("#start_date").val() || !$("#end_date").val()) { |
| 237 |
alert("Please select both start and end dates"); |
241 |
alert("Please select both start and end dates"); |
| 238 |
return false; |
242 |
return false; |
| 239 |
} |
243 |
} |
| 240 |
let newUrl = '/api/v1/items/available_for_booking'; |
244 |
let newUrl = "/api/v1/items/available_for_booking"; |
| 241 |
let params = []; |
245 |
let params = []; |
| 242 |
|
246 |
|
| 243 |
let fromdate = $("#start_date"); |
247 |
let fromdate = $("#start_date"); |
| 244 |
let todate = $("#end_date"); |
248 |
let todate = $("#end_date"); |
| 245 |
if ( fromdate.val() !== '' && todate.val() !== '' ) { |
249 |
if (fromdate.val() !== "" && todate.val() !== "") { |
| 246 |
let fromDateStr = fromdate.val(); |
250 |
let fromDateStr = fromdate.val(); |
| 247 |
let toDateStr = todate.val(); |
251 |
let toDateStr = todate.val(); |
| 248 |
params.push('start_date=' + encodeURIComponent(fromDateStr)); |
252 |
params.push("start_date=" + encodeURIComponent(fromDateStr)); |
| 249 |
params.push('end_date=' + encodeURIComponent(toDateStr)); |
253 |
params.push("end_date=" + encodeURIComponent(toDateStr)); |
| 250 |
|
|
|
| 251 |
} |
254 |
} |
| 252 |
if (params.length > 0) { |
255 |
if (params.length > 0) { |
| 253 |
newUrl += '?' + params.join('&'); |
256 |
newUrl += "?" + params.join("&"); |
| 254 |
} |
257 |
} |
| 255 |
available_items_table.DataTable().ajax.url(newUrl).load(); |
258 |
available_items_table.DataTable().ajax.url(newUrl).load(); |
| 256 |
}); |
259 |
}); |
| 257 |
|
260 |
|
| 258 |
$("#available_items_filter input[type=reset]").on("click", function(e){ |
261 |
$("#available_items_filter input[type=reset]").on("click", function (e) { |
| 259 |
$("#pickup_libraries").val([]); |
262 |
$("#pickup_libraries").val([]); |
| 260 |
$("#item_type").val(''); |
263 |
$("#item_type").val(""); |
| 261 |
$("#start_date").val('[% start_date_default | html %]'); |
264 |
$("#start_date").val(start_date_default); |
| 262 |
$("#end_date").val('[% end_date_default | html %]'); |
265 |
$("#end_date").val(end_date_default); |
| 263 |
|
266 |
|
| 264 |
let resetUrl = '/api/v1/items/available_for_booking'; |
267 |
let resetUrl = "/api/v1/items/available_for_booking"; |
| 265 |
if ('[% start_date_default | html %]' && '[% end_date_default | html %]') { |
268 |
if (start_date_default && end_date_default) { |
| 266 |
resetUrl += '?start_date=[% start_date_default | uri %]&end_date=[% end_date_default | uri %]'; |
269 |
resetUrl += `?start_date=${start_date_default}&end_date=${end_date_default}`; |
| 267 |
} |
270 |
} |
| 268 |
available_items_table.DataTable().ajax.url(resetUrl).load(); |
271 |
available_items_table.DataTable().ajax.url(resetUrl).load(); |
| 269 |
}); |
272 |
}); |
| 270 |
|
273 |
$("#pickup_libraries").select2(); |
| 271 |
}); |
274 |
}); |
| 272 |
</script> |
275 |
</script> |
| 273 |
[% END %] |
276 |
[% END %] |
| 274 |
- |
|
|