Koha/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt
Tomas Cohen Arazi af59238ba0 Bug 7317: (followup) Remove extra columns from backends on the main list
This patch removes the extra columns functionality, simplifying the code.
It removes redundant code (in both Perl and JS), unused vars.

It removes the use of here_link and hardcodes the script path on the template.

It also adjusts the AJAX call so it uses the 'library' param instead of 'branch'.

The library column now displays the library name instead of the ID.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-11-09 11:42:16 -03:00

645 lines
30 KiB
Text

[% USE Branches %]
[% USE Koha %]
[% USE KohaDates %]
[% columns = [ 'metadata_Author', 'metadata_Title', 'borrowername', 'biblio_id', 'library', 'status', 'updated', 'illrequest_id', 'action' ] %]
[% BLOCK translate_column %]
[%- SWITCH column -%]
[%- CASE 'metadata_Author' -%]Author
[%- CASE 'metadata_Title' -%]Title
[%- CASE 'borrowername' -%]Patron
[%- CASE 'biblio_id' -%]Biblio ID
[%- CASE 'library' -%]Library
[%- CASE 'status' -%]Status
[%- CASE 'updated' -%]Updated on
[%- CASE 'illrequest_id' -%]Request number
[%- END -%]
[% END %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; ILL requests &rsaquo;</title>
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript" src="[% interface %]/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
<link rel="stylesheet" type="text/css" href="[% interface %]/[% theme %]/css/datatables.css">
[% INCLUDE 'datatables.inc' %]
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
// Illview Datatable setup
// 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'
];
// Extra fields that we need to tack on to the end
var extra = [ '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 '<a title="View borrower details" ' +
'href="/cgi-bin/koha/members/moremember.pl?' +
'borrowernumber='+row.borrowernumber+'">' +
row.patron_firstname + ' ' + row.patron_surname +
'</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;
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 '<a class="btn btn-default btn-sm" ' +
'href="/cgi-bin/koha/ill/ill-requests.pl?' +
'method=illview&amp;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: _("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 ajax = $.ajax(
'/api/v1/illrequests?embed=metadata,patron,capabilities,library'
).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);
});
// Append any extra columns we need to tag on
if (extra.length > 0) {
extra.forEach(function(thisExtra) {
allCols[thisExtra] = 1;
});
}
// 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': [ 'action' ],
'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
}));
}
);
});
//]]>
</script>
</head>
<body id="illrequests" class="ill">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]
<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
<a href="/cgi-bin/koha/ill/ill-requests.pl">ILL requests</a>
[% IF query_type == 'create' %]
&rsaquo; New request
[% ELSIF query_type == 'status' %]
&rsaquo; Status
[% END %]
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div id="interlibraryloans" class="yui-b">
[% IF !backends_available %]
<div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a></div>
[% ELSE %]
[% INCLUDE 'ill-toolbar.inc' %]
[% IF whole.error %]
<h1>Error performing operation</h1>
<!-- Dispatch on Status -->
<p>We encountered an error:</p>
<p>
<pre>[% whole.message %] ([% whole.status %])</pre>
</p>
[% END %]
[% IF query_type == 'create' %]
<h1>New ILL request</h1>
[% IF whole.stage == 'copyrightclearance' %]
<div>
<p>
[% Koha.Preference('ILLModuleCopyrightClearance') %]
</p>
<a href="?method=create&stage=copyrightclearance&backend=[% whole.value.backend %]"
class="btn btn-sm btn-default btn-group"><i class="fa fa-check">Yes</i></a>
<a href="/cgi-bin/koha/ill/ill-requests.pl"
class="btn btn-sm btn-default btn-group"><i class="fa fa-times">No</i></a>
</div>
[% ELSE %]
[% PROCESS $whole.template %]
[% END %]
[% ELSIF query_type == 'confirm' %]
<h1>Confirm ILL request</h1>
[% PROCESS $whole.template %]
[% ELSIF query_type == 'cancel' and !whole.error %]
<h1>Cancel a confirmed request</h1>
[% PROCESS $whole.template %]
[% ELSIF query_type == 'generic_confirm' %]
<h1>Place request with partner libraries</h1>
[% IF error %]
<div class="alert">
[% IF error == 'no_target_email' %]
No target email addresses found. Either select at least
one partner or check your ILL partner library records.
[% ELSIF error == 'no_library_email' %]
Your library has no usable email address. Please set it.
[% ELSIF error == 'unkown_error' %]
Unknown error processing your request. Contact your administrator.
[% END %]
</div>
[% END %]
<!-- Start of GENERIC_EMAIL case -->
[% IF whole.value.partners %]
[% ill_url = "/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id=" _ request.illrequest_id %]
<form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
<fieldset class="rows">
<legend>Interlibrary loan request details</legend>
<ol>
<li>
<label for="partner_filter">Filter partner libraries:</label>
<input type="text" id="partner_filter">
</li>
<li>
<label for="partners">Select partner libraries:</label>
<select size="5" multiple="true" id="partners"
name="partners">
[% FOREACH partner IN whole.value.partners %]
<option value=[% partner.email %]>
[% partner.branchcode _ " - " _ partner.surname %]
</option>
[% END %]
</select>
</li>
<li>
<label for="subject">Subject Line</label>
<input type="text" name="subject"
id="subject" type="text"
value="[% whole.value.draft.subject %]"/>
</li>
<li>
<label for="body">Email text:</label>
<textarea name="body" id="body" rows="20" cols="80">[% whole.value.draft.body %]</textarea>
</li>
</ol>
<input type="hidden" value="generic_confirm" name="method">
<input type="hidden" value="draft" name="stage">
<input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
</fieldset>
<fieldset class="action">
<input type="submit" class="btn btn-default" value="Send email"/>
<span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span>
</fieldset>
</form>
[% ELSE %]
<fieldset class="rows">
<legend>Interlibrary loan request details</legend>
<p>No partners have been defined yet. Please create appropriate patron records (by default ILLLIBS category).</p>
<p>Be sure to provide email addresses for these patrons.</p>
<p><span><a href="[% ill_url %]" title="Return to request details">Cancel</a></span></p>
</fieldset>
[% END %]
<!-- generic_confirm ends here -->
[% ELSIF query_type == 'edit_action' %]
<form method="POST" action="/cgi-bin/koha/ill/ill-requests.pl">
<fieldset class="rows">
<legend>Request details</legend>
<ol>
<li class="borrowernumber">
<label for="borrowernumber">Patron ID:</label>
<input name="borrowernumber" id="borrowernumber" type="text" value="[% request.borrowernumber %]">
</li>
<li class="biblio_id">
<label for="biblio_id" class="biblio_id">Biblio ID:</label>
<input name="biblio_id" id="biblio_id" type="text" value="[% request.biblio_id %]">
</li>
<li class="branchcode">
<label for="branchcode" class="branchcode">Library:</label>
<select name="branchcode" id="branch">
[% FOREACH branch IN branches %]
[% IF ( branch.branchcode == request.branchcode ) %]
<option value="[% branch.branchcode %]" selected="selected">
[% branch.branchname %]
</option>
[% ELSE %]
<option value="[% branch.branchcode %]">
[% branch.branchname %]
</option>
[% END %]
[% END %]
</select>
</li>
<li class="status">
<label class="status">Status:</label>
[% stat = request.status %]
[% request.capabilities.$stat.name %]
</li>
<li class="updated">
<label class="updated">Last updated:</label>
[% request.updated | $KohaDates with_hours => 1 %]
</li>
<li class="medium">
<label class="medium">Request type:</label>
[% request.medium %]
</li>
<li class="cost">
<label class="cost">Cost:</label>
[% request.cost || 'N/A' %]
</li>
<li class="req_id">
<label class="req_id">Request number:</label>
[% request.id_prefix _ request.illrequest_id %]
</li>
<li class="notesstaff">
<label for="notesstaff" class="notesstaff">Staff notes:</label>
<textarea name="notesstaff" id="notesstaff" rows="5">[% request.notesstaff %]</textarea>
</li>
<li class="notesopac">
<label for="notesopac" class="notesopac">Opac notes:</label>
<textarea name="notesopac" id="notesopac" rows="5">[% request.notesopac %]</textarea>
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="hidden" value="edit_action" name="method">
<input type="hidden" value="form" name="stage">
<input type="hidden" value="[% request.illrequest_id %]" name="illrequest_id">
<input type="submit" value="Submit">
<a class="cancel" href="/cgi-bin/koha/ill/ill-requests.pl?method=illview&amp;illrequest_id=[% request.id %]">Cancel</a>
</fieldset>
</form>
[% ELSIF query_type == 'delete_confirm' %]
<div class="dialog alert">
<h3>Are you sure you wish to delete this request?</h3>
<p>
<a class="btn btn-default btn-sm approve" href="?method=delete&amp;illrequest_id=[% request.id %]&amp;confirmed=1"><i class="fa fa-fw fa-check"></i>Yes</a>
<a class="btn btn-default btn-sm deny" href="?method=illview&amp;illrequest_id=[% request.id %]"><i class="fa fa-fw fa-remove"></i>No</a>
</p>
</div>
[% ELSIF query_type == 'illview' %]
[% actions = request.available_actions %]
[% capabilities = request.capabilities %]
[% req_status = request.status %]
<h1>Manage ILL request</h1>
<div id="toolbar" class="btn-toolbar">
<a title="Edit request" id="ill-toolbar-btn-edit-action" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=edit_action&amp;illrequest_id=[% request.illrequest_id %]">
<span class="fa fa-pencil"></span>
Edit request
</a>
[% FOREACH action IN actions %]
[% IF action.method != 0 %]
<a title="[% action.ui_method_name %]" id="ill-toolbar-btn-[% action.id | lower %]" class="btn btn-sm btn-default" href="/cgi-bin/koha/ill/ill-requests.pl?method=[% action.method %]&amp;illrequest_id=[% request.illrequest_id %]">
<span class="fa [% action.ui_method_icon %]"></span>
[% action.ui_method_name %]
</a>
[% END %]
[% END %]
</div>
<div id="ill-view-panel" class="panel panel-default">
<div class="panel-heading">
<h3>Request details</h3>
</div>
<div class="panel-body">
<h4>Details from library</h4>
<div class="rows">
<div class="orderid">
<span class="label orderid">Order ID:</span>
[% request.orderid || "N/A" %]
</div>
<div class="borrowernumber">
<span class="label borrowernumber">Patron:</span>
[% borrowerlink = "/cgi-bin/koha/members/moremember.pl" _ "?borrowernumber=" _ request.patron.borrowernumber %]
<a href="[% borrowerlink %]" title="View borrower details">
[% request.patron.firstname _ " " _ request.patron.surname _ " [" _ request.patron.cardnumber _ "]" %]
</a>
</div>
<div class="biblio_id">
<span class="label biblio_id">Biblio ID:</span>
[% request.biblio_id || "N/A" %]
</div>
<div class="branchcode">
<span class="label branchcode">Library:</span>
[% Branches.GetName(request.branchcode) %]
</div>
<div class="status">
<span class="label status">Status:</span>
[% capabilities.$req_status.name %]
</div>
<div class="updated">
<span class="label updated">Last updated:</span>
[% request.updated | $KohaDates with_hours => 1 %]
</div>
<div class="medium">
<span class="label medium">Request type:</span>
[% request.medium %]
</div>
<div class="cost">
<span class="label cost">Cost:</span>
[% request.cost || "N/A" %]
</div>
<div class="req_id">
<span class="label req_id">Request number:</span>
[% request.id_prefix _ request.illrequest_id %]
</div>
<div class="notesstaff">
<span class="label notes_staff">Staff notes:</span>
<pre>[% request.notesstaff %]</pre>
</div>
<div class="notesopac">
<span class="label notes_opac">Notes:</span>
<pre>[% request.notesopac %]</pre>
</div>
</div>
<div class="rows">
<h4>Details from supplier ([% request.backend %])</h4>
[% FOREACH meta IN request.metadata %]
<div class="requestmeta-[% meta.key %]">
<span class="label">[% meta.key %]:</span>
[% meta.value %]
</div>
[% END %]
</div>
<div class="rows">
<h3><a id="toggle_requestattributes" href="#">Toggle full supplier metadata</a></h3>
<div id="requestattributes" class="content_hidden">
[% FOREACH attr IN request.illrequestattributes %]
<div class="requestattr-[% attr.type %]">
<span class="label">[% attr.type %]:</span>
[% attr.value %]
</div>
[% END %]
</div>
</div>
</div>
</div>
[% ELSIF query_type == 'illlist' %]
<!-- illlist -->
<h1>View ILL requests</h1>
<div id="results">
<h3>Details for all requests</h3>
<table id="ill-requests">
<thead>
<tr id="illview-header">
[% FOR column IN columns %]
<th>[% PROCESS translate_column column=column %]</th>
[% END %]
</tr>
</thead>
<tbody id="illview-body">
</tbody>
</table>
</div>
[% ELSE %]
<!-- Custom Backend Action -->
[% INCLUDE $whole.template %]
[% END %]
[% END %]
</div>
</div>
</div>
</div>
[% TRY %]
[% PROCESS backend_jsinclude %]
[% CATCH %]
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]