@@ -, +, @@ --- ill/ill-requests.pl | 5 +- .../intranet-tmpl/prog/en/includes/circ-menu.inc | 2 +- .../prog/en/includes/ill-list-table.inc | 17 ++ .../prog/en/modules/ill/ill-requests.tt | 292 +-------------------- .../prog/en/modules/members/ill-requests.tt | 41 +++ koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js | 272 +++++++++++++++++++ members/ill-requests.pl | 54 ++++ 7 files changed, 390 insertions(+), 293 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/ill-requests.tt create mode 100644 koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js create mode 100755 members/ill-requests.pl --- a/ill/ill-requests.pl +++ a/ill/ill-requests.pl @@ -223,13 +223,12 @@ if ( $backends_available ) { my $active_filters = []; foreach my $filter(@{$possible_filters}) { if ($params->{$filter}) { - push @{$active_filters}, - { name => $filter, value => $params->{$filter}}; + push @{$active_filters}, "$filter=$params->{$filter}"; } } if (scalar @{$active_filters} > 0) { $template->param( - prefilters => $active_filters + prefilters => join(",", @{$active_filters}) ); } } else { --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -122,7 +122,7 @@ [% IF houseboundview %]
  • [% ELSE %]
  • [% END %]Housebound
  • [% END %] [% IF Koha.Preference('ILLModule') && CAN_user_ill %] -
  • Interlibrary loans
  • + [% IF illview %]
  • [% ELSE %]
  • [% END %]Interlibrary loans
  • [% END %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc @@ -0,0 +1,17 @@ + 0 %] data-prefilters="[% prefilters %]"[% END %]> + + + + + + + + + + + + + + + +
    AuthorTitlePatronBiblio IDLibraryStatusUpdated onRequest number
    --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -10,277 +10,7 @@ [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %] [% Asset.css("css/datatables.css") | $raw %] [% INCLUDE 'datatables.inc' %] - +[% Asset.js("js/ill-list-table.js") %] @@ -597,26 +327,10 @@ [% ELSIF query_type == 'illlist' %]

    View ILL requests

    + [% prefilter_arr = %]

    Details for all requests

    - - - - - - - - - - - - - - - - - -
    AuthorTitlePatronBibliographic record IDLibraryStatusUpdated onRequest number
    + [% INCLUDE 'ill-list-table.inc' %]
    [% ELSE %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/ill-requests.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/ill-requests.tt @@ -0,0 +1,41 @@ +[% USE Asset %] +[% USE Branches %] +[% USE Koha %] +[% USE KohaDates %] + +[% INCLUDE 'doc-head-open.inc' %] +Koha › Patrons › ILL requests for [% INCLUDE 'patron-title.inc' no_html = 1 %] +[% INCLUDE 'doc-head-close.inc' %] +[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") %] +[% Asset.css("css/datatables.css") %] +[% INCLUDE 'datatables.inc' %] +[% Asset.js("js/ill-list-table.js") %] + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'patron-search.inc' %] + + + +
    + +
    +
    +
    +
    +

    ILL requests

    + [% INCLUDE 'ill-list-table.inc' %] +
    +
    +
    +
    + [% INCLUDE 'circ-menu.inc' %] +
    +
    + +[% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js +++ a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js @@ -0,0 +1,272 @@ +$(document).ready(function() { + + // Illview Datatable setup + + // Get any prefilters + var prefilters = $('table#ill-requests').data('prefilters'); + + // Fields we don't want to display + var ignore = [ + 'accessurl', + 'backend', + 'branchcode', + 'completed', + 'capabilities', + 'cost', + 'medium', + 'notesopac', + 'notesstaff', + 'placed', + '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', + 'biblio_id', + 'library', + 'status', + 'updated', + 'illrequest_id', + 'action' + ]; + + // 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) { + return '' + + row.patron_firstname + ' ' + row.patron_surname + + ''; + }; + + // 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; + switch( status_name ) { + 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 status_name; + } + } else { + return ''; + } + }; + + // Render function for creating a row's action link + var createActionLink = function(data, type, row) { + return '' + _("Manage request") + ''; + }; + + // 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: _("Biblio ID") + }, + library: { + name: _("Library"), + func: createLibrary + } + }; + + // Toggle request attributes in Illview + $('#toggle_requestattributes').on('click', function(e) { + e.preventDefault(); + $('#requestattributes').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(); + } + }); + }); + + // Get our data from the API and process it prior to passing + // it to datatables + var filterParam = prefilters ? '&' + prefilters : ''; + var ajax = $.ajax( + '/api/v1/illrequests?embed=metadata,patron,capabilities,library' + + filterParam + ).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 + }; + // 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 + $('#ill-requests').DataTable($.extend(true, {}, dataTablesDefaults, { + 'aoColumnDefs': [ // Last column shouldn't be sortable or searchable + { + 'aTargets': [ 'actions' ], + 'bSortable': false, + 'bSearchable': false + }, + ], + 'aaSorting': [[ 6, '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 + })); + } + ); + +}); --- a/members/ill-requests.pl +++ a/members/ill-requests.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# This file is part of Koha. +# +# Copyright 2018 PTFS Europe +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use CGI qw ( -utf8 ); +use C4::Auth; +use C4::Output; +use C4::Members; +use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patrons; + +my $input = new CGI; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { template_name => "members/ill-requests.tt", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => { borrowers => 'edit_borrowers' }, + debug => 1, + } +); + +my $borrowernumber = $input->param('borrowernumber'); + +my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in"; +my $patron = Koha::Patrons->find( $borrowernumber ); +output_and_exit_if_error( $input, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } ); + +my $category = $patron->category; +$template->param( + prefilters => "borrowernumber=$borrowernumber", + patron => $patron, + illview => 1, +); + +output_html_with_http_headers $input, $cookie, $template->output; --