[% USE Branches %]
[% USE Koha %]
[% USE KohaDates %]
+[% SET footerjs = 1 %]
+[% USE AuthorisedValues %]
+[% USE ColumnsSettings %]
[% INCLUDE 'doc-head-open.inc' %]
-<title>Koha › ILL requests ›</title>
+<title>Koha › ILL requests</title>
[% INCLUDE 'doc-head-close.inc' %]
-[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
-[% Asset.css("css/datatables.css") | $raw %]
-[% INCLUDE 'datatables.inc' %]
-[% INCLUDE 'calendar.inc' %]
-<script type="text/javascript">
- //<![CDATA[
- $(document).ready(function() {
-
- // Illview Datatable setup
-
- var table;
-
- // Filters that are active
- var activeFilters = {};
-
- // Fields we don't want to display
- var ignore = [
- 'accessurl',
- 'backend',
- 'branchcode',
- 'completed',
- 'capabilities',
- 'cost',
- 'medium',
- 'notesopac',
- 'notesstaff',
- 'replied'
- ];
-
- // Fields we need to expand (flatten)
- var expand = [
- 'metadata',
- 'patron'
- ];
-
- // Expanded fields
- // This is auto populated
- var expanded = {};
-
- // The core fields that should be displayed first
- var core = [
- 'metadata_author',
- 'metadata_title',
- 'borrowername',
- 'patron_cardnumber',
- 'biblio_id',
- 'library',
- 'status',
- 'placed',
- 'placed_formatted',
- 'updated',
- 'updated_formatted',
- 'illrequest_id',
- 'comments',
- 'action' // Action should always be last
- ];
-
- // Filterable columns
- var filterable = {
- status: {
- prep: function(tableData, oData) {
- var uniques = {};
- tableData.forEach(function(row) {
- var resolvedName = getStatusName(
- oData[0].capabilities[row.status].name
- );
- uniques[resolvedName] = 1
- });
- Object.keys(uniques).sort().forEach(function(unique) {
- $('#illfilter_status').append(
- '<option value="' + unique +
- '">' + unique + '</option>'
- );
- });
- },
- listener: function() {
- var me = 'status';
- $('#illfilter_status').change(function() {
- var sel = $('#illfilter_status option:selected').val();
- if (sel && sel.length > 0) {
- activeFilters[me] = function() {
- table.column(6).search(sel);
- }
- } else {
- if (activeFilters.hasOwnProperty(me)) {
- delete activeFilters[me];
- }
- }
- });
- },
- clear: function() {
- $('#illfilter_status').val('');
- }
- },
- pickupBranch: {
- prep: function(tableData, oData) {
- var uniques = {};
- tableData.forEach(function(row) {
- uniques[row.library.branchname] = 1
- });
- Object.keys(uniques).sort().forEach(function(unique) {
- $('#illfilter_branchname').append(
- '<option value="' + unique +
- '">' + unique + '</option>'
- );
- });
- },
- listener: function() {
- var me = 'pickupBranch';
- $('#illfilter_branchname').change(function() {
- var sel = $('#illfilter_branchname option:selected').val();
- if (sel && sel.length > 0) {
- activeFilters[me] = function() {
- table.column(5).search(sel);
- }
- } else {
- if (activeFilters.hasOwnProperty(me)) {
- delete activeFilters[me];
- }
- }
- });
- },
- clear: function() {
- $('#illfilter_branchname').val('');
- }
- },
- barcode: {
- listener: function() {
- var me = 'barcode';
- $('#illfilter_barcode').change(function() {
- var val = $('#illfilter_barcode').val();
- if (val && val.length > 0) {
- activeFilters[me] = function() {
- table.column(3).search(val);
- }
- } else {
- if (activeFilters.hasOwnProperty(me)) {
- delete activeFilters[me];
- }
- }
- });
- },
- clear: function() {
- $('#illfilter_barcode').val('');
- }
- },
- dateModified: {
- clear: function() {
- $('#illfilter_datemodified_start, #illfilter_datemodified_end').val('');
- }
- },
- datePlaced: {
- clear: function() {
- $('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val('');
- }
- }
- };
-
- // Remove any fields we're ignoring
- var removeIgnore = function(dataObj) {
- dataObj.forEach(function(thisRow) {
- ignore.forEach(function(thisIgnore) {
- if (thisRow.hasOwnProperty(thisIgnore)) {
- delete thisRow[thisIgnore];
- }
- });
- });
- };
-
- // Expand any fields we're expanding
- var expandExpand = function(row) {
- expand.forEach(function(thisExpand) {
- if (row.hasOwnProperty(thisExpand)) {
- if (!expanded.hasOwnProperty(thisExpand)) {
- expanded[thisExpand] = [];
- }
- var expandObj = row[thisExpand];
- Object.keys(expandObj).forEach(
- function(thisExpandCol) {
- var expColName = thisExpand + '_' + thisExpandCol;
- // Keep a list of fields that have been expanded
- // so we can create toggle links for them
- if (expanded[thisExpand].indexOf(expColName) == -1) {
- expanded[thisExpand].push(expColName);
- }
- expandObj[expColName] =
- expandObj[thisExpandCol];
- delete expandObj[thisExpandCol];
- }
- );
- $.extend(true, row, expandObj);
- delete row[thisExpand];
- }
- });
- };
-
- // Build a de-duped list of all column names
- var allCols = {};
- core.map(function(thisCore) {
- allCols[thisCore] = 1;
- });
-
- // Strip the expand prefix if it exists, we do this for display
- var stripPrefix = function(value) {
- expand.forEach(function(thisExpand) {
- var regex = new RegExp(thisExpand + '_', 'g');
- value = value.replace(regex, '');
- });
- return value;
- };
-
- // Our 'render' function for borrowerlink
- var createPatronLink = function(data, type, row) {
- var patronLink = '<a title="' + _("View borrower details") + '" ' +
- 'href="/cgi-bin/koha/members/moremember.pl?' +
- 'borrowernumber='+row.borrowernumber+'">';
- if ( row.patron_firstname ) {
- patronLink = patronLink + row.patron_firstname + ' ';
- }
- patronLink = patronLink + row.patron_surname + '</a>';
- return patronLink
- };
-
- // Our 'render' function for biblio_id
- var createBiblioLink = function(data, type, row) {
- return (row.biblio_id) ?
- '<a title="' + _("View biblio details") + '" ' +
- 'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' +
- row.biblio_id + '">' +
- row.biblio_id +
- '</a>' : '';
- };
-
- // Our 'render' function for the library name
- var createLibrary = function(data, type, row) {
- return row.library.branchname;
- };
-
- // Render function for request ID
- var createRequestId = function(data, type, row) {
- return row.id_prefix + row.illrequest_id;
- };
-
- // Render function for request status
- var createStatus = function(data, type, row, meta) {
- var origData = meta.settings.oInit.originalData;
- if (origData.length > 0) {
- var status_name = meta.settings.oInit.originalData[0].capabilities[
- row.status
- ].name;
- return getStatusName(status_name);
- } else {
- return '';
- }
- };
-
- var getStatusName = function(origName) {
- switch( origName ) {
- case "New request":
- return _("New request");
- case "Requested":
- return _("Requested");
- case "Requested from partners":
- return _("Requested from partners");
- case "Request reverted":
- return _("Request reverted");
- case "Queued request":
- return _("Queued request");
- case "Cancellation requested":
- return _("Cancellation requested");
- case "Completed":
- return _("Completed");
- case "Delete request":
- return _("Delete request");
- default:
- return origName;
- }
- };
-
- // Render function for creating a row's action link
- var createActionLink = function(data, type, row) {
- return '<a class="btn btn-default btn-sm" ' +
- 'href="/cgi-bin/koha/ill/ill-requests.pl?' +
- 'method=illview&illrequest_id=' +
- row.illrequest_id +
- '">' + _("Manage request") + '</a>';
- };
-
- // Columns that require special treatment
- var specialCols = {
- action: {
- name: '',
- func: createActionLink
- },
- borrowername: {
- name: _("Patron"),
- func: createPatronLink
- },
- illrequest_id: {
- name: _("Request number"),
- func: createRequestId
- },
- status: {
- name: _("Status"),
- func: createStatus
- },
- biblio_id: {
- name: _("Bibliographic record ID"),
- func: createBiblioLink
- },
- library: {
- name: _("Library"),
- func: createLibrary
- },
- updated: {
- name: _("Updated on"),
- },
- patron_cardnumber: {
- name: _("Patron barcode")
- }
- };
-
- // Toggle request attributes in Illview
- $('#toggle_requestattributes').on('click', function(e) {
- e.preventDefault();
- $('#requestattributes').toggleClass('content_hidden');
- });
-
- // Toggle new comment form in Illview
- $('#toggle_addcomment').on('click', function(e) {
- e.preventDefault();
- $('#addcomment').toggleClass('content_hidden');
- });
-
- // Filter partner list
- $('#partner_filter').keyup(function() {
- var needle = $('#partner_filter').val();
- $('#partners > option').each(function() {
- var regex = new RegExp(needle, 'i');
- if (
- needle.length == 0 ||
- $(this).is(':selected') ||
- $(this).text().match(regex)
- ) {
- $(this).show();
- } else {
- $(this).hide();
- }
- });
- });
-
- // Display the modal containing request supplier metadata
- $('#ill-request-display-metadata').on('click', function(e) {
- e.preventDefault();
- $('#dataPreview').modal({show:true});
- });
-
- // Get our data from the API and process it prior to passing
- // it to datatables
- var ajax = $.ajax(
- '/api/v1/illrequests?embed=metadata,patron,capabilities,library,comments'
- ).done(function() {
- var data = JSON.parse(ajax.responseText);
- // Make a copy, we'll be removing columns next and need
- // to be able to refer to data that has been removed
- var dataCopy = $.extend(true, [], data);
- // Remove all columns we're not interested in
- removeIgnore(dataCopy);
- // Expand columns that need it and create an array
- // of all column names
- $.each(dataCopy, function(k, row) {
- expandExpand(row);
- });
-
- // Assemble an array of column definitions for passing
- // to datatables
- var colData = [];
- Object.keys(allCols).forEach(function(thisCol) {
- // Create the base column object
- var colObj = {
- name: thisCol,
- className: thisCol,
- defaultContent: ''
- };
- // We may need to process the data going in this
- // column, so do it if necessary
- if (
- specialCols.hasOwnProperty(thisCol) &&
- specialCols[thisCol].hasOwnProperty('func')
- ) {
- colObj.render = specialCols[thisCol].func;
- } else {
- colObj.data = thisCol;
- }
- colData.push(colObj);
- });
-
- // Initialise the datatable
- table = $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, {
- 'aoColumnDefs': [
- { // Last column shouldn't be sortable or searchable
- 'aTargets': [ 'actions' ],
- 'bSortable': false,
- 'bSearchable': false
- },
- { // Hide the two date columns we use just for sorting
- 'aTargets': [ 'placed', 'updated' ],
- 'bVisible': false,
- 'bSearchable': true
- },
- { // When sorting 'placed', we want to use the
- // unformatted column
- 'aTargets': [ 'placed_formatted'],
- 'iDataSort': 7
- },
- { // When sorting 'updated', we want to use the
- // unformatted column
- 'aTargets': [ 'updated_formatted'],
- 'iDataSort': 9
- }
- ],
- 'aaSorting': [[ 9, 'desc' ]], // Default sort, updated descending
- 'processing': true, // Display a message when manipulating
- 'iDisplayLength': 10, // 10 results per page
- 'sPaginationType': "full_numbers", // Pagination display
- 'deferRender': true, // Improve performance on big datasets
- 'data': dataCopy,
- 'columns': colData,
- 'originalData': data, // Enable render functions to access
- // our original data
- 'initComplete': function() {
-
- // Prepare any filter elements that need it
- for (var el in filterable) {
- if (filterable.hasOwnProperty(el)) {
- if (filterable[el].hasOwnProperty('prep')) {
- filterable[el].prep(dataCopy, data);
- }
- if (filterable[el].hasOwnProperty('listener')) {
- filterable[el].listener();
- }
- }
- }
-
- }
- }));
-
- // Custom date range filtering
- $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
- var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate');
- var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate');
- var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate');
- var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate');
- var rowPlaced = data[7] ? new Date(data[7]) : null;
- var rowModified = data[9] ? new Date(data[9]) : null;
- var placedPassed = true;
- var modifiedPassed = true;
- if (placedStart && rowPlaced && rowPlaced < placedStart) {
- placedPassed = false
- };
- if (placedEnd && rowPlaced && rowPlaced > placedEnd) {
- placedPassed = false;
- }
- if (modifiedStart && rowModified && rowModified < modifiedStart) {
- modifiedPassed = false
- };
- if (modifiedEnd && rowModified && rowModified > modifiedEnd) {
- modifiedPassed = false;
- }
-
- return placedPassed && modifiedPassed;
-
- });
-
- }
- );
-
- var clearSearch = function() {
- table.search('').columns().search('');
- activeFilters = {};
- for (var filter in filterable) {
- if (
- filterable.hasOwnProperty(filter) &&
- filterable[filter].hasOwnProperty('clear')
- ) {
- filterable[filter].clear();
- }
- }
- table.draw();
- };
-
- // Apply any search filters, or clear any previous
- // ones
- $('#illfilter_form').submit(function(event) {
- event.preventDefault();
- table.search('').columns().search('');
- for (var active in activeFilters) {
- if (activeFilters.hasOwnProperty(active)) {
- activeFilters[active]();
- }
- }
- table.draw();
- });
-
- // Clear all filters
- $('#clear_search').click(function() {
- clearSearch();
- });
-
- });
- //]]>
-</script>
</head>
<body id="illrequests" class="ill">
</li>
<li>
<label for="illfilter_dateplaced_start">Date placed between:</label>
- <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker">
+ <input type="text" name="illfilter_dateplaced_start" id="illfilter_dateplaced_start" class="datepicker" />
</li>
<li>
<label for="illfilter_dateplaced_end">and:</label>
- <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker">
+ <input type="text" name="illfilter_dateplaced_end" id="illfilter_dateplaced_end" class="datepicker" />
</li>
<li>
<label for="illfilter_datemodified_start">Updated between:</label>
- <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker">
+ <input type="text" name="illfilter_datemodified_start" id="illfilter_datemodified_start" class="datepicker" />
</li>
<li>
<label for="illfilter_datemodified_end">and:</label>
- <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker">
+ <input type="text" name="illfilter_datemodified_end" id="illfilter_datemodified_end" class="datepicker" />
</li>
<li>
<label for="illfilter_branchname">Library:</label>
</select>
</li>
<li>
- <label for="illfilter_barcode">Patron barcode:</label>
- <input type="text" name="illfilter_barcode" id="illfilter_barcode">
+ <label for="illfilter_patron">Patron:</label>
+ <input type="text" name="illfilter_patron" id="illfilter_patron" />
</li>
</ol>
<fieldset class="action">
<ol>
<li>
<label for="partner_filter">Filter partner libraries:</label>
- <input type="text" id="partner_filter">
+ <input type="text" id="partner_filter" />
</li>
<li>
<label for="partners" class="required">Select partner libraries:</label>
</li>
<li>
- <label for="subject" class="required">Subject Line</label>
+ <label for="subject" class="required">Subject line:</label>
<input type="text" name="subject" id="subject" type="text" value="[% whole.value.draft.subject | html %]" required="required" />
</li>
<li>
<li class="status">
<label class="status">Status:</label>
[% stat = request.status %]
- [% request.capabilities.$stat.name | html %]
+ [% current_alias = request.status_alias %]
+ <select id="status_alias" name="status_alias">
+ [% IF !current_alias %]
+ <option value="" selected>
+ [% ELSE %]
+ <option value="">
+ [% END %]
+ [% request.capabilities.$stat.name | html %]
+ </option>
+ [% FOREACH alias IN AuthorisedValues.Get('ILLSTATUS') %]
+ [% IF alias.authorised_value == current_alias %]
+ <option value="[% alias.authorised_value | html %]" selected>
+ [% ELSE %]
+ <option value="[% alias.authorised_value | html %]">
+ [% END %]
+ [% alias.lib | html %]
+ </option>
+ [% END %]
+ </select>
</li>
<li class="updated">
<label class="updated">Last updated:</label>
<span class="fa fa-eye"></span>
Display supplier metadata
</a>
+ <a title="ILL request log" id="ill-request-display-log" class="btn btn-sm btn-default pull-right" href="#">
+ <span class="fa fa-calendar"></span>
+ ILL request log
+ </a>
</div>
<div class="ill-view-panel panel panel-default">
<div class="panel-heading">
</li>
<li class="status">
<span class="label status">Status:</span>
- [% request.capabilities.$req_status.name | html %]
+ [% IF request.statusalias %]
+ [% request.statusalias.lib | html %]
+ [% ELSE %]
+ [% request.capabilities.$req_status.name | html%]
+ [% END %]
</li>
<li class="updated">
<span class="label updated">Last updated:</span>
</div>
</div>
+ <div id="requestLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="dataPreviewLabel" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
+ <h3 id="requestLogLabel"> Request log</h3>
+ </div>
+ <div class="modal-body">
+ [% IF request.logs.size > 0 %]
+ [% FOREACH log IN request.logs %]
+ [% tpl = log.template %]
+ [% INCLUDE $tpl log=log %]
+ [% END %]
+ [% ELSE %]
+ There are no recorded logs for this request
+ [% END %]
+ </div>
+ <div class="modal-footer">
+ <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Close</button>
+ </div>
+ </div>
+ </div>
+ </div>
+
<div class="ill-view-panel panel panel-default">
<div class="panel-heading">
<h3>[% request.illcomments.count | html %] comments</h3>
</form>
</div>
</div>
- </div>
+ </div>
</div>
[% ELSIF query_type == 'illlist' %]
<table id="ill-requests">
<thead>
<tr id="illview-header">
- <th>Author</th>
- <th>Title</th>
- <th>Patron</th>
- <th>Bibliographic record ID</th>
- <th>Library</th>
- <th>Status</th>
- <th class="placed"> </th>
- <th class="placed_formatted">Date placed</th>
- <th class="updated"> </th>
- <th class="updated_formatted">Updated on</th>
- <th>Request number</th>
- <th>Comments</th>
- <th class="actions"></th>
+ <th scope="col">Request ID</th>
+ <th scope="col">Author</th>
+ <th scope="col">Title</th>
+ <th scope="col">Article title</th>
+ <th scope="col">Issue</th>
+ <th scope="col">Volume</th>
+ <th scope="col">Year</th>
+ <th scope="col">Pages</th>
+ <th scope="col">Type</th>
+ <th scope="col">Order ID</th>
+ <th scope="col">Patron</th>
+ <th scope="col">Bibliographic record</th>
+ <th scope="col">Branch</th>
+ <th scope="col">Status</th>
+ <th scope="col" class="placed"> </th>
+ <th scope="col" class="placed_formatted">Placed on</th>
+ <th scope="col" class="updated"> </th>
+ <th scope="col" class="updated_formatted">Updated on</th>
+ <th scope="col">Replied</th>
+ <th scope="col" class="completed"> </th>
+ <th scope="col" class="completed_formatted">Completed on</th>
+ <th scope="col">Access URL</th>
+ <th scope="col">Cost</th>
+ <th scope="col">Comments</th>
+ <th scope="col">OPAC notes</th>
+ <th scope="col">Staff notes</th>
+ <th scope="col">Backend</th>
+ <th scope="col" class="actions"></th>
</tr>
</thead>
<tbody id="illview-body">
[% CATCH %]
[% END %]
+[% MACRO jsinclude BLOCK %]
+ [% INCLUDE 'datatables.inc' %]
+ [% INCLUDE 'columns_settings.inc' %]
+ [% INCLUDE 'calendar.inc' %]
+ [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
+ <script>
+ $(document).ready(function() {
+
+ // Illview Datatable setup
+
+ var columns_settings = [% ColumnsSettings.GetColumns( 'illrequests', 'ill-requests', 'ill-requests', 'json' ) %];
+
+ var table;
+
+ // Filters that are active
+ var activeFilters = {};
+
+ // Fields we need to expand (flatten)
+ var expand = [
+ 'metadata',
+ 'patron',
+ 'library'
+ ];
+
+ // Expanded fields
+ // This is auto populated
+ var expanded = {};
+
+ // Filterable columns
+ var filterable = {
+ status: {
+ prep: function(tableData, oData) {
+ var uniques = {};
+ tableData.forEach(function(row) {
+ var resolvedName;
+ if (row.status_alias) {
+ resolvedName = row.status_alias.lib;
+ } else {
+ resolvedName = getStatusName(
+ oData[0].capabilities[row.status].name
+ );
+ }
+ uniques[resolvedName] = 1
+ });
+ Object.keys(uniques).sort().forEach(function(unique) {
+ $('#illfilter_status').append(
+ '<option value="' + unique +
+ '">' + unique + '</option>'
+ );
+ });
+ },
+ listener: function() {
+ var me = 'status';
+ $('#illfilter_status').change(function() {
+ var sel = $('#illfilter_status option:selected').val();
+ if (sel && sel.length > 0) {
+ activeFilters[me] = function() {
+ table.api().column(13).search(sel);
+ }
+ } else {
+ if (activeFilters.hasOwnProperty(me)) {
+ delete activeFilters[me];
+ }
+ }
+ });
+ },
+ clear: function() {
+ $('#illfilter_status').val('');
+ }
+ },
+ pickupBranch: {
+ prep: function(tableData, oData) {
+ var uniques = {};
+ tableData.forEach(function(row) {
+ uniques[row.library_branchname] = 1
+ });
+ Object.keys(uniques).sort().forEach(function(unique) {
+ $('#illfilter_branchname').append(
+ '<option value="' + unique +
+ '">' + unique + '</option>'
+ );
+ });
+ },
+ listener: function() {
+ var me = 'pickupBranch';
+ $('#illfilter_branchname').change(function() {
+ var sel = $('#illfilter_branchname option:selected').val();
+ if (sel && sel.length > 0) {
+ activeFilters[me] = function() {
+ table.api().column(12).search(sel);
+ }
+ } else {
+ if (activeFilters.hasOwnProperty(me)) {
+ delete activeFilters[me];
+ }
+ }
+ });
+ },
+ clear: function() {
+ $('#illfilter_branchname').val('');
+ }
+ },
+ patron: {
+ listener: function() {
+ var me = 'patron';
+ $('#illfilter_patron').change(function() {
+ var val = $('#illfilter_patron').val();
+ if (val && val.length > 0) {
+ activeFilters[me] = function() {
+ table.api().column(10).search(val);
+ }
+ } else {
+ if (activeFilters.hasOwnProperty(me)) {
+ delete activeFilters[me];
+ }
+ }
+ });
+ },
+ clear: function() {
+ $('#illfilter_patron').val('');
+ }
+ },
+ dateModified: {
+ clear: function() {
+ $('#illfilter_datemodified_start, #illfilter_datemodified_end').val('');
+ }
+ },
+ datePlaced: {
+ clear: function() {
+ $('#illfilter_dateplaced_start, #illfilter_dateplaced_end').val('');
+ }
+ }
+ };
+
+ // Expand any fields we're expanding
+ var expandExpand = function(row) {
+ expand.forEach(function(thisExpand) {
+ if (row.hasOwnProperty(thisExpand)) {
+ if (!expanded.hasOwnProperty(thisExpand)) {
+ expanded[thisExpand] = [];
+ }
+ var expandObj = row[thisExpand];
+ Object.keys(expandObj).forEach(
+ function(thisExpandCol) {
+ var expColName = thisExpand + '_' + thisExpandCol.replace(/\s/g,'_');
+ // Keep a list of fields that have been expanded
+ // so we can create toggle links for them
+ if (expanded[thisExpand].indexOf(expColName) == -1) {
+ expanded[thisExpand].push(expColName);
+ }
+ expandObj[expColName] =
+ expandObj[thisExpandCol];
+ delete expandObj[thisExpandCol];
+ }
+ );
+ $.extend(true, row, expandObj);
+ delete row[thisExpand];
+ }
+ });
+ };
+
+ // Strip the expand prefix if it exists, we do this for display
+ var stripPrefix = function(value) {
+ expand.forEach(function(thisExpand) {
+ var regex = new RegExp(thisExpand + '_', 'g');
+ value = value.replace(regex, '');
+ });
+ return value;
+ };
+
+ // Our 'render' function for borrowerlink
+ var createPatronLink = function(data, type, row) {
+ var patronLink = '<a title="' + _("View borrower details") + '" ' +
+ 'href="/cgi-bin/koha/members/moremember.pl?' +
+ 'borrowernumber='+row.borrowernumber+'">';
+ if ( row.patron_firstname ) {
+ patronLink = patronLink + row.patron_firstname + ' ';
+ }
+ patronLink = patronLink + row.patron_surname +
+ ' (' + row.patron_cardnumber + ')' + '</a>';
+ return patronLink;
+ };
+
+ // Our 'render' function for biblio_id
+ var createBiblioLink = function(data, type, row) {
+ return (row.biblio_id) ?
+ '<a title="' + _("View biblio details") + '" ' +
+ 'href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=' +
+ row.biblio_id + '">' +
+ row.biblio_id +
+ '</a>' : '';
+ };
+
+ // Our 'render' function for title
+ var createTitle = function(data, type, row) {
+ return (
+ row.hasOwnProperty('metadata_container_title') &&
+ row.metadata_container_title
+ ) ? row.metadata_container_title : row.metadata_title;
+ };
+
+ // Render function for request ID
+ var createRequestId = function(data, type, row) {
+ return row.id_prefix + row.illrequest_id;
+ };
+
+ // Render function for type
+ var createType = function(data, type, row) {
+ if (!row.hasOwnProperty('metadata_Type') || !row.metadata_Type) {
+ if (row.hasOwnProperty('medium') && row.medium) {
+ row.metadata_Type = row.medium;
+ } else {
+ row.metadata_Type = null;
+ }
+ }
+ return row.metadata_Type;
+ };
+
+ // Render function for request status
+ var createStatus = function(data, type, row, meta) {
+ if (row.status_alias) {
+ return row.status_alias.lib
+ ? row.status_alias.lib
+ : row.status_alias.authorised_value;
+ } else {
+ var origData = meta.settings.oInit.originalData;
+ if (origData.length > 0) {
+ var status_name = meta.settings.oInit.originalData[0].capabilities[
+ row.status
+ ].name;
+ return getStatusName(status_name);
+ } else {
+ return '';
+ }
+ }
+ };
+
+ var getStatusName = function(origName) {
+ switch( origName ) {
+ case "New request":
+ return _("New request");
+ case "Requested":
+ return _("Requested");
+ case "Requested from partners":
+ return _("Requested from partners");
+ case "Request reverted":
+ return _("Request reverted");
+ case "Queued request":
+ return _("Queued request");
+ case "Cancellation requested":
+ return _("Cancellation requested");
+ case "Completed":
+ return _("Completed");
+ case "Delete request":
+ return _("Delete request");
+ default:
+ return origName;
+ }
+ };
+
+ // Render function for creating a row's action link
+ var createActionLink = function(data, type, row) {
+ return '<a class="btn btn-default btn-sm" ' +
+ 'href="/cgi-bin/koha/ill/ill-requests.pl?' +
+ 'method=illview&illrequest_id=' +
+ row.illrequest_id +
+ '">' + _("Manage request") + '</a>';
+ };
+
+ // Columns that require special treatment
+ var specialCols = {
+ action: {
+ func: createActionLink,
+ skipSanitize: true
+ },
+ illrequest_id: {
+ func: createRequestId
+ },
+ status: {
+ func: createStatus
+ },
+ biblio_id: {
+ name: _("Bibliograpic record ID"),
+ func: createBiblioLink,
+ skipSanitize: true
+ },
+ metadata_title: {
+ func: createTitle
+ },
+ metadata_Type: {
+ func: createType
+ },
+ updated: {
+ name: _("Updated on"),
+ },
+ patron: {
+ skipSanitize: true,
+ func: createPatronLink
+ }
+ };
+
+ // Display the modal containing request supplier metadata
+ $('#ill-request-display-log').on('click', function(e) {
+ e.preventDefault();
+ $('#requestLog').modal({show:true});
+ });
+
+ // Toggle request attributes in Illview
+ $('#toggle_requestattributes').on('click', function(e) {
+ e.preventDefault();
+ $('#requestattributes').toggleClass('content_hidden');
+ });
+
+ // Toggle new comment form in Illview
+ $('#toggle_addcomment').on('click', function(e) {
+ e.preventDefault();
+ $('#addcomment').toggleClass('content_hidden');
+ });
+
+ // Filter partner list
+ $('#partner_filter').keyup(function() {
+ var needle = $('#partner_filter').val();
+ $('#partners > option').each(function() {
+ var regex = new RegExp(needle, 'i');
+ if (
+ needle.length == 0 ||
+ $(this).is(':selected') ||
+ $(this).text().match(regex)
+ ) {
+ $(this).show();
+ } else {
+ $(this).hide();
+ }
+ });
+ });
+
+ // Display the modal containing request supplier metadata
+ $('#ill-request-display-metadata').on('click', function(e) {
+ e.preventDefault();
+ $('#dataPreview').modal({show:true});
+ });
+
+ // Allow us to chain Datatable render helpers together, so we
+ // can use our custom functions and render.text(), which
+ // provides us with data sanitization
+ $.fn.dataTable.render.multi = function(renderArray) {
+ return function(d, type, row, meta) {
+ for(var r = 0; r < renderArray.length; r++) {
+ var toCall = renderArray[r].hasOwnProperty('display') ?
+ renderArray[r].display :
+ renderArray[r];
+ d = toCall(d, type, row, meta);
+ }
+ return d;
+ }
+ }
+
+ // Get our data from the API and process it prior to passing
+ // it to datatables
+ var ajax = $.ajax(
+ '/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias,comments'
+ ).done(function() {
+ var data = JSON.parse(ajax.responseText);
+ // Make a copy, we'll be removing columns next and need
+ // to be able to refer to data that has been removed
+ var dataCopy = $.extend(true, [], data);
+ // Expand columns that need it and create an array
+ // of all column names
+ $.each(dataCopy, function(k, row) {
+ expandExpand(row);
+ });
+
+ // Assemble an array of column definitions for passing
+ // to datatables
+ var colData = [];
+ columns_settings.forEach(function(thisCol) {
+ var colName = thisCol.columnname;
+ // Create the base column object
+ var colObj = $.extend({}, thisCol);
+ colObj.name = colName;
+ colObj.className = colName;
+ colObj.defaultContent = '';
+
+ // We may need to process the data going in this
+ // column, so do it if necessary
+ if (
+ specialCols.hasOwnProperty(colName) &&
+ specialCols[colName].hasOwnProperty('func')
+ ) {
+ var renderArray = [
+ specialCols[colName].func
+ ];
+ if (!specialCols[colName].skipSanitize) {
+ renderArray.push(
+ $.fn.dataTable.render.text()
+ );
+ }
+
+ colObj.render = $.fn.dataTable.render.multi(
+ renderArray
+ );
+ } else {
+ colObj.data = colName;
+ colObj.render = $.fn.dataTable.render.text()
+ }
+ // Make sure properties that aren't present in the API
+ // response are populated with null to avoid Datatables
+ // choking on their absence
+ dataCopy.forEach(function(thisData) {
+ if (!thisData.hasOwnProperty(colName)) {
+ thisData[colName] = null;
+ }
+ });
+ colData.push(colObj);
+ });
+
+ // Initialise the datatable
+ table = KohaTable("ill-requests", {
+ 'aoColumnDefs': [
+ { // Last column shouldn't be sortable or searchable
+ 'aTargets': [ 'actions' ],
+ 'bSortable': false,
+ 'bSearchable': false
+ },
+ { // When sorting 'placed', we want to use the
+ // unformatted column
+ 'aTargets': [ 'placed_formatted'],
+ 'iDataSort': 14
+ },
+ { // When sorting 'updated', we want to use the
+ // unformatted column
+ 'aTargets': [ 'updated_formatted'],
+ 'iDataSort': 16
+ },
+ { // When sorting 'completed', we want to use the
+ // unformatted column
+ 'aTargets': [ 'completed_formatted'],
+ 'iDataSort': 19
+ }
+ ],
+ 'aaSorting': [[ 16, 'desc' ]], // Default sort, updated descending
+ 'processing': true, // Display a message when manipulating
+ 'sPaginationType': "full_numbers", // Pagination display
+ 'deferRender': true, // Improve performance on big datasets
+ 'data': dataCopy,
+ 'columns': colData,
+ 'originalData': data, // Enable render functions to access
+ // our original data
+ 'initComplete': function() {
+
+ // Prepare any filter elements that need it
+ for (var el in filterable) {
+ if (filterable.hasOwnProperty(el)) {
+ if (filterable[el].hasOwnProperty('prep')) {
+ filterable[el].prep(dataCopy, data);
+ }
+ if (filterable[el].hasOwnProperty('listener')) {
+ filterable[el].listener();
+ }
+ }
+ }
+
+ }
+ }, columns_settings);
+
+ // Custom date range filtering
+ $.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
+ var placedStart = $('#illfilter_dateplaced_start').datepicker('getDate');
+ var placedEnd = $('#illfilter_dateplaced_end').datepicker('getDate');
+ var modifiedStart = $('#illfilter_datemodified_start').datepicker('getDate');
+ var modifiedEnd = $('#illfilter_datemodified_end').datepicker('getDate');
+ var rowPlaced = data[14] ? new Date(data[14]) : null;
+ var rowModified = data[16] ? new Date(data[16]) : null;
+ var placedPassed = true;
+ var modifiedPassed = true;
+ if (placedStart && rowPlaced && rowPlaced < placedStart) {
+ placedPassed = false
+ };
+ if (placedEnd && rowPlaced && rowPlaced > placedEnd) {
+ placedPassed = false;
+ }
+ if (modifiedStart && rowModified && rowModified < modifiedStart) {
+ modifiedPassed = false
+ };
+ if (modifiedEnd && rowModified && rowModified > modifiedEnd) {
+ modifiedPassed = false;
+ }
+
+ return placedPassed && modifiedPassed;
+
+ });
+
+ }
+ );
+
+ var clearSearch = function() {
+ table.api().search('').columns().search('');
+ activeFilters = {};
+ for (var filter in filterable) {
+ if (
+ filterable.hasOwnProperty(filter) &&
+ filterable[filter].hasOwnProperty('clear')
+ ) {
+ filterable[filter].clear();
+ }
+ }
+ table.api().draw();
+ };
+
+ // Apply any search filters, or clear any previous
+ // ones
+ $('#illfilter_form').submit(function(event) {
+ event.preventDefault();
+ table.api().search('').columns().search('');
+ for (var active in activeFilters) {
+ if (activeFilters.hasOwnProperty(active)) {
+ activeFilters[active]();
+ }
+ }
+ table.api().draw();
+ });
+
+ // Clear all filters
+ $('#clear_search').click(function() {
+ clearSearch();
+ });
+
+ });
+ </script>
+[% END %]
+
[% INCLUDE 'intranet-bottom.inc' %]