From 63a17aab80d43305e0178f1d1343127652dedcb9 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Tue, 24 Apr 2018 14:15:19 +0100 Subject: [PATCH] Bug 18589: Show ILLs as part of patron profile This patch moves the display of a patron's ILL requests to be inline in the Patron Profile page, as per all other patron information. It includes a substantial refactor of koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt in that it moves the display of the illlist table (which is populated by an API request) into it's own separate include file. It also moves the datatable related Javascript for this table into it's own JS file. Doing this allows us to reuse both in both the new members/ill-requests.tt template and the pre-existing ill/ill-requests.tt template. To test: 1) Ensure ILL is enabled and your user has sufficient permissions 2) Ensure your user has some ILL requests 3) Navigate to the user's patron profile page 4) Click on the "Interlibrary loans" tab 5) Observe that the requests table is displayed inline 6) Observe that only your user's requests are displayed --- 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 diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 47cfc97050..c4fc2b2f22 100755 --- a/ill/ill-requests.pl +++ b/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 { diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc index dcdf1ccc87..78f91f967d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc @@ -119,7 +119,7 @@ [% IF houseboundview %]
  • [% ELSE %]
  • [% END %]Housebound
  • [% END %] [% IF Koha.Preference('ILLModule') && CAN_user_ill %] -
  • Interlibrary loans
  • + [% IF illview %]
  • [% ELSE %]
  • [% END %]Interlibrary loans
  • [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc new file mode 100644 index 0000000000..19ef765b89 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-list-table.inc @@ -0,0 +1,17 @@ + 0 %] data-prefilters="[% prefilters %]"[% END %]> + + + + + + + + + + + + + + + +
    AuthorTitlePatronBiblio IDLibraryStatusUpdated onRequest number
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt index 70f31cad16..83171775d5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -9,277 +9,7 @@ [% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") %] [% Asset.css("css/datatables.css") %] [% INCLUDE 'datatables.inc' %] - +[% Asset.js("js/ill-list-table.js") %] @@ -580,26 +310,10 @@ [% ELSIF query_type == 'illlist' %]

    View ILL requests

    + [% prefilter_arr = %]

    Details for all requests

    - - - - - - - - - - - - - - - - - -
    AuthorTitlePatronBiblio IDLibraryStatusUpdated onRequest number
    + [% INCLUDE 'ill-list-table.inc' %]
    [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/ill-requests.tt new file mode 100644 index 0000000000..5f739fa999 --- /dev/null +++ b/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' %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js b/koha-tmpl/intranet-tmpl/prog/js/ill-list-table.js new file mode 100644 index 0000000000..083eca4453 --- /dev/null +++ b/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 + })); + } + ); + +}); diff --git a/members/ill-requests.pl b/members/ill-requests.pl new file mode 100755 index 0000000000..461437745b --- /dev/null +++ b/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; -- 2.11.0