Koha/koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
Jonathan Druart 88816eebd9 Bug 13021: guarantor search - main patch
This patch is the main patch.
The "common" template is improved to allow different type of picking:
"add" or "select".
The first one appends a patron to a list, the second one selects the
patron and close the result search window.

The members/guarantor_search.pl has completly changed but is quite the
same file as acqui/add_user_search.pl. Both should exist: they don't
belong to the same module (acqui vs members), the picking type is
different (add vs select) and the columns are not the same.

The changes in the common template are very powerful, it's now possible
to list the column we want! This will be very useful for further
reusability.

Before this patch, all patrons mathing the pattern were return. Now only
the first 20 are (depends on the DataTables selected value).

For QA: This patch introduces a new template plugin "To", for now it
permits to convert a perl structure to json. In the idea, it could
permit to convert foo to bar too.

Test plan:
1/ Verify there is no regression in the guarantor search. When the
selection has been done, all data from the guarantor should fill the
form in the "main address" section.
Note that the request is done when the search input in not empty and the
user stop to write for 1 sec.
2/ Verify there is no regression on the 2 other pages where this patron
search is used: link a patron to an order and to a basket (in the
acquisition module).

Signed-off-by: Morag Hills <the.invinnysible.one@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
2015-03-19 14:19:34 -03:00

169 lines
5.3 KiB
Text

[% USE Koha %]
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Patron search</title>
[% INCLUDE 'doc-head-close.inc' %]
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
[% INCLUDE 'datatables.inc' %]
<script type="text/javascript">
//<![CDATA[
var search = 1;
$(document).ready(function(){
$("#info").hide();
$("#error").hide();
[% IF view != "show_results" %]
$("#searchresults").hide();
search = 0;
[% END %]
$("#searchmember_filter").on('keyup', function(){
filter();
});
// Apply DataTables on the results table
dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
'bServerSide': true,
'sAjaxSource': "/cgi-bin/koha/svc/members/search",
'fnServerData': function(sSource, aoData, fnCallback) {
if ( ! search ) {
return;
}
aoData.push({
'name': 'searchmember',
'value': $("#searchmember_filter").val()
},
{
'name': 'template_path',
'value': '[% json_template %]',
}
[% IF patrons_with_acq_perm_only %]
,{
'name': 'has_permission',
'value': 'acquisition.order_manage',
}
[% END %]
);
$.ajax({
'dataType': 'json',
'type': 'POST',
'url': sSource,
'data': aoData,
'success': function(json){
fnCallback(json);
}
});
},
'aoColumns':[
[% FOR column IN columns %]
[% IF column == 'action' %]
{ 'mDataProp': 'dt_action', 'bSortable': false }
[% ELSE %]
{ 'mDataProp': 'dt_[% column %]' }
[% END %]
[% UNLESS loop.last %],[% END %]
[% END %]
],
'bAutoWidth': false,
[% IF patrons_with_acq_perm_only %]
'bPaginate': false,
[% ELSE %]
'sPaginationType': 'full_numbers',
"iDisplayLength": [% Koha.Preference('PatronsPerPage') %],
[% END %]
'bFilter': false,
'bProcessing': true,
}));
dtMemberResults.fnAddFilters("filter", 750);
});
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
})();
function filter() {
search = 1;
$("#searchresults").show();
if ( $("#searchmember_filter").val().length > 0 ) {
delay(function(){
dtMemberResults.fnDraw();
}, 1000);
}
return false;
}
// modify parent window owner element
[% IF selection_type == 'add' %]
[%# Note that add_user could sent data instead of borrowername too %]
function add_user(borrowernumber, borrowername) {
var p = window.opener;
$("#info").hide();
$("#error").hide();
if ( p.add_user(borrowernumber, borrowername) < 0 ) {
$("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
$("#error").show();
} else {
$("#info").html(_("Borrower '%s' added.").format(borrowername));
$("#info").show();
}
}
[% ELSIF selection_type == 'select' %]
function select_user(borrowernumber, data) {
var p = window.opener;
p.select_user(borrowernumber, data);
window.close();
}
[% END %]
//]]>
</script>
</head>
<body>
<div id="patron_search" class="yui-t7">
<div id="bd">
<div class="yui-g">
<h3>Search for patron</h3>
<label for="searchmember_filter">Search:</label>
<input type="text" id="searchmember_filter" value="[% searchmember %]"/>
[% IF patrons_with_acq_perm_only %]
<div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
[% END %]
<div id="info" class="dialog message"></div>
<div id="error" class="dialog alert"></div>
<div id="searchresults">
<table id="memberresultst">
<thead>
<tr>
[% FOR column IN columns %]
[% SWITCH column %]
[% CASE 'cardnumber' %]<th>Card</th>
[% CASE 'dateofbirth' %]<th>Date of birth</th>
[% CASE 'address' %]<th>Address</th>
[% CASE 'name' %]<th>Name</th>
[% CASE 'branch' %]<th>Library</th>
[% CASE 'category' %]<th>Category</th>
[% CASE 'action' %]<th>&nbsp;</th>
[% END %]
[% END %]
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<div id="closewindow"><a href="#" class="close">Close</a></div>
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]