Jonathan Druart
9309dedb53
This patch removes the circ/ysearch.pl script used by the jQuery autocomplete widget. We can now use the /api/v1/patrons endpoint to retrieve the patrons and generate the patron result list. Prior to this patch the different occurrences were defining the style and the list of patron's attributes to display for each option (name, date of birth, age, address, etc.). Now they are all displaying the same information. To acchieve this we had to: * Make js-date-format.inc and js-patron-get-age.inc available from js_includes.inc and so available from everywhere, which is certainly a good move. We could discuss why this code is in include file instead of JS files however. * Remove the .ajaxSetup call in tags-review.js to reduce its scope: an underscore parameter was added to the REST API query (?) A better solution would have been to extend the existing widget (https://learn.jquery.com/jquery-ui/widget-factory/extending-widgets/) but I didn't manage to do it, and I feel like there is a bug in jQuery autocomplete. The "source" was not taken into account. We could think about replacing the jQuery autocomplete with something else, but that's outside the scope of this bug. Test plan: Search for patrons and confirm the autocomplete works and that the "select" action works as before (either a redirect or select the patrons) on the different views: * Place a hold * Search for tags (form on the left) * In the header, "Check out" and "Search patrons" * Add instructors to course reserves * View logs (the "librarian" input) Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
48 lines
2 KiB
JavaScript
48 lines
2 KiB
JavaScript
function patron_autocomplete(params) {
|
|
var patron_container = params.patron_container;
|
|
var input_autocomplete = params.input_autocomplete;
|
|
var patron_input_name = params.patron_input_name || 'cardnumber';
|
|
var field_to_retrieve = params.field_to_retrieve || 'cardnumber';
|
|
|
|
$( input_autocomplete ).autocomplete({
|
|
source: "/api/v1/patrons",
|
|
minLength: 3,
|
|
select: function( event, ui ) {
|
|
var field = ui.item.cardnumber;
|
|
if ( field_to_retrieve == 'borrowernumber' ) {
|
|
field = ui.item.borrowernumber;
|
|
}
|
|
AddPatron( ui.item.firstname + " " + ui.item.middle_name + " " + ui.item.surname, field, patron_container, patron_input_name );
|
|
input_autocomplete.val('').focus();
|
|
return false;
|
|
}
|
|
})
|
|
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
|
|
return $( "<li></li>" )
|
|
.data( "ui-autocomplete-item", item )
|
|
.append( "<a>" + item.surname + ", " + item.firstname + " " + item.middle_name + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
|
|
.appendTo( ul );
|
|
};
|
|
|
|
$("body").on("click",".removePatron",function(e){
|
|
e.preventDefault();
|
|
var divid = $(this).parent().attr("id");
|
|
var cardnumber = divid.replace("borrower_","");
|
|
RemovePatron(cardnumber, patron_container);
|
|
});
|
|
}
|
|
|
|
function AddPatron( patron_name, value, container, input_name ) {
|
|
div = "<div id='borrower_" + value + "'>" + patron_name + " ( <a href='#' class='removePatron'><i class='fa fa-trash' aria-hidden='true'></i> " + MSG_REMOVE_PATRON + " </a> ) <input type='hidden' name='" + input_name + "' value='" + value + "' /></div>";
|
|
$(container).append( div );
|
|
|
|
$(container).parent().show( 800 );
|
|
}
|
|
|
|
function RemovePatron( cardnumber, container ) {
|
|
$( '#borrower_' + cardnumber ).remove();
|
|
|
|
if ( ! $(container).html() ) {
|
|
$(container).parent().hide( 800 );
|
|
}
|
|
}
|