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