Bug 12944: Refactor the patron autocomplete
The patron list feature uses an autocomplete field to search patron. This will be reused in the next patch. This patch should not introduce any behavior change. Signed-off-by: Paola Rossi <paola.rossi@cineca.it> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Bug 12944 [QA Followup] - Rename patrons.pl to patrons.js Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
3cf7194335
commit
c8053f3c8d
|
|
@ -0,0 +1,48 @@
|
|||
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: "/cgi-bin/koha/circ/ysearch.pl",
|
||||
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.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.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'> " + _("Remove") + " </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 );
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
|
||||
[% INCLUDE 'datatables.inc' %]
|
||||
|
||||
<script type="text/javascript" src="[% interface %]/js/autocomplete/patrons.js"></script>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$(document).ready(function() {
|
||||
|
|
@ -21,26 +22,10 @@ $(document).ready(function() {
|
|||
"sPaginationType": "four_button"
|
||||
} ));
|
||||
|
||||
$( "#find_patron" ).autocomplete({
|
||||
source: "/cgi-bin/koha/circ/ysearch.pl",
|
||||
minLength: 3,
|
||||
select: function( event, ui ) {
|
||||
AddPatron( ui.item.firstname + " " + ui.item.surname, ui.item.cardnumber );
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
|
||||
return $( "<li></li>" )
|
||||
.data( "ui-autocomplete-item", item )
|
||||
.append( "<a>" + item.surname + ", " + item.firstname + " (" + 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_autocomplete({
|
||||
patron_container: $("#patrons_to_add"),
|
||||
input_autocomplete: $("#find_patron"),
|
||||
patron_input_name = 'patrons_to_add'
|
||||
});
|
||||
|
||||
var checkBoxes = $("input[type='checkbox']","#patron-list-table");
|
||||
|
|
@ -74,22 +59,6 @@ $(document).ready(function() {
|
|||
});
|
||||
});
|
||||
|
||||
function AddPatron( name, cardnumber ) {
|
||||
div = "<div id='borrower_" + cardnumber + "'>" + name + " ( <a href='#' class='removePatron'> " + _("Remove") + " </a> ) <input type='hidden' name='patrons_to_add' value='" + cardnumber + "' /></div>";
|
||||
$('#patrons_to_add').append( div );
|
||||
|
||||
$('#find_patron').val('').focus();
|
||||
|
||||
$('#patrons_to_add_fieldset').show( 800 );
|
||||
}
|
||||
|
||||
function RemovePatron( cardnumber ) {
|
||||
$( '#borrower_' + cardnumber ).remove();
|
||||
|
||||
if ( ! $('#patrons_to_add').html() ) {
|
||||
$('#patrons_to_add_fieldset').hide( 800 );
|
||||
}
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue