|
Lines 362-501
$(document).ready(function() {
Link Here
|
| 362 |
// Get our data from the API and process it prior to passing |
362 |
// Get our data from the API and process it prior to passing |
| 363 |
// it to datatables |
363 |
// it to datatables |
| 364 |
var filterParam = prefilters ? '&' + prefilters : ''; |
364 |
var filterParam = prefilters ? '&' + prefilters : ''; |
| 365 |
var ajax = $.ajax( |
365 |
// Only fire the request if we're on the ILL list page |
| 366 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias,comments,requested_partners' |
366 |
if (window.location.search.length == 0) {} |
| 367 |
+ filterParam |
367 |
var ajax = $.ajax( |
| 368 |
).done(function() { |
368 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias,comments,requested_partners' |
| 369 |
var data = JSON.parse(ajax.responseText); |
369 |
+ filterParam |
| 370 |
// Make a copy, we'll be removing columns next and need |
370 |
).done(function() { |
| 371 |
// to be able to refer to data that has been removed |
371 |
var data = JSON.parse(ajax.responseText); |
| 372 |
var dataCopy = $.extend(true, [], data); |
372 |
// Make a copy, we'll be removing columns next and need |
| 373 |
// Expand columns that need it and create an array |
373 |
// to be able to refer to data that has been removed |
| 374 |
// of all column names |
374 |
var dataCopy = $.extend(true, [], data); |
| 375 |
$.each(dataCopy, function(k, row) { |
375 |
// Expand columns that need it and create an array |
| 376 |
expandExpand(row); |
376 |
// of all column names |
| 377 |
}); |
377 |
$.each(dataCopy, function(k, row) { |
| 378 |
|
378 |
expandExpand(row); |
| 379 |
// Assemble an array of column definitions for passing |
379 |
}); |
| 380 |
// to datatables |
|
|
| 381 |
var colData = []; |
| 382 |
columns_settings.forEach(function(thisCol) { |
| 383 |
var colName = thisCol.columnname; |
| 384 |
// Create the base column object |
| 385 |
var colObj = $.extend({}, thisCol); |
| 386 |
colObj.name = colName; |
| 387 |
colObj.className = colName; |
| 388 |
colObj.defaultContent = ''; |
| 389 |
|
| 390 |
// We may need to process the data going in this |
| 391 |
// column, so do it if necessary |
| 392 |
if ( |
| 393 |
specialCols.hasOwnProperty(colName) && |
| 394 |
specialCols[colName].hasOwnProperty('func') |
| 395 |
) { |
| 396 |
var renderArray = [ |
| 397 |
specialCols[colName].func |
| 398 |
]; |
| 399 |
if (!specialCols[colName].skipSanitize) { |
| 400 |
renderArray.push( |
| 401 |
$.fn.dataTable.render.text() |
| 402 |
); |
| 403 |
} |
| 404 |
|
380 |
|
| 405 |
colObj.render = $.fn.dataTable.render.multi( |
381 |
// Assemble an array of column definitions for passing |
| 406 |
renderArray |
382 |
// to datatables |
| 407 |
); |
383 |
var colData = []; |
| 408 |
} else { |
384 |
columns_settings.forEach(function(thisCol) { |
| 409 |
colObj.data = colName; |
385 |
var colName = thisCol.columnname; |
| 410 |
colObj.render = $.fn.dataTable.render.text() |
386 |
// Create the base column object |
| 411 |
} |
387 |
var colObj = $.extend({}, thisCol); |
| 412 |
// Make sure properties that aren't present in the API |
388 |
colObj.name = colName; |
| 413 |
// response are populated with null to avoid Datatables |
389 |
colObj.className = colName; |
| 414 |
// choking on their absence |
390 |
colObj.defaultContent = ''; |
| 415 |
dataCopy.forEach(function(thisData) { |
391 |
|
| 416 |
if (!thisData.hasOwnProperty(colName)) { |
392 |
// We may need to process the data going in this |
| 417 |
thisData[colName] = null; |
393 |
// column, so do it if necessary |
|
|
394 |
if ( |
| 395 |
specialCols.hasOwnProperty(colName) && |
| 396 |
specialCols[colName].hasOwnProperty('func') |
| 397 |
) { |
| 398 |
var renderArray = [ |
| 399 |
specialCols[colName].func |
| 400 |
]; |
| 401 |
if (!specialCols[colName].skipSanitize) { |
| 402 |
renderArray.push( |
| 403 |
$.fn.dataTable.render.text() |
| 404 |
); |
| 405 |
} |
| 406 |
|
| 407 |
colObj.render = $.fn.dataTable.render.multi( |
| 408 |
renderArray |
| 409 |
); |
| 410 |
} else { |
| 411 |
colObj.data = colName; |
| 412 |
colObj.render = $.fn.dataTable.render.text() |
| 418 |
} |
413 |
} |
|
|
414 |
// Make sure properties that aren't present in the API |
| 415 |
// response are populated with null to avoid Datatables |
| 416 |
// choking on their absence |
| 417 |
dataCopy.forEach(function(thisData) { |
| 418 |
if (!thisData.hasOwnProperty(colName)) { |
| 419 |
thisData[colName] = null; |
| 420 |
} |
| 421 |
}); |
| 422 |
colData.push(colObj); |
| 419 |
}); |
423 |
}); |
| 420 |
colData.push(colObj); |
424 |
|
| 421 |
}); |
425 |
// Initialise the datatable |
| 422 |
|
426 |
table = KohaTable("ill-requests", { |
| 423 |
// Initialise the datatable |
427 |
'aoColumnDefs': [ |
| 424 |
table = KohaTable("ill-requests", { |
428 |
{ // Last column shouldn't be sortable or searchable |
| 425 |
'aoColumnDefs': [ |
429 |
'aTargets': [ 'actions' ], |
| 426 |
{ // Last column shouldn't be sortable or searchable |
430 |
'bSortable': false, |
| 427 |
'aTargets': [ 'actions' ], |
431 |
'bSearchable': false |
| 428 |
'bSortable': false, |
432 |
}, |
| 429 |
'bSearchable': false |
433 |
{ // When sorting 'placed', we want to use the |
| 430 |
}, |
434 |
// unformatted column |
| 431 |
{ // When sorting 'placed', we want to use the |
435 |
'aTargets': [ 'placed_formatted'], |
| 432 |
// unformatted column |
436 |
'iDataSort': 14 |
| 433 |
'aTargets': [ 'placed_formatted'], |
437 |
}, |
| 434 |
'iDataSort': 14 |
438 |
{ // When sorting 'updated', we want to use the |
| 435 |
}, |
439 |
// unformatted column |
| 436 |
{ // When sorting 'updated', we want to use the |
440 |
'aTargets': [ 'updated_formatted'], |
| 437 |
// unformatted column |
441 |
'iDataSort': 16 |
| 438 |
'aTargets': [ 'updated_formatted'], |
442 |
}, |
| 439 |
'iDataSort': 16 |
443 |
{ // When sorting 'completed', we want to use the |
| 440 |
}, |
444 |
// unformatted column |
| 441 |
{ // When sorting 'completed', we want to use the |
445 |
'aTargets': [ 'completed_formatted'], |
| 442 |
// unformatted column |
446 |
'iDataSort': 19 |
| 443 |
'aTargets': [ 'completed_formatted'], |
447 |
} |
| 444 |
'iDataSort': 19 |
448 |
], |
| 445 |
} |
449 |
'aaSorting': [[ 16, 'desc' ]], // Default sort, updated descending |
| 446 |
], |
450 |
'processing': true, // Display a message when manipulating |
| 447 |
'aaSorting': [[ 16, 'desc' ]], // Default sort, updated descending |
451 |
'sPaginationType': "full_numbers", // Pagination display |
| 448 |
'processing': true, // Display a message when manipulating |
452 |
'deferRender': true, // Improve performance on big datasets |
| 449 |
'sPaginationType': "full_numbers", // Pagination display |
453 |
'data': dataCopy, |
| 450 |
'deferRender': true, // Improve performance on big datasets |
454 |
'columns': colData, |
| 451 |
'data': dataCopy, |
455 |
'originalData': data, // Enable render functions to access |
| 452 |
'columns': colData, |
456 |
// our original data |
| 453 |
'originalData': data, // Enable render functions to access |
457 |
'initComplete': function() { |
| 454 |
// our original data |
458 |
|
| 455 |
'initComplete': function() { |
459 |
// Prepare any filter elements that need it |
| 456 |
|
460 |
for (var el in filterable) { |
| 457 |
// Prepare any filter elements that need it |
461 |
if (filterable.hasOwnProperty(el)) { |
| 458 |
for (var el in filterable) { |
462 |
if (filterable[el].hasOwnProperty('prep')) { |
| 459 |
if (filterable.hasOwnProperty(el)) { |
463 |
filterable[el].prep(dataCopy, data); |
| 460 |
if (filterable[el].hasOwnProperty('prep')) { |
464 |
} |
| 461 |
filterable[el].prep(dataCopy, data); |
465 |
if (filterable[el].hasOwnProperty('listener')) { |
| 462 |
} |
466 |
filterable[el].listener(); |
| 463 |
if (filterable[el].hasOwnProperty('listener')) { |
467 |
} |
| 464 |
filterable[el].listener(); |
|
|
| 465 |
} |
468 |
} |
| 466 |
} |
469 |
} |
| 467 |
} |
|
|
| 468 |
|
470 |
|
| 469 |
} |
471 |
} |
| 470 |
}, columns_settings); |
472 |
}, columns_settings); |
| 471 |
|
473 |
|
| 472 |
// Custom date range filtering |
474 |
// Custom date range filtering |
| 473 |
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) { |
475 |
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) { |
| 474 |
var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate'); |
476 |
var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate'); |
| 475 |
var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate'); |
477 |
var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate'); |
| 476 |
var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate'); |
478 |
var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate'); |
| 477 |
var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate'); |
479 |
var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate'); |
| 478 |
var rowPlaced = data[14] ? new Date(data[14]) : null; |
480 |
var rowPlaced = data[14] ? new Date(data[14]) : null; |
| 479 |
var rowModified = data[16] ? new Date(data[16]) : null; |
481 |
var rowModified = data[16] ? new Date(data[16]) : null; |
| 480 |
var placedPassed = true; |
482 |
var placedPassed = true; |
| 481 |
var modifiedPassed = true; |
483 |
var modifiedPassed = true; |
| 482 |
if (placedStart && rowPlaced && rowPlaced < placedStart) { |
484 |
if (placedStart && rowPlaced && rowPlaced < placedStart) { |
| 483 |
placedPassed = false |
485 |
placedPassed = false |
| 484 |
}; |
486 |
}; |
| 485 |
if (placedEnd && rowPlaced && rowPlaced > placedEnd) { |
487 |
if (placedEnd && rowPlaced && rowPlaced > placedEnd) { |
| 486 |
placedPassed = false; |
488 |
placedPassed = false; |
| 487 |
} |
489 |
} |
| 488 |
if (modifiedStart && rowModified && rowModified < modifiedStart) { |
490 |
if (modifiedStart && rowModified && rowModified < modifiedStart) { |
| 489 |
modifiedPassed = false |
491 |
modifiedPassed = false |
| 490 |
}; |
492 |
}; |
| 491 |
if (modifiedEnd && rowModified && rowModified > modifiedEnd) { |
493 |
if (modifiedEnd && rowModified && rowModified > modifiedEnd) { |
| 492 |
modifiedPassed = false; |
494 |
modifiedPassed = false; |
| 493 |
} |
495 |
} |
| 494 |
|
496 |
|
| 495 |
return placedPassed && modifiedPassed; |
497 |
return placedPassed && modifiedPassed; |
| 496 |
|
498 |
|
| 497 |
}); |
499 |
}); |
| 498 |
|
500 |
|
|
|
501 |
} |
| 499 |
} |
502 |
} |
| 500 |
); |
503 |
); |
| 501 |
|
504 |
|
| 502 |
- |
|
|