|
Lines 192-397
Link Here
|
| 192 |
const show_itemtype_column = [% show_itemtype_column ? 1 : 0 | html %]; |
192 |
const show_itemtype_column = [% show_itemtype_column ? 1 : 0 | html %]; |
| 193 |
</script> |
193 |
</script> |
| 194 |
<script> |
194 |
<script> |
| 195 |
$(document).ready(function() { |
195 |
$(document).ready(function () { |
| 196 |
let current_holds_table = build_holds_table("#table_holdshistory"); |
196 |
let current_holds_table = build_holds_table("#table_holdshistory"); |
| 197 |
let old_holds_table = build_holds_table("#table_oldholdshistory", 1); |
197 |
let old_holds_table = build_holds_table("#table_oldholdshistory", 1); |
| 198 |
function build_holds_table(table_id, old){ |
198 |
function build_holds_table(table_id, old) { |
| 199 |
let additional_filters = { |
199 |
let additional_filters = { |
| 200 |
"-and": function(){ |
200 |
"-and": function () { |
| 201 |
let statuses = []; |
201 |
let statuses = []; |
| 202 |
let include_cancelled = false; |
202 |
let include_cancelled = false; |
| 203 |
if ( table_id == '#table_holdshistory' ) { |
203 |
if (table_id == "#table_holdshistory") { |
| 204 |
if ( $("#current_pending_filter").is(":checked") ) { |
204 |
if ($("#current_pending_filter").is(":checked")) { |
| 205 |
statuses.push(null); |
205 |
statuses.push(null); |
| 206 |
} |
206 |
} |
| 207 |
if ( $("#current_waiting_filter").is(":checked") ) { |
207 |
if ($("#current_waiting_filter").is(":checked")) { |
| 208 |
statuses.push("W"); |
208 |
statuses.push("W"); |
| 209 |
} |
209 |
} |
| 210 |
if ( $("#current_processing_filter").is(":checked") ) { |
210 |
if ($("#current_processing_filter").is(":checked")) { |
| 211 |
statuses.push("P"); |
211 |
statuses.push("P"); |
| 212 |
} |
212 |
} |
| 213 |
if ( $("#current_transit_filter").is(":checked") ) { |
213 |
if ($("#current_transit_filter").is(":checked")) { |
| 214 |
statuses.push("T"); |
214 |
statuses.push("T"); |
| 215 |
} |
215 |
} |
| 216 |
} else { |
216 |
} else { |
| 217 |
if ( $("#old_fulfilled_filter").is(":checked") ) { |
217 |
if ($("#old_fulfilled_filter").is(":checked")) { |
| 218 |
statuses.push("F"); |
218 |
statuses.push("F"); |
| 219 |
} |
219 |
} |
| 220 |
if ( $("#old_cancelled_filter").is(":checked") ) { |
220 |
if ($("#old_cancelled_filter").is(":checked")) { |
| 221 |
include_cancelled = true; |
221 |
include_cancelled = true; |
| 222 |
} |
222 |
} |
| 223 |
} |
223 |
} |
| 224 |
if ( include_cancelled ) { |
224 |
if (include_cancelled) { |
| 225 |
return [{status: statuses}, { cancellation_date: {"<": new Date().toISOString() } } ]; // cancellation_date cannot be in the future. Would be better a 'not null' here however. |
225 |
return [{ status: statuses }, { cancellation_date: { "<": new Date().toISOString() } }]; // cancellation_date cannot be in the future. Would be better a 'not null' here however. |
| 226 |
} else { |
226 |
} else { |
| 227 |
return [{status: statuses}]; |
227 |
return [{ status: statuses }]; |
| 228 |
} |
228 |
} |
| 229 |
}, |
229 |
}, |
| 230 |
|
|
|
| 231 |
}; |
230 |
}; |
| 232 |
|
231 |
|
| 233 |
let table_url = `/api/v1/patrons/${patron_id}/holds`; |
232 |
let table_url = `/api/v1/patrons/${patron_id}/holds`; |
| 234 |
let table_embeds = ['+strings', 'biblio', 'item', 'pickup_library']; |
233 |
let table_embeds = ["+strings", "biblio", "item", "pickup_library"]; |
| 235 |
if (old){ |
234 |
if (old) { |
| 236 |
table_url += '?old=1'; |
235 |
table_url += "?old=1"; |
| 237 |
table_embeds.push('deleted_biblio'); |
236 |
table_embeds.push("deleted_biblio"); |
| 238 |
} |
237 |
} |
| 239 |
return $(table_id).kohaTable({ |
238 |
return $(table_id).kohaTable( |
| 240 |
ajax: { |
239 |
{ |
| 241 |
url: table_url, |
240 |
ajax: { |
| 242 |
}, |
241 |
url: table_url, |
| 243 |
order: [], |
|
|
| 244 |
embed: table_embeds, |
| 245 |
columns: [ |
| 246 |
{ |
| 247 |
data: "biblio.title:biblio.subtitle:biblio.medium", |
| 248 |
searchable: true, |
| 249 |
orderable: true, |
| 250 |
render: function (data, type, row, meta) { |
| 251 |
if( row.biblio ){ |
| 252 |
return $biblio_to_html(row.biblio, { link: 1 }); |
| 253 |
} else { |
| 254 |
return $biblio_to_html(row.deleted_biblio, { link: 0, deleted: 1 }); |
| 255 |
} |
| 256 |
} |
| 257 |
}, |
| 258 |
{ |
| 259 |
data: "biblio.author", |
| 260 |
searchable: true, |
| 261 |
orderable: true, |
| 262 |
render: function (data, type, row, meta) { |
| 263 |
let biblio = row.biblio ? row.biblio : row.deleted_biblio; |
| 264 |
return biblio ? biblio.author : ""; |
| 265 |
} |
| 266 |
}, |
| 267 |
{ |
| 268 |
data: "item.external_id", |
| 269 |
searchable: true, |
| 270 |
orderable: true, |
| 271 |
render: function (data, type, row, meta) { |
| 272 |
return row.item ? row.item.external_id : ""; |
| 273 |
} |
| 274 |
}, |
| 275 |
{ |
| 276 |
data: "item.callnumber", |
| 277 |
searchable: true, |
| 278 |
orderable: true, |
| 279 |
render: function (data, type, row, meta) { |
| 280 |
return row.item ? row.item.callnumber: ""; |
| 281 |
} |
| 282 |
}, |
| 283 |
{ |
| 284 |
data: "me.pickup_library_id", |
| 285 |
datatype: "coded_value:library", |
| 286 |
dataFilter: "libraries", |
| 287 |
searchable: true, |
| 288 |
orderable: true, |
| 289 |
render: function (data, type, row, meta) { |
| 290 |
return escape_str(row._strings.pickup_library_id ? row._strings.pickup_library_id.str : row.pickup_library_id); |
| 291 |
} |
| 292 |
}, |
| 293 |
{ |
| 294 |
data: "hold_date", |
| 295 |
type: "date", |
| 296 |
searchable: true, |
| 297 |
orderable: true, |
| 298 |
render: function (data, type, row, meta) { |
| 299 |
return $date(row.hold_date); |
| 300 |
} |
| 301 |
}, |
242 |
}, |
| 302 |
{ |
243 |
order: [], |
| 303 |
data: "expiration_date", |
244 |
embed: table_embeds, |
| 304 |
type: "date", |
245 |
columns: [ |
| 305 |
searchable: true, |
246 |
{ |
| 306 |
orderable: true, |
247 |
data: "biblio.title:biblio.subtitle:biblio.medium", |
| 307 |
render: function (data, type, row, meta) { |
248 |
searchable: true, |
| 308 |
return $date(row.expiration_date) |
249 |
orderable: true, |
| 309 |
} |
250 |
render: function (data, type, row, meta) { |
| 310 |
}, |
251 |
if (row.biblio) { |
| 311 |
{ |
252 |
return $biblio_to_html(row.biblio, { link: 1 }); |
| 312 |
data: "waiting_date", |
253 |
} else { |
| 313 |
type: "date", |
254 |
return $biblio_to_html(row.deleted_biblio, { link: 0, deleted: 1 }); |
| 314 |
searchable: true, |
255 |
} |
| 315 |
orderable: true, |
256 |
}, |
| 316 |
render: function (data, type, row, meta) { |
257 |
}, |
| 317 |
return $date(row.waiting_date) |
258 |
{ |
| 318 |
} |
259 |
data: "biblio.author", |
| 319 |
}, |
260 |
searchable: true, |
| 320 |
{ |
261 |
orderable: true, |
| 321 |
data: "cancellation_date", |
262 |
render: function (data, type, row, meta) { |
| 322 |
type: "date", |
263 |
let biblio = row.biblio ? row.biblio : row.deleted_biblio; |
| 323 |
searchable: true, |
264 |
return biblio ? biblio.author : ""; |
| 324 |
orderable: true, |
265 |
}, |
| 325 |
render: function (data, type, row, meta) { |
266 |
}, |
| 326 |
return $date(row.cancellation_date) |
267 |
{ |
| 327 |
} |
268 |
data: "item.external_id", |
| 328 |
}, |
269 |
searchable: true, |
| 329 |
...(show_itemtype_column? |
270 |
orderable: true, |
| 330 |
[{ |
271 |
render: function (data, type, row, meta) { |
| 331 |
data: "item_type_id", |
272 |
return row.item ? row.item.external_id : ""; |
| 332 |
datatype: "coded_value:item_type", |
273 |
}, |
| 333 |
dataFilter: "item_types", |
274 |
}, |
| 334 |
searchable: true, |
275 |
{ |
| 335 |
orderable: true, |
276 |
data: "item.callnumber", |
| 336 |
render: function (data, type, row, meta) { |
277 |
searchable: true, |
| 337 |
if ( row.item_type_id ) { |
278 |
orderable: true, |
| 338 |
return row._strings.item_type_id ? row._strings.item_type_id.str : row.item_type_id; |
279 |
render: function (data, type, row, meta) { |
| 339 |
} else { |
280 |
return row.item ? row.item.callnumber : ""; |
| 340 |
return _("Any item type"); |
281 |
}, |
| 341 |
} |
282 |
}, |
| 342 |
} |
283 |
{ |
| 343 |
}]:[]), |
284 |
data: "me.pickup_library_id", |
| 344 |
{ |
285 |
datatype: "coded_value:library", |
| 345 |
data: "status", |
286 |
dataFilter: "libraries", |
| 346 |
searchable: false, |
287 |
searchable: true, |
| 347 |
orderable: true, |
288 |
orderable: true, |
| 348 |
render: function (data, type, row, meta) { |
289 |
render: function (data, type, row, meta) { |
| 349 |
if ( row.status == 'F' ) { |
290 |
return escape_str(row._strings.pickup_library_id ? row._strings.pickup_library_id.str : row.pickup_library_id); |
| 350 |
return _("Fulfilled"); |
291 |
}, |
| 351 |
} else if (row.cancellation_date) { |
292 |
}, |
| 352 |
let r = _("Cancelled"); |
293 |
{ |
| 353 |
if (row.cancellation_reason){ |
294 |
data: "hold_date", |
| 354 |
r += " (%s)".format(row._strings.cancellation_reason.str); |
295 |
type: "date", |
|
|
296 |
searchable: true, |
| 297 |
orderable: true, |
| 298 |
render: function (data, type, row, meta) { |
| 299 |
return $date(row.hold_date); |
| 300 |
}, |
| 301 |
}, |
| 302 |
{ |
| 303 |
data: "expiration_date", |
| 304 |
type: "date", |
| 305 |
searchable: true, |
| 306 |
orderable: true, |
| 307 |
render: function (data, type, row, meta) { |
| 308 |
return $date(row.expiration_date); |
| 309 |
}, |
| 310 |
}, |
| 311 |
{ |
| 312 |
data: "waiting_date", |
| 313 |
type: "date", |
| 314 |
searchable: true, |
| 315 |
orderable: true, |
| 316 |
render: function (data, type, row, meta) { |
| 317 |
return $date(row.waiting_date); |
| 318 |
}, |
| 319 |
}, |
| 320 |
{ |
| 321 |
data: "cancellation_date", |
| 322 |
type: "date", |
| 323 |
searchable: true, |
| 324 |
orderable: true, |
| 325 |
render: function (data, type, row, meta) { |
| 326 |
return $date(row.cancellation_date); |
| 327 |
}, |
| 328 |
}, |
| 329 |
...(show_itemtype_column |
| 330 |
? [ |
| 331 |
{ |
| 332 |
data: "item_type_id", |
| 333 |
datatype: "coded_value:item_type", |
| 334 |
dataFilter: "item_types", |
| 335 |
searchable: true, |
| 336 |
orderable: true, |
| 337 |
render: function (data, type, row, meta) { |
| 338 |
if (row.item_type_id) { |
| 339 |
return row._strings.item_type_id ? row._strings.item_type_id.str : row.item_type_id; |
| 340 |
} else { |
| 341 |
return _("Any item type"); |
| 342 |
} |
| 343 |
}, |
| 344 |
}, |
| 345 |
] |
| 346 |
: []), |
| 347 |
{ |
| 348 |
data: "status", |
| 349 |
searchable: false, |
| 350 |
orderable: true, |
| 351 |
render: function (data, type, row, meta) { |
| 352 |
if (row.status == "F") { |
| 353 |
return _("Fulfilled"); |
| 354 |
} else if (row.cancellation_date) { |
| 355 |
let r = _("Cancelled"); |
| 356 |
if (row.cancellation_reason) { |
| 357 |
r += " (%s)".format(row._strings.cancellation_reason.str); |
| 358 |
} |
| 359 |
return r; |
| 360 |
} else if (row.status == "W") { |
| 361 |
return _("Waiting"); |
| 362 |
} else if (row.status == "P") { |
| 363 |
return _("Processing"); |
| 364 |
} else if (row.status == "T") { |
| 365 |
return _("In transit"); |
| 355 |
} |
366 |
} |
| 356 |
return r; |
|
|
| 357 |
} else if (row.status == 'W') { |
| 358 |
return _("Waiting"); |
| 359 |
} else if (row.status == 'P') { |
| 360 |
return _("Processing"); |
| 361 |
} else if (row.status == 'T') { |
| 362 |
return _("In transit"); |
| 363 |
} |
| 364 |
|
367 |
|
| 365 |
return _("Pending"); |
368 |
return _("Pending"); |
| 366 |
} |
369 |
}, |
| 367 |
}, |
370 |
}, |
| 368 |
{ |
371 |
{ |
| 369 |
data: "notes", |
372 |
data: "notes", |
| 370 |
searchable: true, |
373 |
searchable: true, |
| 371 |
orderable: true, |
374 |
orderable: true, |
| 372 |
render: function (data, type, row, meta) { |
375 |
render: function (data, type, row, meta) { |
| 373 |
return row.notes; |
376 |
return row.notes; |
| 374 |
} |
377 |
}, |
| 375 |
}, |
378 |
}, |
| 376 |
], |
379 |
], |
| 377 |
}, |
380 |
}, |
| 378 |
table_settings, |
381 |
table_settings, |
| 379 |
true, |
382 |
true, |
| 380 |
additional_filters, |
383 |
additional_filters, |
| 381 |
filters_options, |
384 |
filters_options |
| 382 |
); |
385 |
); |
| 383 |
} |
386 |
} |
| 384 |
$("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function(e){ |
387 |
$("#current_holds_filters :checkbox, #old_holds_filters :checkbox").on("change", function (e) { |
| 385 |
e.preventDefault(); |
388 |
e.preventDefault(); |
| 386 |
let container = $(this).closest("div"); |
389 |
let container = $(this).closest("div"); |
| 387 |
if ( $(this).hasClass("show_all") ) { |
390 |
if ($(this).hasClass("show_all")) { |
| 388 |
if ( $(this).is(":checked") ) { |
391 |
if ($(this).is(":checked")) { |
| 389 |
container.find(":checkbox").prop("checked", true); |
392 |
container.find(":checkbox").prop("checked", true); |
| 390 |
} |
393 |
} |
| 391 |
} else if ( $(this).not(":checked") ) { |
394 |
} else if ($(this).not(":checked")) { |
| 392 |
container.find(".show_all").prop("checked", false); |
395 |
container.find(".show_all").prop("checked", false); |
| 393 |
} |
396 |
} |
| 394 |
let table_dt = $("#"+container.data("table-id")).DataTable(); |
397 |
let table_dt = $("#" + container.data("table-id")).DataTable(); |
| 395 |
table_dt.draw(); |
398 |
table_dt.draw(); |
| 396 |
}); |
399 |
}); |
| 397 |
}); |
400 |
}); |