Lines 10-286
Link Here
|
10 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
10 |
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] |
11 |
[% Asset.css("css/datatables.css") | $raw %] |
11 |
[% Asset.css("css/datatables.css") | $raw %] |
12 |
[% INCLUDE 'datatables.inc' %] |
12 |
[% INCLUDE 'datatables.inc' %] |
13 |
<script type="text/javascript"> |
13 |
[% Asset.js("js/ill-list-table.js") %] |
14 |
//<![CDATA[ |
|
|
15 |
$(document).ready(function() { |
16 |
|
17 |
// Illview Datatable setup |
18 |
|
19 |
// Fields we don't want to display |
20 |
var ignore = [ |
21 |
'accessurl', |
22 |
'backend', |
23 |
'branchcode', |
24 |
'completed', |
25 |
'capabilities', |
26 |
'cost', |
27 |
'medium', |
28 |
'notesopac', |
29 |
'notesstaff', |
30 |
'placed', |
31 |
'replied' |
32 |
]; |
33 |
|
34 |
// Fields we need to expand (flatten) |
35 |
var expand = [ |
36 |
'metadata', |
37 |
'patron' |
38 |
]; |
39 |
|
40 |
// Expanded fields |
41 |
// This is auto populated |
42 |
var expanded = {}; |
43 |
|
44 |
// The core fields that should be displayed first |
45 |
var core = [ |
46 |
'metadata_Author', |
47 |
'metadata_Title', |
48 |
'borrowername', |
49 |
'biblio_id', |
50 |
'library', |
51 |
'status', |
52 |
'updated', |
53 |
'illrequest_id', |
54 |
'action' |
55 |
]; |
56 |
|
57 |
// Remove any fields we're ignoring |
58 |
var removeIgnore = function(dataObj) { |
59 |
dataObj.forEach(function(thisRow) { |
60 |
ignore.forEach(function(thisIgnore) { |
61 |
if (thisRow.hasOwnProperty(thisIgnore)) { |
62 |
delete thisRow[thisIgnore]; |
63 |
} |
64 |
}); |
65 |
}); |
66 |
}; |
67 |
|
68 |
// Expand any fields we're expanding |
69 |
var expandExpand = function(row) { |
70 |
expand.forEach(function(thisExpand) { |
71 |
if (row.hasOwnProperty(thisExpand)) { |
72 |
if (!expanded.hasOwnProperty(thisExpand)) { |
73 |
expanded[thisExpand] = []; |
74 |
} |
75 |
var expandObj = row[thisExpand]; |
76 |
Object.keys(expandObj).forEach( |
77 |
function(thisExpandCol) { |
78 |
var expColName = thisExpand + '_' + thisExpandCol; |
79 |
// Keep a list of fields that have been expanded |
80 |
// so we can create toggle links for them |
81 |
if (expanded[thisExpand].indexOf(expColName) == -1) { |
82 |
expanded[thisExpand].push(expColName); |
83 |
} |
84 |
expandObj[expColName] = |
85 |
expandObj[thisExpandCol]; |
86 |
delete expandObj[thisExpandCol]; |
87 |
} |
88 |
); |
89 |
$.extend(true, row, expandObj); |
90 |
delete row[thisExpand]; |
91 |
} |
92 |
}); |
93 |
}; |
94 |
|
95 |
// Build a de-duped list of all column names |
96 |
var allCols = {}; |
97 |
core.map(function(thisCore) { |
98 |
allCols[thisCore] = 1; |
99 |
}); |
100 |
|
101 |
// Strip the expand prefix if it exists, we do this for display |
102 |
var stripPrefix = function(value) { |
103 |
expand.forEach(function(thisExpand) { |
104 |
var regex = new RegExp(thisExpand + '_', 'g'); |
105 |
value = value.replace(regex, ''); |
106 |
}); |
107 |
return value; |
108 |
}; |
109 |
|
110 |
// Our 'render' function for borrowerlink |
111 |
var createPatronLink = function(data, type, row) { |
112 |
return '<a title="' + _("View borrower details") + '" ' + |
113 |
'href="/cgi-bin/koha/members/moremember.pl?' + |
114 |
'borrowernumber='+row.borrowernumber+'">' + |
115 |
row.patron_firstname + ' ' + row.patron_surname + |
116 |
'</a>'; |
117 |
}; |
118 |
|
119 |
// Our 'render' function for the library name |
120 |
var createLibrary = function(data, type, row) { |
121 |
return row.library.branchname; |
122 |
}; |
123 |
|
124 |
// Render function for request ID |
125 |
var createRequestId = function(data, type, row) { |
126 |
return row.id_prefix + row.illrequest_id; |
127 |
}; |
128 |
|
129 |
// Render function for request status |
130 |
var createStatus = function(data, type, row, meta) { |
131 |
var origData = meta.settings.oInit.originalData; |
132 |
if (origData.length > 0) { |
133 |
var status_name = meta.settings.oInit.originalData[0].capabilities[ |
134 |
row.status |
135 |
].name; |
136 |
switch( status_name ) { |
137 |
case "New request": |
138 |
return _("New request"); |
139 |
case "Requested": |
140 |
return _("Requested"); |
141 |
case "Requested from partners": |
142 |
return _("Requested from partners"); |
143 |
case "Request reverted": |
144 |
return _("Request reverted"); |
145 |
case "Queued request": |
146 |
return _("Queued request"); |
147 |
case "Cancellation requested": |
148 |
return _("Cancellation requested"); |
149 |
case "Completed": |
150 |
return _("Completed"); |
151 |
case "Delete request": |
152 |
return _("Delete request"); |
153 |
default: |
154 |
return status_name; |
155 |
} |
156 |
} else { |
157 |
return ''; |
158 |
} |
159 |
}; |
160 |
|
161 |
// Render function for creating a row's action link |
162 |
var createActionLink = function(data, type, row) { |
163 |
return '<a class="btn btn-default btn-sm" ' + |
164 |
'href="/cgi-bin/koha/ill/ill-requests.pl?' + |
165 |
'method=illview&illrequest_id=' + |
166 |
row.illrequest_id + |
167 |
'">' + _("Manage request") + '</a>'; |
168 |
}; |
169 |
|
170 |
// Columns that require special treatment |
171 |
var specialCols = { |
172 |
action: { |
173 |
name: '', |
174 |
func: createActionLink |
175 |
}, |
176 |
borrowername: { |
177 |
name: _("Patron"), |
178 |
func: createPatronLink |
179 |
}, |
180 |
illrequest_id: { |
181 |
name: _("Request number"), |
182 |
func: createRequestId |
183 |
}, |
184 |
status: { |
185 |
name: _("Status"), |
186 |
func: createStatus |
187 |
}, |
188 |
biblio_id: { |
189 |
name: _("Bibliograpic Record ID") |
190 |
}, |
191 |
library: { |
192 |
name: _("Library"), |
193 |
func: createLibrary |
194 |
} |
195 |
}; |
196 |
|
197 |
// Filter partner list |
198 |
$('#partner_filter').keyup(function() { |
199 |
var needle = $('#partner_filter').val(); |
200 |
$('#partners > option').each(function() { |
201 |
var regex = new RegExp(needle, 'i'); |
202 |
if ( |
203 |
needle.length == 0 || |
204 |
$(this).is(':selected') || |
205 |
$(this).text().match(regex) |
206 |
) { |
207 |
$(this).show(); |
208 |
} else { |
209 |
$(this).hide(); |
210 |
} |
211 |
}); |
212 |
}); |
213 |
|
214 |
// Display the modal containing request supplier metadata |
215 |
$('#ill-request-display-metadata').on('click', function(e) { |
216 |
e.preventDefault(); |
217 |
$('#dataPreview').modal({show:true}); |
218 |
}); |
219 |
|
220 |
// Get our data from the API and process it prior to passing |
221 |
// it to datatables |
222 |
var ajax = $.ajax( |
223 |
'/api/v1/illrequests?embed=metadata,patron,capabilities,library' |
224 |
).done(function() { |
225 |
var data = JSON.parse(ajax.responseText); |
226 |
// Make a copy, we'll be removing columns next and need |
227 |
// to be able to refer to data that has been removed |
228 |
var dataCopy = $.extend(true, [], data); |
229 |
// Remove all columns we're not interested in |
230 |
removeIgnore(dataCopy); |
231 |
// Expand columns that need it and create an array |
232 |
// of all column names |
233 |
$.each(dataCopy, function(k, row) { |
234 |
expandExpand(row); |
235 |
}); |
236 |
|
237 |
// Assemble an array of column definitions for passing |
238 |
// to datatables |
239 |
var colData = []; |
240 |
Object.keys(allCols).forEach(function(thisCol) { |
241 |
// Create the base column object |
242 |
var colObj = { |
243 |
name: thisCol, |
244 |
className: thisCol |
245 |
}; |
246 |
// We may need to process the data going in this |
247 |
// column, so do it if necessary |
248 |
if ( |
249 |
specialCols.hasOwnProperty(thisCol) && |
250 |
specialCols[thisCol].hasOwnProperty('func') |
251 |
) { |
252 |
colObj.render = specialCols[thisCol].func; |
253 |
} else { |
254 |
colObj.data = thisCol; |
255 |
} |
256 |
colData.push(colObj); |
257 |
}); |
258 |
|
259 |
// Initialise the datatable |
260 |
$('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, { |
261 |
'aoColumnDefs': [ // Last column shouldn't be sortable or searchable |
262 |
{ |
263 |
'aTargets': [ 'actions' ], |
264 |
'bSortable': false, |
265 |
'bSearchable': false |
266 |
}, |
267 |
], |
268 |
'aaSorting': [[ 6, 'desc' ]], // Default sort, updated descending |
269 |
'processing': true, // Display a message when manipulating |
270 |
'iDisplayLength': 10, // 10 results per page |
271 |
'sPaginationType': "full_numbers", // Pagination display |
272 |
'deferRender': true, // Improve performance on big datasets |
273 |
'data': dataCopy, |
274 |
'columns': colData, |
275 |
'originalData': data // Enable render functions to access |
276 |
// our original data |
277 |
})); |
278 |
} |
279 |
); |
280 |
|
281 |
}); |
282 |
//]]> |
283 |
</script> |
284 |
</head> |
14 |
</head> |
285 |
|
15 |
|
286 |
<body id="illrequests" class="ill"> |
16 |
<body id="illrequests" class="ill"> |
Lines 597-622
Link Here
|
597 |
[% ELSIF query_type == 'illlist' %] |
327 |
[% ELSIF query_type == 'illlist' %] |
598 |
<!-- illlist --> |
328 |
<!-- illlist --> |
599 |
<h1>View ILL requests</h1> |
329 |
<h1>View ILL requests</h1> |
|
|
330 |
[% prefilter_arr = %] |
600 |
<div id="results"> |
331 |
<div id="results"> |
601 |
<h3>Details for all requests</h3> |
332 |
<h3>Details for all requests</h3> |
602 |
|
333 |
[% INCLUDE 'ill-list-table.inc' %] |
603 |
<table id="ill-requests"> |
|
|
604 |
<thead> |
605 |
<tr id="illview-header"> |
606 |
<th>Author</th> |
607 |
<th>Title</th> |
608 |
<th>Patron</th> |
609 |
<th>Bibliographic record ID</th> |
610 |
<th>Library</th> |
611 |
<th>Status</th> |
612 |
<th>Updated on</th> |
613 |
<th>Request number</th> |
614 |
<th class="actions"></th> |
615 |
</tr> |
616 |
</thead> |
617 |
<tbody id="illview-body"> |
618 |
</tbody> |
619 |
</table> |
620 |
</div> |
334 |
</div> |
621 |
[% ELSE %] |
335 |
[% ELSE %] |
622 |
<!-- Custom Backend Action --> |
336 |
<!-- Custom Backend Action --> |