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