Browse Source
On 30578 we replace circ/ysearch.pl with a call to the /api/v1/patrons route. A new patron_autocomplete JS function has been written (js/patron-autocomplete.js) for that purpose. However 3 occurrences were using an existing patron_autocomplete function, and 30578 didn't take care of adjusting correctly the call to the REST API route. On this patchset I am suggesting to copy/paste the JS functions defined in js/autocomplete/patrons.js, because we are very close of the 22.11 release. But ideally we should improve js/patron-autocomplete.js to add a new 'on-select-add-to' option that will take care of add/remove/hide behaviour. IMO that must be done on a separate bug, and after 22.11 is released (to not need to retest the other occurrences of the patron autocomplete) Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>22.11.x
1 changed files with 0 additions and 48 deletions
@ -1,48 +0,0 @@ |
|||
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 ); |
|||
} |
|||
} |
Loading…
Reference in new issue