|
Lines 1-322
Link Here
|
| 1 |
$(document).ready(function() { |
1 |
$(document).ready(function() { |
| 2 |
|
|
|
| 3 |
// Illview Datatable setup |
| 4 |
|
| 5 |
var table; |
| 6 |
|
| 7 |
// Filters that are active |
| 8 |
var activeFilters = {}; |
| 9 |
|
| 10 |
// Get any prefilters |
| 11 |
var prefilters = $('table#ill-requests').data('prefilters'); |
| 12 |
|
| 13 |
// Fields we need to expand (flatten) |
| 14 |
var expand = [ |
| 15 |
'metadata', |
| 16 |
'patron', |
| 17 |
'library' |
| 18 |
]; |
| 19 |
|
| 20 |
// Expanded fields |
| 21 |
// This is auto populated |
| 22 |
var expanded = {}; |
| 23 |
|
| 24 |
// Filterable columns |
| 25 |
var filterable = { |
| 26 |
status: { |
| 27 |
prep: function(tableData, oData) { |
| 28 |
var uniques = {}; |
| 29 |
tableData.forEach(function(row) { |
| 30 |
var resolvedName; |
| 31 |
if (row.status_alias) { |
| 32 |
resolvedName = row.status_alias.lib; |
| 33 |
} else { |
| 34 |
resolvedName = getStatusName( |
| 35 |
row.capabilities[row.status].name, |
| 36 |
row |
| 37 |
); |
| 38 |
} |
| 39 |
uniques[resolvedName] = 1 |
| 40 |
}); |
| 41 |
Object.keys(uniques).sort().forEach(function(unique) { |
| 42 |
$('#illfilter_status').append( |
| 43 |
'<option value="' + unique + |
| 44 |
'">' + unique + '</option>' |
| 45 |
); |
| 46 |
}); |
| 47 |
}, |
| 48 |
listener: function() { |
| 49 |
var me = 'status'; |
| 50 |
$('#illfilter_status').change(function() { |
| 51 |
var sel = $('#illfilter_status option:selected').val(); |
| 52 |
if (sel && sel.length > 0) { |
| 53 |
activeFilters[me] = function() { |
| 54 |
table.api().column(13).search(sel); |
| 55 |
} |
| 56 |
} else { |
| 57 |
if (activeFilters.hasOwnProperty(me)) { |
| 58 |
delete activeFilters[me]; |
| 59 |
} |
| 60 |
} |
| 61 |
}); |
| 62 |
}, |
| 63 |
clear: function() { |
| 64 |
$('#illfilter_status').val(''); |
| 65 |
} |
| 66 |
}, |
| 67 |
pickupBranch: { |
| 68 |
prep: function(tableData, oData) { |
| 69 |
var uniques = {}; |
| 70 |
tableData.forEach(function(row) { |
| 71 |
uniques[row.library_branchname] = 1 |
| 72 |
}); |
| 73 |
Object.keys(uniques).sort().forEach(function(unique) { |
| 74 |
$('#illfilter_branchname').append( |
| 75 |
'<option value="' + unique + |
| 76 |
'">' + unique + '</option>' |
| 77 |
); |
| 78 |
}); |
| 79 |
}, |
| 80 |
listener: function() { |
| 81 |
var me = 'pickupBranch'; |
| 82 |
$('#illfilter_branchname').change(function() { |
| 83 |
var sel = $('#illfilter_branchname option:selected').val(); |
| 84 |
if (sel && sel.length > 0) { |
| 85 |
activeFilters[me] = function() { |
| 86 |
table.api().column(12).search(sel); |
| 87 |
} |
| 88 |
} else { |
| 89 |
if (activeFilters.hasOwnProperty(me)) { |
| 90 |
delete activeFilters[me]; |
| 91 |
} |
| 92 |
} |
| 93 |
}); |
| 94 |
}, |
| 95 |
clear: function() { |
| 96 |
$('#illfilter_branchname').val(''); |
| 97 |
} |
| 98 |
}, |
| 99 |
patron: { |
| 100 |
listener: function() { |
| 101 |
var me = 'patron'; |
| 102 |
$('#illfilter_patron').change(function() { |
| 103 |
var val = $('#illfilter_patron').val(); |
| 104 |
if (val && val.length > 0) { |
| 105 |
activeFilters[me] = function() { |
| 106 |
table.api().column(10).search(val); |
| 107 |
} |
| 108 |
} else { |
| 109 |
if (activeFilters.hasOwnProperty(me)) { |
| 110 |
delete activeFilters[me]; |
| 111 |
} |
| 112 |
} |
| 113 |
}); |
| 114 |
}, |
| 115 |
clear: function() { |
| 116 |
$('#illfilter_patron').val(''); |
| 117 |
} |
| 118 |
}, |
| 119 |
keyword: { |
| 120 |
listener: function () { |
| 121 |
var me = 'keyword'; |
| 122 |
$('#illfilter_keyword').change(function () { |
| 123 |
var val = $('#illfilter_keyword').val(); |
| 124 |
if (val && val.length > 0) { |
| 125 |
activeFilters[me] = function () { |
| 126 |
table.api().search(val); |
| 127 |
} |
| 128 |
} else { |
| 129 |
if (activeFilters.hasOwnProperty(me)) { |
| 130 |
delete activeFilters[me]; |
| 131 |
} |
| 132 |
} |
| 133 |
}); |
| 134 |
}, |
| 135 |
clear: function () { |
| 136 |
$('#illfilter_keyword').val(''); |
| 137 |
} |
| 138 |
}, |
| 139 |
dateModified: { |
| 140 |
clear: function() { |
| 141 |
$('#illfilter_datemodified_start, #illfilter_datemodified_end').val(''); |
| 142 |
} |
| 143 |
}, |
| 144 |
datePlaced: { |
| 145 |
clear: function() { |
| 146 |
$('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val(''); |
| 147 |
} |
| 148 |
} |
| 149 |
}; //END Filterable columns |
| 150 |
|
| 151 |
// Expand any fields we're expanding |
| 152 |
var expandExpand = function(row) { |
| 153 |
expand.forEach(function(thisExpand) { |
| 154 |
if (row.hasOwnProperty(thisExpand)) { |
| 155 |
if (!expanded.hasOwnProperty(thisExpand)) { |
| 156 |
expanded[thisExpand] = []; |
| 157 |
} |
| 158 |
var expandObj = row[thisExpand]; |
| 159 |
Object.keys(expandObj).forEach( |
| 160 |
function(thisExpandCol) { |
| 161 |
var expColName = thisExpand + '_' + thisExpandCol.replace(/\s/g,'_'); |
| 162 |
// Keep a list of fields that have been expanded |
| 163 |
// so we can create toggle links for them |
| 164 |
if (expanded[thisExpand].indexOf(expColName) == -1) { |
| 165 |
expanded[thisExpand].push(expColName); |
| 166 |
} |
| 167 |
expandObj[expColName] = |
| 168 |
expandObj[thisExpandCol]; |
| 169 |
delete expandObj[thisExpandCol]; |
| 170 |
} |
| 171 |
); |
| 172 |
$.extend(true, row, expandObj); |
| 173 |
delete row[thisExpand]; |
| 174 |
} |
| 175 |
}); |
| 176 |
}; |
| 177 |
//END Expand |
| 178 |
|
| 179 |
// Strip the expand prefix if it exists, we do this for display |
| 180 |
var stripPrefix = function(value) { |
| 181 |
expand.forEach(function(thisExpand) { |
| 182 |
var regex = new RegExp(thisExpand + '_', 'g'); |
| 183 |
value = value.replace(regex, ''); |
| 184 |
}); |
| 185 |
return value; |
| 186 |
}; |
| 187 |
|
| 188 |
// Our 'render' function for borrowerlink |
| 189 |
var createPatronLink = function(data, type, row) { |
| 190 |
var patronLink = '<a title="' + ill_borrower_details + '" ' + |
| 191 |
'href="/cgi-bin/koha/members/moremember.pl?' + |
| 192 |
'borrowernumber='+row.borrowernumber+'">'; |
| 193 |
if ( row.patron_firstname ) { |
| 194 |
patronLink = patronLink + row.patron_firstname + ' '; |
| 195 |
} |
| 196 |
patronLink = patronLink + row.patron_surname + |
| 197 |
' (' + row.patron_cardnumber + ')' + '</a>'; |
| 198 |
return patronLink; |
| 199 |
}; |
| 200 |
|
| 201 |
// Our 'render' function for biblio_id |
| 202 |
var createBiblioLink = function(data, type, row) { |
| 203 |
return (row.biblio_id) ? |
| 204 |
'<a title="' + ill_biblio_details + '" ' + |
| 205 |
'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + |
| 206 |
row.biblio_id + '">' + |
| 207 |
row.biblio_id + |
| 208 |
'</a>' : ''; |
| 209 |
}; |
| 210 |
|
| 211 |
// Our 'render' function for title |
| 212 |
var createTitle = function(data, type, row) { |
| 213 |
return ( |
| 214 |
row.hasOwnProperty('metadata_container_title') && |
| 215 |
row.metadata_container_title |
| 216 |
) ? row.metadata_container_title : row.metadata_title; |
| 217 |
}; |
| 218 |
|
| 219 |
// Render function for request ID |
| 220 |
var createRequestId = function(data, type, row) { |
| 221 |
return row.id_prefix + row.illrequest_id; |
| 222 |
}; |
| 223 |
|
| 224 |
// Render function for type |
| 225 |
var createType = function(data, type, row) { |
| 226 |
if (!row.hasOwnProperty('metadata_Type') || !row.metadata_Type) { |
| 227 |
if (row.hasOwnProperty('medium') && row.medium) { |
| 228 |
row.metadata_Type = row.medium; |
| 229 |
} else { |
| 230 |
row.metadata_Type = null; |
| 231 |
} |
| 232 |
} |
| 233 |
return row.metadata_Type; |
| 234 |
}; |
| 235 |
|
| 236 |
// Render function for request status |
| 237 |
var createStatus = function(data, type, row, meta) { |
| 238 |
if (row.status_alias) { |
| 239 |
return row.status_alias.lib |
| 240 |
? row.status_alias.lib |
| 241 |
: row.status_alias.authorised_value; |
| 242 |
} else { |
| 243 |
var status_name = row.capabilities[row.status].name; |
| 244 |
return getStatusName(status_name, row); |
| 245 |
} |
| 246 |
}; |
| 247 |
|
| 248 |
var getStatusName = function(origName, row) { |
| 249 |
switch( origName ) { |
| 250 |
case "New request": |
| 251 |
return ill_statuses.new; |
| 252 |
case "Requested": |
| 253 |
return ill_statuses.req; |
| 254 |
case "Requested from partners": |
| 255 |
var statStr = ill_statuses.genreq; |
| 256 |
if ( |
| 257 |
row.hasOwnProperty('requested_partners') && |
| 258 |
row.requested_partners && |
| 259 |
row.requested_partners.length > 0 |
| 260 |
) { |
| 261 |
statStr += ' (' + row.requested_partners + ')'; |
| 262 |
} |
| 263 |
return statStr; |
| 264 |
case "Request reverted": |
| 265 |
return ill_statuses.rev; |
| 266 |
case "Queued request": |
| 267 |
return ill_statuses.que; |
| 268 |
case "Cancellation requested": |
| 269 |
return ill_statuses.canc; |
| 270 |
case "Completed": |
| 271 |
return ill_statuses.comp; |
| 272 |
case "Delete request": |
| 273 |
return ill_statuses.del; |
| 274 |
default: |
| 275 |
return origName; |
| 276 |
} |
| 277 |
}; |
| 278 |
|
| 279 |
// Render function for creating a row's action link |
| 280 |
var createActionLink = function(data, type, row) { |
| 281 |
return '<a class="btn btn-default btn-sm" ' + |
| 282 |
'href="/cgi-bin/koha/ill/ill-requests.pl?' + |
| 283 |
'method=illview&illrequest_id=' + |
| 284 |
row.illrequest_id + |
| 285 |
'">' + ill_manage + '</a>'; |
| 286 |
}; |
| 287 |
|
| 288 |
// Columns that require special treatment |
| 289 |
var specialCols = { |
| 290 |
action: { |
| 291 |
func: createActionLink, |
| 292 |
skipSanitize: true |
| 293 |
}, |
| 294 |
illrequest_id: { |
| 295 |
func: createRequestId |
| 296 |
}, |
| 297 |
status: { |
| 298 |
func: createStatus |
| 299 |
}, |
| 300 |
biblio_id: { |
| 301 |
name: ill_columns.biblio_id, |
| 302 |
func: createBiblioLink, |
| 303 |
skipSanitize: true |
| 304 |
}, |
| 305 |
metadata_title: { |
| 306 |
func: createTitle |
| 307 |
}, |
| 308 |
metadata_Type: { |
| 309 |
func: createType |
| 310 |
}, |
| 311 |
updated: { |
| 312 |
name: ill_columns.updated |
| 313 |
}, |
| 314 |
patron: { |
| 315 |
skipSanitize: true, |
| 316 |
func: createPatronLink |
| 317 |
} |
| 318 |
}; |
| 319 |
|
| 320 |
// Display the modal containing request supplier metadata |
2 |
// Display the modal containing request supplier metadata |
| 321 |
$('#ill-request-display-log').on('click', function(e) { |
3 |
$('#ill-request-display-log').on('click', function(e) { |
| 322 |
e.preventDefault(); |
4 |
e.preventDefault(); |
|
Lines 360-559
$(document).ready(function() {
Link Here
|
| 360 |
$('#dataPreview').modal({show:true}); |
42 |
$('#dataPreview').modal({show:true}); |
| 361 |
}); |
43 |
}); |
| 362 |
|
44 |
|
| 363 |
// Allow us to chain Datatable render helpers together, so we |
45 |
function display_extended_attribute(row, type) { |
| 364 |
// can use our custom functions and render.text(), which |
46 |
var arr = $.grep(row.extended_attributes, ( x => x.type === type )); |
| 365 |
// provides us with data sanitization |
47 |
if (arr.length > 0) { |
| 366 |
$.fn.dataTable.render.multi = function(renderArray) { |
48 |
return escape_str(arr[0].value); |
| 367 |
return function(d, type, row, meta) { |
|
|
| 368 |
for(var r = 0; r < renderArray.length; r++) { |
| 369 |
var toCall = renderArray[r].hasOwnProperty('display') ? |
| 370 |
renderArray[r].display : |
| 371 |
renderArray[r]; |
| 372 |
d = toCall(d, type, row, meta); |
| 373 |
} |
| 374 |
return d; |
| 375 |
} |
49 |
} |
|
|
50 |
|
| 51 |
return ''; |
| 376 |
} |
52 |
} |
| 377 |
|
53 |
|
| 378 |
// Get our data from the API and process it prior to passing |
54 |
// At the moment, the only prefilter possible is borrowernumber |
| 379 |
// it to datatables |
55 |
// see ill/ill-requests.pl and members/ill-requests.pl |
| 380 |
var filterParam = prefilters ? '&' + prefilters : ''; |
56 |
let additional_prefilters = []; |
| 381 |
// Only fire the request if we're on an appropriate page |
57 |
if(prefilters){ |
| 382 |
if ( |
58 |
let prefilters_array = prefilters.split("&"); |
| 383 |
( |
59 |
prefilters_array.forEach((prefilter) => { |
| 384 |
// ILL list requests page |
60 |
let prefilter_split = prefilter.split("="); |
| 385 |
window.location.href.match(/ill\/ill-requests\.pl/) && |
61 |
additional_prefilters.push( { |
| 386 |
window.location.search.length == 0 |
62 |
"key": prefilter_split[0], |
| 387 |
) || |
63 |
"value": prefilter_split[1] |
| 388 |
// Patron profile page |
64 |
} ); |
| 389 |
window.location.href.match(/members\/ill-requests\.pl/) |
65 |
|
| 390 |
) { |
|
|
| 391 |
var ajax = $.ajax( |
| 392 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias,comments,requested_partners' |
| 393 |
+ filterParam |
| 394 |
).done(function() { |
| 395 |
var data = JSON.parse(ajax.responseText); |
| 396 |
// Make a copy, we'll be removing columns next and need |
| 397 |
// to be able to refer to data that has been removed |
| 398 |
var dataCopy = $.extend(true, [], data); |
| 399 |
// Expand columns that need it and create an array |
| 400 |
// of all column names |
| 401 |
$.each(dataCopy, function(k, row) { |
| 402 |
expandExpand(row); |
| 403 |
}); |
66 |
}); |
|
|
67 |
} |
| 404 |
|
68 |
|
| 405 |
// Assemble an array of column definitions for passing |
69 |
let additional_filters = { |
| 406 |
// to datatables |
70 |
"me.backend": function(){ |
| 407 |
var colData = []; |
71 |
let backend = $("#illfilter_backend").val(); |
| 408 |
var columns = table_settings['columns']; |
72 |
if (!backend) return ""; |
| 409 |
columns.forEach(function(thisCol) { |
73 |
return { "=": backend } |
| 410 |
var colName = thisCol.columnname; |
74 |
}, |
| 411 |
// Create the base column object |
75 |
"me.branchcode": function(){ |
| 412 |
var colObj = $.extend({}, thisCol); |
76 |
let branchcode = $("#illfilter_branchname").val(); |
| 413 |
colObj.name = colName; |
77 |
if (!branchcode) return ""; |
| 414 |
colObj.className = colName; |
78 |
return { "=": branchcode } |
| 415 |
colObj.defaultContent = ''; |
79 |
}, |
| 416 |
|
80 |
"me.borrowernumber": function(){ |
| 417 |
// We may need to process the data going in this |
81 |
let borrowernumber_pre_filter = additional_prefilters.find(e => e.key === 'borrowernumber'); |
| 418 |
// column, so do it if necessary |
82 |
if ( additional_prefilters.length == 0 || typeof borrowernumber_pre_filter === undefined) return ""; |
| 419 |
if ( |
83 |
return { "=": borrowernumber_pre_filter["value"] } |
| 420 |
specialCols.hasOwnProperty(colName) && |
84 |
}, |
| 421 |
specialCols[colName].hasOwnProperty('func') |
85 |
"-or": function(){ |
| 422 |
) { |
86 |
let patron = $("#illfilter_patron").val(); |
| 423 |
var renderArray = [ |
87 |
let status = $("#illfilter_status").val(); |
| 424 |
specialCols[colName].func |
88 |
let filters = []; |
| 425 |
]; |
89 |
let patron_sub_or = []; |
| 426 |
if (!specialCols[colName].skipSanitize) { |
90 |
let status_sub_or = []; |
| 427 |
renderArray.push( |
91 |
let subquery_and = []; |
| 428 |
$.fn.dataTable.render.text() |
92 |
|
| 429 |
); |
93 |
if (!patron && !status) return ""; |
|
|
94 |
|
| 95 |
if(patron){ |
| 96 |
const patron_search_fields = "me.borrowernumber,patron.cardnumber,patron.firstname,patron.surname"; |
| 97 |
patron_search_fields.split(',').forEach(function(attr){ |
| 98 |
let operator = "="; |
| 99 |
let patron_data = patron; |
| 100 |
if ( attr != "me.borrowernumber" && attr != "patron.cardnumber") { |
| 101 |
operator = "like"; |
| 102 |
patron_data = "%" + patron + "%"; |
| 430 |
} |
103 |
} |
|
|
104 |
patron_sub_or.push({ |
| 105 |
[attr]:{[operator]: patron_data } |
| 106 |
}); |
| 107 |
}); |
| 108 |
subquery_and.push(patron_sub_or); |
| 109 |
} |
| 431 |
|
110 |
|
| 432 |
colObj.render = $.fn.dataTable.render.multi( |
111 |
if(status){ |
| 433 |
renderArray |
112 |
const status_search_fields = "me.status,me.status_av"; |
| 434 |
); |
113 |
status_search_fields.split(',').forEach(function(attr){ |
| 435 |
} else { |
114 |
status_sub_or.push({ |
| 436 |
colObj.data = colName; |
115 |
[attr]:{"=": status } |
| 437 |
colObj.render = $.fn.dataTable.render.text() |
116 |
}); |
| 438 |
} |
117 |
}); |
| 439 |
// Make sure properties that aren't present in the API |
118 |
subquery_and.push(status_sub_or); |
| 440 |
// response are populated with null to avoid Datatables |
119 |
} |
| 441 |
// choking on their absence |
120 |
|
| 442 |
dataCopy.forEach(function(thisData) { |
121 |
filters.push({"-and": subquery_and}); |
| 443 |
if (!thisData.hasOwnProperty(colName)) { |
122 |
|
| 444 |
thisData[colName] = null; |
123 |
return filters; |
| 445 |
} |
124 |
}, |
|
|
125 |
"me.placed": function(){ |
| 126 |
if ( additional_prefilters.length != 0 && !additional_prefilters.find(e => e.key === 'placed')) return ""; |
| 127 |
let placed_start = $('#illfilter_dateplaced_start').get(0)._flatpickr.selectedDates[0]; |
| 128 |
let placed_end = $('#illfilter_dateplaced_end').get(0)._flatpickr.selectedDates[0]; |
| 129 |
if (!placed_start && !placed_end) return ""; |
| 130 |
return { |
| 131 |
...(placed_start && {">=": placed_start}), |
| 132 |
...(placed_end && {"<=": placed_end}) |
| 133 |
} |
| 134 |
}, |
| 135 |
"me.updated": function(){ |
| 136 |
if ( additional_prefilters.length != 0 && !additional_prefilters.find(e => e.key === 'updated')) return ""; |
| 137 |
let updated_start = $('#illfilter_datemodified_start').get(0)._flatpickr.selectedDates[0]; |
| 138 |
let updated_end = $('#illfilter_datemodified_end').get(0)._flatpickr.selectedDates[0]; |
| 139 |
if (!updated_start && !updated_end) return ""; |
| 140 |
// set selected datetime hours and minutes to the end of the day |
| 141 |
// to grab any request updated during that day |
| 142 |
let updated_end_value = new Date(updated_end); |
| 143 |
updated_end_value.setHours(updated_end_value.getHours()+23); |
| 144 |
updated_end_value.setMinutes(updated_end_value.getMinutes()+59); |
| 145 |
return { |
| 146 |
...(updated_start && {">=": updated_start}), |
| 147 |
...(updated_end && {"<=": updated_end_value}) |
| 148 |
} |
| 149 |
}, |
| 150 |
"-and": function(){ |
| 151 |
let keyword = $("#illfilter_keyword").val(); |
| 152 |
if (!keyword) return ""; |
| 153 |
|
| 154 |
let filters = []; |
| 155 |
let subquery_and = []; |
| 156 |
|
| 157 |
const search_fields = "me.illrequest_id,me.borrowernumber,me.biblio_id,me.due_date,me.branchcode,library.name,me.status,me.status_alias,me.placed,me.replied,me.updated,me.completed,me.medium,me.accessurl,me.cost,me.price_paid,me.notesopac,me.notesstaff,me.orderid,me.backend,patron.firstname,patron.surname"; |
| 158 |
let sub_or = []; |
| 159 |
search_fields.split(',').forEach(function(attr){ |
| 160 |
sub_or.push({ |
| 161 |
[attr]:{"like":"%" + keyword + "%"} |
| 446 |
}); |
162 |
}); |
| 447 |
colData.push(colObj); |
|
|
| 448 |
}); |
163 |
}); |
|
|
164 |
subquery_and.push(sub_or); |
| 165 |
filters.push({"-and": subquery_and}); |
| 166 |
|
| 167 |
const extended_attributes = "title,type,author,article_title,pages,issue,volume,year"; |
| 168 |
let extended_sub_or = []; |
| 169 |
subquery_and = []; |
| 170 |
extended_sub_or.push({ |
| 171 |
"extended_attributes.type": extended_attributes.split(','), |
| 172 |
"extended_attributes.value":{"like":"%" + keyword + "%"} |
| 173 |
}); |
| 174 |
subquery_and.push(extended_sub_or); |
| 449 |
|
175 |
|
| 450 |
// Initialise the datatable |
176 |
filters.push({"-and": subquery_and}); |
| 451 |
table = KohaTable("ill-requests", { |
177 |
return filters; |
| 452 |
'aoColumnDefs': [ |
178 |
} |
| 453 |
{ // Last column shouldn't be sortable or searchable |
179 |
}; |
| 454 |
'aTargets': [ 'actions' ], |
|
|
| 455 |
'bSortable': false, |
| 456 |
'bSearchable': false |
| 457 |
}, |
| 458 |
{ // When sorting 'placed', we want to use the |
| 459 |
// unformatted column |
| 460 |
'aTargets': [ 'placed_formatted'], |
| 461 |
'iDataSort': 14 |
| 462 |
}, |
| 463 |
{ // When sorting 'updated', we want to use the |
| 464 |
// unformatted column |
| 465 |
'aTargets': [ 'updated_formatted'], |
| 466 |
'iDataSort': 16 |
| 467 |
}, |
| 468 |
{ // When sorting 'completed', we want to use the |
| 469 |
// unformatted column |
| 470 |
'aTargets': [ 'completed_formatted'], |
| 471 |
'iDataSort': 19 |
| 472 |
} |
| 473 |
], |
| 474 |
'aaSorting': [[ 16, 'desc' ]], // Default sort, updated descending |
| 475 |
'processing': true, // Display a message when manipulating |
| 476 |
'sPaginationType': "full_numbers", // Pagination display |
| 477 |
'deferRender': true, // Improve performance on big datasets |
| 478 |
'data': dataCopy, |
| 479 |
"dom": '<"top pager"<"table_entries"ilp><"table_controls"B>>tr<"bottom pager"ip>', |
| 480 |
'columns': colData, |
| 481 |
'originalData': data, // Enable render functions to access |
| 482 |
// our original data |
| 483 |
'initComplete': function() { |
| 484 |
|
| 485 |
// Prepare any filter elements that need it |
| 486 |
for (var el in filterable) { |
| 487 |
if (filterable.hasOwnProperty(el)) { |
| 488 |
if (filterable[el].hasOwnProperty('prep')) { |
| 489 |
filterable[el].prep(dataCopy, data); |
| 490 |
} |
| 491 |
if (filterable[el].hasOwnProperty('listener')) { |
| 492 |
filterable[el].listener(); |
| 493 |
} |
| 494 |
} |
| 495 |
} |
| 496 |
|
180 |
|
|
|
181 |
var ill_requests_table = $("#ill-requests").kohaTable({ |
| 182 |
"ajax": { |
| 183 |
"url": '/api/v1/ill_requests' |
| 184 |
}, |
| 185 |
"embed": [ |
| 186 |
'+strings', |
| 187 |
'biblio', |
| 188 |
'comments+count', |
| 189 |
'extended_attributes', |
| 190 |
'library', |
| 191 |
'id_prefix', |
| 192 |
'patron' |
| 193 |
], |
| 194 |
"stateSave": true, // remember state on page reload |
| 195 |
"columns": [ |
| 196 |
{ |
| 197 |
"data": "ill_request_id", |
| 198 |
"searchable": true, |
| 199 |
"orderable": true, |
| 200 |
"render": function( data, type, row, meta ) { |
| 201 |
return '<a href="/cgi-bin/koha/ill/ill-requests.pl?' + |
| 202 |
'method=illview&illrequest_id=' + |
| 203 |
encodeURIComponent(data) + |
| 204 |
'">' + escape_str(row.id_prefix) + escape_str(data) + '</a>'; |
| 205 |
} |
| 206 |
}, |
| 207 |
{ |
| 208 |
"data": "", // author |
| 209 |
"orderable": false, |
| 210 |
"render": function(data, type, row, meta) { |
| 211 |
return display_extended_attribute(row, 'author'); |
| 212 |
} |
| 213 |
}, |
| 214 |
{ |
| 215 |
"data": "", // title |
| 216 |
"orderable": false, |
| 217 |
"render": function(data, type, row, meta) { |
| 218 |
return display_extended_attribute(row, 'title'); |
| 219 |
} |
| 220 |
}, |
| 221 |
{ |
| 222 |
"data": "", // article_title |
| 223 |
"orderable": false, |
| 224 |
"render": function(data, type, row, meta) { |
| 225 |
return display_extended_attribute(row, 'article_title'); |
| 226 |
} |
| 227 |
}, |
| 228 |
{ |
| 229 |
"data": "", // issue |
| 230 |
"orderable": false, |
| 231 |
"render": function(data, type, row, meta) { |
| 232 |
return display_extended_attribute(row, 'issue'); |
| 233 |
} |
| 234 |
}, |
| 235 |
{ |
| 236 |
"data": "", // volume |
| 237 |
"orderable": false, |
| 238 |
"render": function(data, type, row, meta) { |
| 239 |
return display_extended_attribute(row, 'volume'); |
| 240 |
} |
| 241 |
}, |
| 242 |
{ |
| 243 |
"data": "", // year |
| 244 |
"orderable": false, |
| 245 |
"render": function(data, type, row, meta) { |
| 246 |
return display_extended_attribute(row, 'year'); |
| 247 |
} |
| 248 |
}, |
| 249 |
{ |
| 250 |
"data": "", // pages |
| 251 |
"orderable": false, |
| 252 |
"render": function(data, type, row, meta) { |
| 253 |
return display_extended_attribute(row, 'pages'); |
| 254 |
} |
| 255 |
}, |
| 256 |
{ |
| 257 |
"data": "", // type |
| 258 |
"orderable": false, |
| 259 |
"render": function(data, type, row, meta) { |
| 260 |
return display_extended_attribute(row, 'type'); |
| 261 |
} |
| 262 |
}, |
| 263 |
{ |
| 264 |
"data": "ill_backend_request_id", |
| 265 |
"orderable": true, |
| 266 |
"render": function(data, type, row, meta) { |
| 267 |
return escape_str(data); |
| 497 |
} |
268 |
} |
| 498 |
}, table_settings); |
269 |
}, |
| 499 |
|
270 |
{ |
| 500 |
// Custom date range filtering |
271 |
"data": "patron.firstname:patron.surname:patron.cardnumber", |
| 501 |
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) { |
272 |
"render": function(data, type, row, meta) { |
| 502 |
var placedStart = $('#illfilter_dateplaced_start').get(0)._flatpickr.selectedDates[0]; |
273 |
return (row.patron) ? $patron_to_html( row.patron, { display_cardnumber: true, url: true } ) : ''; } }, |
| 503 |
var placedEnd = $('#illfilter_dateplaced_end').get(0)._flatpickr.selectedDates[0]; |
274 |
{ |
| 504 |
var modifiedStart = $('#illfilter_datemodified_start').get(0)._flatpickr.selectedDates[0]; |
275 |
"data": "biblio_id", |
| 505 |
var modifiedEnd = $('#illfilter_datemodified_end').get(0)._flatpickr.selectedDates[0]; |
276 |
"orderable": true, |
| 506 |
var rowPlaced = data[14] ? new Date(data[14]) : null; |
277 |
"render": function(data, type, row, meta) { |
| 507 |
var rowModified = data[16] ? new Date(data[16]) : null; |
278 |
if ( data === null ) { |
| 508 |
var placedPassed = true; |
279 |
return ""; |
| 509 |
var modifiedPassed = true; |
280 |
} |
| 510 |
if (placedStart && rowPlaced && rowPlaced < placedStart) { |
281 |
return $biblio_to_html(row.biblio, { biblio_id_only: 1, link: 1 }); |
| 511 |
placedPassed = false |
|
|
| 512 |
}; |
| 513 |
if (placedEnd && rowPlaced && rowPlaced > placedEnd) { |
| 514 |
placedPassed = false; |
| 515 |
} |
282 |
} |
| 516 |
if (modifiedStart && rowModified && rowModified < modifiedStart) { |
283 |
}, |
| 517 |
modifiedPassed = false |
284 |
{ |
| 518 |
}; |
285 |
"data": "library.name", |
| 519 |
if (modifiedEnd && rowModified && rowModified > modifiedEnd) { |
286 |
"orderable": true, |
| 520 |
modifiedPassed = false; |
287 |
"render": function(data, type, row, meta) { |
|
|
288 |
return escape_str(data); |
| 521 |
} |
289 |
} |
|
|
290 |
}, |
| 291 |
{ |
| 292 |
"data": "status", |
| 293 |
"orderable": true, |
| 294 |
"render": function(data, type, row, meta) { |
| 295 |
let status_label = row._strings.status_av ? |
| 296 |
row._strings.status_av.str ? |
| 297 |
row._strings.status_av.str : |
| 298 |
row._strings.status_av.code : |
| 299 |
row._strings.status.str |
| 300 |
return escape_str(status_label); |
| 301 |
} |
| 302 |
}, |
| 303 |
{ |
| 304 |
"data": "requested_date", |
| 305 |
"orderable": true, |
| 306 |
"render": function(data, type, row, meta) { |
| 307 |
return $date(data); |
| 308 |
} |
| 309 |
}, |
| 310 |
{ |
| 311 |
"data": "timestamp", |
| 312 |
"orderable": true, |
| 313 |
"render": function(data, type, row, meta) { |
| 314 |
return $date(data); |
| 315 |
} |
| 316 |
}, |
| 317 |
{ |
| 318 |
"data": "replied_date", |
| 319 |
"orderable": true, |
| 320 |
"render": function(data, type, row, meta) { |
| 321 |
return $date(data); |
| 322 |
} |
| 323 |
}, |
| 324 |
{ |
| 325 |
"data": "completed_date", |
| 326 |
"orderable": true, |
| 327 |
"render": function(data, type, row, meta) { |
| 328 |
return $date(data); |
| 329 |
} |
| 330 |
}, |
| 331 |
{ |
| 332 |
"data": "access_url", |
| 333 |
"orderable": true, |
| 334 |
"render": function(data, type, row, meta) { |
| 335 |
return escape_str(data); |
| 336 |
} |
| 337 |
}, |
| 338 |
{ |
| 339 |
"data": "cost", |
| 340 |
"orderable": true, |
| 341 |
"render": function(data, type, row, meta) { |
| 342 |
return escape_str(data); |
| 343 |
} |
| 344 |
}, |
| 345 |
{ |
| 346 |
"data": "paid_price", |
| 347 |
"orderable": true, |
| 348 |
"render": function(data, type, row, meta) { |
| 349 |
return escape_str(data); |
| 350 |
} |
| 351 |
}, |
| 352 |
{ |
| 353 |
"data": "comments_count", |
| 354 |
"orderable": true, |
| 355 |
"searchable": false, |
| 356 |
"render": function(data, type, row, meta) { |
| 357 |
return escape_str(data); |
| 358 |
} |
| 359 |
}, |
| 360 |
{ |
| 361 |
"data": "opac_notes", |
| 362 |
"orderable": true, |
| 363 |
"render": function(data, type, row, meta) { |
| 364 |
return escape_str(data); |
| 365 |
} |
| 366 |
}, |
| 367 |
{ |
| 368 |
"data": "staff_notes", |
| 369 |
"orderable": true, |
| 370 |
"render": function(data, type, row, meta) { |
| 371 |
return escape_str(data); |
| 372 |
} |
| 373 |
}, |
| 374 |
{ |
| 375 |
"data": "ill_backend_id", |
| 376 |
"orderable": true, |
| 377 |
"render": function(data, type, row, meta) { |
| 378 |
return escape_str(data); |
| 379 |
} |
| 380 |
}, |
| 381 |
{ |
| 382 |
"data": "ill_request_id", |
| 383 |
"orderable": false, |
| 384 |
"searchable": false, |
| 385 |
"render": function( data, type, row, meta ) { |
| 386 |
return '<a class="btn btn-default btn-sm" ' + |
| 387 |
'href="/cgi-bin/koha/ill/ill-requests.pl?' + |
| 388 |
'method=illview&illrequest_id=' + |
| 389 |
encodeURIComponent(data) + |
| 390 |
'">' + ill_manage + '</a>'; |
| 391 |
} |
| 392 |
} |
| 393 |
] |
| 394 |
}, table_settings, null, additional_filters); |
| 522 |
|
395 |
|
| 523 |
return placedPassed && modifiedPassed; |
396 |
$("#illfilter_form").on('submit', filter); |
| 524 |
|
397 |
|
| 525 |
}); |
398 |
function redrawTable() { |
|
|
399 |
let table_dt = ill_requests_table.DataTable(); |
| 400 |
table_dt.draw(); |
| 401 |
} |
| 526 |
|
402 |
|
|
|
403 |
function filter() { |
| 404 |
redrawTable(); |
| 405 |
return false; |
| 406 |
} |
| 407 |
|
| 408 |
function clearSearch() { |
| 409 |
let filters = [ |
| 410 |
"illfilter_backend", |
| 411 |
"illfilter_branchname", |
| 412 |
"illfilter_patron", |
| 413 |
"illfilter_keyword", |
| 414 |
]; |
| 415 |
filters.forEach((filter) => { |
| 416 |
$("#"+filter).val(""); |
| 527 |
}); |
417 |
}); |
| 528 |
} //END if window.location.search.length == 0 |
|
|
| 529 |
|
418 |
|
| 530 |
var clearSearch = function() { |
419 |
//Clear flatpickr date filters |
| 531 |
table.api().search('').columns().search(''); |
420 |
$('#illfilter_form > fieldset > ol > li:nth-child(4) > span > a').click(); |
| 532 |
activeFilters = {}; |
421 |
$('#illfilter_form > fieldset > ol > li:nth-child(5) > span > a').click(); |
| 533 |
for (var filter in filterable) { |
422 |
$('#illfilter_form > fieldset > ol > li:nth-child(6) > span > a').click(); |
| 534 |
if ( |
423 |
$('#illfilter_form > fieldset > ol > li:nth-child(7) > span > a').click(); |
| 535 |
filterable.hasOwnProperty(filter) && |
424 |
|
| 536 |
filterable[filter].hasOwnProperty('clear') |
425 |
disableStatusFilter(); |
| 537 |
) { |
426 |
|
| 538 |
filterable[filter].clear(); |
427 |
redrawTable(); |
|
|
428 |
} |
| 429 |
|
| 430 |
function populateStatusFilter(backend) { |
| 431 |
$.ajax({ |
| 432 |
type: "GET", |
| 433 |
url: "/api/v1/ill_backends/"+backend+"/statuses", |
| 434 |
success: function(statuses){ |
| 435 |
$('#illfilter_status').append( |
| 436 |
'<option value="">'+ill_all_statuses+'</option>' |
| 437 |
); |
| 438 |
statuses.sort((a, b) => a.str.localeCompare(b.str)).forEach(function(status) { |
| 439 |
$('#illfilter_status').append( |
| 440 |
'<option value="' + status.code + |
| 441 |
'">' + status.str + '</option>' |
| 442 |
); |
| 443 |
}); |
| 539 |
} |
444 |
} |
| 540 |
} |
445 |
}); |
| 541 |
table.api().draw(); |
446 |
} |
| 542 |
}; |
|
|
| 543 |
|
447 |
|
| 544 |
// Apply any search filters, or clear any previous |
448 |
function populateBackendFilter() { |
| 545 |
// ones |
449 |
$.ajax({ |
| 546 |
$('#illfilter_form').submit(function(event) { |
450 |
type: "GET", |
| 547 |
event.preventDefault(); |
451 |
url: "/api/v1/ill_backends", |
| 548 |
table.api().search('').columns().search(''); |
452 |
success: function(backends){ |
| 549 |
for (var active in activeFilters) { |
453 |
backends.sort((a, b) => a.ill_backend_id.localeCompare(b.ill_backend_id)).forEach(function(backend) { |
| 550 |
if (activeFilters.hasOwnProperty(active)) { |
454 |
$('#illfilter_backend').append( |
| 551 |
activeFilters[active](); |
455 |
'<option value="' + backend.ill_backend_id + |
|
|
456 |
'">' + backend.ill_backend_id + '</option>' |
| 457 |
); |
| 458 |
}); |
| 552 |
} |
459 |
} |
|
|
460 |
}); |
| 461 |
} |
| 462 |
|
| 463 |
function disableStatusFilter() { |
| 464 |
$('#illfilter_status').children().remove(); |
| 465 |
$("#illfilter_status").attr('title', ill_manage_select_backend_first); |
| 466 |
$('#illfilter_status').prop("disabled", true); |
| 467 |
} |
| 468 |
|
| 469 |
function enableStatusFilter() { |
| 470 |
$('#illfilter_status').children().remove(); |
| 471 |
$("#illfilter_status").attr('title', ''); |
| 472 |
$('#illfilter_status').prop("disabled", false); |
| 473 |
} |
| 474 |
|
| 475 |
$('#illfilter_backend').change(function() { |
| 476 |
var selected_backend = $('#illfilter_backend option:selected').val(); |
| 477 |
if (selected_backend && selected_backend.length > 0) { |
| 478 |
populateStatusFilter(selected_backend); |
| 479 |
enableStatusFilter(); |
| 480 |
} else { |
| 481 |
disableStatusFilter(); |
| 553 |
} |
482 |
} |
| 554 |
table.api().draw(); |
|
|
| 555 |
}); |
483 |
}); |
| 556 |
|
484 |
|
|
|
485 |
disableStatusFilter(); |
| 486 |
populateBackendFilter(); |
| 487 |
|
| 557 |
// Clear all filters |
488 |
// Clear all filters |
| 558 |
$('#clear_search').click(function() { |
489 |
$('#clear_search').click(function() { |
| 559 |
clearSearch(); |
490 |
clearSearch(); |
| 560 |
- |
|
|