Lines 7-497
Link Here
|
7 |
[% INCLUDE 'doc-head-open.inc' %] |
7 |
[% INCLUDE 'doc-head-open.inc' %] |
8 |
<title>Koha › ILL requests</title> |
8 |
<title>Koha › ILL requests</title> |
9 |
[% INCLUDE 'doc-head-close.inc' %] |
9 |
[% INCLUDE 'doc-head-close.inc' %] |
10 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
|
|
11 |
[% Asset.css("css/datatables.css") | $raw %] |
10 |
[% Asset.css("css/datatables.css") | $raw %] |
12 |
[% INCLUDE 'datatables.inc' %] |
|
|
13 |
[% INCLUDE 'calendar.inc' %] |
14 |
<script type="text/javascript"> |
15 |
//<![CDATA[ |
16 |
$(document).ready(function() { |
17 |
|
18 |
// Illview Datatable setup |
19 |
|
20 |
var table; |
21 |
|
22 |
// Filters that are active |
23 |
var activeFilters = {}; |
24 |
|
25 |
// Fields we don't want to display |
26 |
var ignore = [ |
27 |
'accessurl', |
28 |
'backend', |
29 |
'branchcode', |
30 |
'completed', |
31 |
'capabilities', |
32 |
'cost', |
33 |
'medium', |
34 |
'notesopac', |
35 |
'notesstaff', |
36 |
'replied' |
37 |
]; |
38 |
|
39 |
// Fields we need to expand (flatten) |
40 |
var expand = [ |
41 |
'metadata', |
42 |
'patron' |
43 |
]; |
44 |
|
45 |
// Expanded fields |
46 |
// This is auto populated |
47 |
var expanded = {}; |
48 |
|
49 |
// The core fields that should be displayed first |
50 |
var core = [ |
51 |
'metadata_Author', |
52 |
'metadata_Title', |
53 |
'borrowername', |
54 |
'patron_cardnumber', |
55 |
'biblio_id', |
56 |
'library', |
57 |
'status', |
58 |
'placed', |
59 |
'placed_formatted', |
60 |
'updated', |
61 |
'updated_formatted', |
62 |
'illrequest_id', |
63 |
'action' |
64 |
]; |
65 |
|
66 |
// Filterable columns |
67 |
var filterable = { |
68 |
status: { |
69 |
prep: function(tableData, oData) { |
70 |
var uniques = {}; |
71 |
tableData.forEach(function(row) { |
72 |
var resolvedName = getStatusName( |
73 |
oData[0].capabilities[row.status].name |
74 |
); |
75 |
uniques[resolvedName] = 1 |
76 |
}); |
77 |
Object.keys(uniques).sort().forEach(function(unique) { |
78 |
$('#illfilter_status').append( |
79 |
'<option value="' + unique + |
80 |
'">' + unique + '</option>' |
81 |
); |
82 |
}); |
83 |
}, |
84 |
listener: function() { |
85 |
var me = 'status'; |
86 |
$('#illfilter_status').change(function() { |
87 |
var sel = $('#illfilter_status option:selected').val(); |
88 |
if (sel && sel.length > 0) { |
89 |
activeFilters[me] = function() { |
90 |
table.column(6).search(sel); |
91 |
} |
92 |
} else { |
93 |
if (activeFilters.hasOwnProperty(me)) { |
94 |
delete activeFilters[me]; |
95 |
} |
96 |
} |
97 |
}); |
98 |
}, |
99 |
clear: function() { |
100 |
$('#illfilter_status').val(''); |
101 |
} |
102 |
}, |
103 |
pickupBranch: { |
104 |
prep: function(tableData, oData) { |
105 |
var uniques = {}; |
106 |
tableData.forEach(function(row) { |
107 |
uniques[row.library.branchname] = 1 |
108 |
}); |
109 |
Object.keys(uniques).sort().forEach(function(unique) { |
110 |
$('#illfilter_branchname').append( |
111 |
'<option value="' + unique + |
112 |
'">' + unique + '</option>' |
113 |
); |
114 |
}); |
115 |
}, |
116 |
listener: function() { |
117 |
var me = 'pickupBranch'; |
118 |
$('#illfilter_branchname').change(function() { |
119 |
var sel = $('#illfilter_branchname option:selected').val(); |
120 |
if (sel && sel.length > 0) { |
121 |
activeFilters[me] = function() { |
122 |
table.column(5).search(sel); |
123 |
} |
124 |
} else { |
125 |
if (activeFilters.hasOwnProperty(me)) { |
126 |
delete activeFilters[me]; |
127 |
} |
128 |
} |
129 |
}); |
130 |
}, |
131 |
clear: function() { |
132 |
$('#illfilter_branchname').val(''); |
133 |
} |
134 |
}, |
135 |
barcode: { |
136 |
listener: function() { |
137 |
var me = 'barcode'; |
138 |
$('#illfilter_barcode').change(function() { |
139 |
var val = $('#illfilter_barcode').val(); |
140 |
if (val && val.length > 0) { |
141 |
activeFilters[me] = function() { |
142 |
table.column(3).search(val); |
143 |
} |
144 |
} else { |
145 |
if (activeFilters.hasOwnProperty(me)) { |
146 |
delete activeFilters[me]; |
147 |
} |
148 |
} |
149 |
}); |
150 |
}, |
151 |
clear: function() { |
152 |
$('#illfilter_barcode').val(''); |
153 |
} |
154 |
}, |
155 |
dateModified: { |
156 |
clear: function() { |
157 |
$('#illfilter_datemodified_start, #illfilter_datemodified_end').val(''); |
158 |
} |
159 |
}, |
160 |
datePlaced: { |
161 |
clear: function() { |
162 |
$('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val(''); |
163 |
} |
164 |
} |
165 |
}; |
166 |
|
167 |
// Remove any fields we're ignoring |
168 |
var removeIgnore = function(dataObj) { |
169 |
dataObj.forEach(function(thisRow) { |
170 |
ignore.forEach(function(thisIgnore) { |
171 |
if (thisRow.hasOwnProperty(thisIgnore)) { |
172 |
delete thisRow[thisIgnore]; |
173 |
} |
174 |
}); |
175 |
}); |
176 |
}; |
177 |
|
178 |
// Expand any fields we're expanding |
179 |
var expandExpand = function(row) { |
180 |
expand.forEach(function(thisExpand) { |
181 |
if (row.hasOwnProperty(thisExpand)) { |
182 |
if (!expanded.hasOwnProperty(thisExpand)) { |
183 |
expanded[thisExpand] = []; |
184 |
} |
185 |
var expandObj = row[thisExpand]; |
186 |
Object.keys(expandObj).forEach( |
187 |
function(thisExpandCol) { |
188 |
var expColName = thisExpand + '_' + thisExpandCol; |
189 |
// Keep a list of fields that have been expanded |
190 |
// so we can create toggle links for them |
191 |
if (expanded[thisExpand].indexOf(expColName) == -1) { |
192 |
expanded[thisExpand].push(expColName); |
193 |
} |
194 |
expandObj[expColName] = |
195 |
expandObj[thisExpandCol]; |
196 |
delete expandObj[thisExpandCol]; |
197 |
} |
198 |
); |
199 |
$.extend(true, row, expandObj); |
200 |
delete row[thisExpand]; |
201 |
} |
202 |
}); |
203 |
}; |
204 |
|
205 |
// Build a de-duped list of all column names |
206 |
var allCols = {}; |
207 |
core.map(function(thisCore) { |
208 |
allCols[thisCore] = 1; |
209 |
}); |
210 |
|
211 |
// Strip the expand prefix if it exists, we do this for display |
212 |
var stripPrefix = function(value) { |
213 |
expand.forEach(function(thisExpand) { |
214 |
var regex = new RegExp(thisExpand + '_', 'g'); |
215 |
value = value.replace(regex, ''); |
216 |
}); |
217 |
return value; |
218 |
}; |
219 |
|
220 |
// Our 'render' function for borrowerlink |
221 |
var createPatronLink = function(data, type, row) { |
222 |
return '<a title="' + _("View borrower details") + '" ' + |
223 |
'href="/cgi-bin/koha/members/moremember.pl?' + |
224 |
'borrowernumber='+row.borrowernumber+'">' + |
225 |
row.patron_firstname + ' ' + row.patron_surname + |
226 |
'</a>'; |
227 |
}; |
228 |
|
229 |
// Our 'render' function for the library name |
230 |
var createLibrary = function(data, type, row) { |
231 |
return row.library.branchname; |
232 |
}; |
233 |
|
234 |
// Render function for request ID |
235 |
var createRequestId = function(data, type, row) { |
236 |
return row.id_prefix + row.illrequest_id; |
237 |
}; |
238 |
|
239 |
// Render function for request status |
240 |
var createStatus = function(data, type, row, meta) { |
241 |
var origData = meta.settings.oInit.originalData; |
242 |
if (origData.length > 0) { |
243 |
var status_name = meta.settings.oInit.originalData[0].capabilities[ |
244 |
row.status |
245 |
].name; |
246 |
return getStatusName(status_name); |
247 |
} else { |
248 |
return ''; |
249 |
} |
250 |
}; |
251 |
|
252 |
var getStatusName = function(origName) { |
253 |
switch( origName ) { |
254 |
case "New request": |
255 |
return _("New request"); |
256 |
case "Requested": |
257 |
return _("Requested"); |
258 |
case "Requested from partners": |
259 |
return _("Requested from partners"); |
260 |
case "Request reverted": |
261 |
return _("Request reverted"); |
262 |
case "Queued request": |
263 |
return _("Queued request"); |
264 |
case "Cancellation requested": |
265 |
return _("Cancellation requested"); |
266 |
case "Completed": |
267 |
return _("Completed"); |
268 |
case "Delete request": |
269 |
return _("Delete request"); |
270 |
default: |
271 |
return origName; |
272 |
} |
273 |
}; |
274 |
|
275 |
// Render function for creating a row's action link |
276 |
var createActionLink = function(data, type, row) { |
277 |
return '<a class="btn btn-default btn-sm" ' + |
278 |
'href="/cgi-bin/koha/ill/ill-requests.pl?' + |
279 |
'method=illview&illrequest_id=' + |
280 |
row.illrequest_id + |
281 |
'">' + _("Manage request") + '</a>'; |
282 |
}; |
283 |
|
284 |
// Columns that require special treatment |
285 |
var specialCols = { |
286 |
action: { |
287 |
name: '', |
288 |
func: createActionLink |
289 |
}, |
290 |
borrowername: { |
291 |
name: _("Patron"), |
292 |
func: createPatronLink |
293 |
}, |
294 |
illrequest_id: { |
295 |
name: _("Request number"), |
296 |
func: createRequestId |
297 |
}, |
298 |
status: { |
299 |
name: _("Status"), |
300 |
func: createStatus |
301 |
}, |
302 |
biblio_id: { |
303 |
name: _("Bibliograpic Record ID") |
304 |
}, |
305 |
library: { |
306 |
name: _("Library"), |
307 |
func: createLibrary |
308 |
}, |
309 |
updated: { |
310 |
name: _("Updated on"), |
311 |
}, |
312 |
patron_cardnumber: { |
313 |
name: _("Patron barcode") |
314 |
} |
315 |
}; |
316 |
|
317 |
// Filter partner list |
318 |
$('#partner_filter').keyup(function() { |
319 |
var needle = $('#partner_filter').val(); |
320 |
$('#partners > option').each(function() { |
321 |
var regex = new RegExp(needle, 'i'); |
322 |
if ( |
323 |
needle.length == 0 || |
324 |
$(this).is(':selected') || |
325 |
$(this).text().match(regex) |
326 |
) { |
327 |
$(this).show(); |
328 |
} else { |
329 |
$(this).hide(); |
330 |
} |
331 |
}); |
332 |
}); |
333 |
|
334 |
// Display the modal containing request supplier metadata |
335 |
$('#ill-request-display-metadata').on('click', function(e) { |
336 |
e.preventDefault(); |
337 |
$('#dataPreview').modal({show:true}); |
338 |
}); |
339 |
|
340 |
// Get our data from the API and process it prior to passing |
341 |
// it to datatables |
342 |
var ajax = $.ajax( |
343 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library' |
344 |
).done(function() { |
345 |
var data = JSON.parse(ajax.responseText); |
346 |
// Make a copy, we'll be removing columns next and need |
347 |
// to be able to refer to data that has been removed |
348 |
var dataCopy = $.extend(true, [], data); |
349 |
// Remove all columns we're not interested in |
350 |
removeIgnore(dataCopy); |
351 |
// Expand columns that need it and create an array |
352 |
// of all column names |
353 |
$.each(dataCopy, function(k, row) { |
354 |
expandExpand(row); |
355 |
}); |
356 |
|
357 |
// Assemble an array of column definitions for passing |
358 |
// to datatables |
359 |
var colData = []; |
360 |
Object.keys(allCols).forEach(function(thisCol) { |
361 |
// Create the base column object |
362 |
var colObj = { |
363 |
name: thisCol, |
364 |
className: thisCol, |
365 |
defaultContent: '' |
366 |
}; |
367 |
// We may need to process the data going in this |
368 |
// column, so do it if necessary |
369 |
if ( |
370 |
specialCols.hasOwnProperty(thisCol) && |
371 |
specialCols[thisCol].hasOwnProperty('func') |
372 |
) { |
373 |
colObj.render = specialCols[thisCol].func; |
374 |
} else { |
375 |
colObj.data = thisCol; |
376 |
} |
377 |
colData.push(colObj); |
378 |
}); |
379 |
|
380 |
// Initialise the datatable |
381 |
table = $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, { |
382 |
'aoColumnDefs': [ |
383 |
{ // Last column shouldn't be sortable or searchable |
384 |
'aTargets': [ 'actions' ], |
385 |
'bSortable': false, |
386 |
'bSearchable': false |
387 |
}, |
388 |
{ // Hide the two date columns we use just for sorting |
389 |
'aTargets': [ 'placed', 'updated' ], |
390 |
'bVisible': false, |
391 |
'bSearchable': true |
392 |
}, |
393 |
{ // When sorting 'placed', we want to use the |
394 |
// unformatted column |
395 |
'aTargets': [ 'placed_formatted'], |
396 |
'iDataSort': 7 |
397 |
}, |
398 |
{ // When sorting 'updated', we want to use the |
399 |
// unformatted column |
400 |
'aTargets': [ 'updated_formatted'], |
401 |
'iDataSort': 9 |
402 |
} |
403 |
], |
404 |
'aaSorting': [[ 9, 'desc' ]], // Default sort, updated descending |
405 |
'processing': true, // Display a message when manipulating |
406 |
'iDisplayLength': 10, // 10 results per page |
407 |
'sPaginationType': "full_numbers", // Pagination display |
408 |
'deferRender': true, // Improve performance on big datasets |
409 |
'data': dataCopy, |
410 |
'columns': colData, |
411 |
'originalData': data, // Enable render functions to access |
412 |
// our original data |
413 |
'initComplete': function() { |
414 |
|
415 |
// Prepare any filter elements that need it |
416 |
for (var el in filterable) { |
417 |
if (filterable.hasOwnProperty(el)) { |
418 |
if (filterable[el].hasOwnProperty('prep')) { |
419 |
filterable[el].prep(dataCopy, data); |
420 |
} |
421 |
if (filterable[el].hasOwnProperty('listener')) { |
422 |
filterable[el].listener(); |
423 |
} |
424 |
} |
425 |
} |
426 |
|
427 |
} |
428 |
})); |
429 |
|
430 |
// Custom date range filtering |
431 |
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) { |
432 |
var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate'); |
433 |
var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate'); |
434 |
var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate'); |
435 |
var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate'); |
436 |
var rowPlaced = data[7] ? new Date(data[7]) : null; |
437 |
var rowModified = data[9] ? new Date(data[9]) : null; |
438 |
var placedPassed = true; |
439 |
var modifiedPassed = true; |
440 |
if (placedStart && rowPlaced && rowPlaced < placedStart) { |
441 |
placedPassed = false |
442 |
}; |
443 |
if (placedEnd && rowPlaced && rowPlaced > placedEnd) { |
444 |
placedPassed = false; |
445 |
} |
446 |
if (modifiedStart && rowModified && rowModified < modifiedStart) { |
447 |
modifiedPassed = false |
448 |
}; |
449 |
if (modifiedEnd && rowModified && rowModified > modifiedEnd) { |
450 |
modifiedPassed = false; |
451 |
} |
452 |
|
453 |
return placedPassed && modifiedPassed; |
454 |
|
455 |
}); |
456 |
|
457 |
} |
458 |
); |
459 |
|
460 |
var clearSearch = function() { |
461 |
table.search('').columns().search(''); |
462 |
activeFilters = {}; |
463 |
for (var filter in filterable) { |
464 |
if ( |
465 |
filterable.hasOwnProperty(filter) && |
466 |
filterable[filter].hasOwnProperty('clear') |
467 |
) { |
468 |
filterable[filter].clear(); |
469 |
} |
470 |
} |
471 |
table.draw(); |
472 |
}; |
473 |
|
474 |
// Apply any search filters, or clear any previous |
475 |
// ones |
476 |
$('#illfilter_form').submit(function(event) { |
477 |
event.preventDefault(); |
478 |
table.search('').columns().search(''); |
479 |
for (var active in activeFilters) { |
480 |
if (activeFilters.hasOwnProperty(active)) { |
481 |
activeFilters[active](); |
482 |
} |
483 |
} |
484 |
table.draw(); |
485 |
}); |
486 |
|
487 |
// Clear all filters |
488 |
$('#clear_search').click(function() { |
489 |
clearSearch(); |
490 |
}); |
491 |
|
492 |
}); |
493 |
//]]> |
494 |
</script> |
495 |
</head> |
11 |
</head> |
496 |
|
12 |
|
497 |
<body id="illrequests" class="ill"> |
13 |
<body id="illrequests" class="ill"> |
Lines 899-904
Link Here
|
899 |
[% MACRO jsinclude BLOCK %] |
415 |
[% MACRO jsinclude BLOCK %] |
900 |
[% INCLUDE 'datatables.inc' %] |
416 |
[% INCLUDE 'datatables.inc' %] |
901 |
[% INCLUDE 'calendar.inc' %] |
417 |
[% INCLUDE 'calendar.inc' %] |
|
|
418 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
902 |
<script> |
419 |
<script> |
903 |
$(document).ready(function() { |
420 |
$(document).ready(function() { |
904 |
|
421 |
|
Lines 1187-1193
Link Here
|
1187 |
func: createStatus |
704 |
func: createStatus |
1188 |
}, |
705 |
}, |
1189 |
biblio_id: { |
706 |
biblio_id: { |
1190 |
name: _("Biblio ID") |
707 |
name: _("Bibliograpic Record ID") |
1191 |
}, |
708 |
}, |
1192 |
library: { |
709 |
library: { |
1193 |
name: _("Library"), |
710 |
name: _("Library"), |
1194 |
- |
|
|