From c8053f3c8d215c5edcfd0946c640d0b8d0bba504 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Sep 2014 17:12:42 +0200 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Bug 12944 [QA Followup] - Rename patrons.pl to patrons.js Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- .../intranet-tmpl/js/autocomplete/patrons.js | 48 +++++++++++++++++++ .../prog/en/modules/patron_lists/list.tt | 41 ++-------------- 2 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js diff --git a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js new file mode 100644 index 0000000000..fa041b0a89 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js @@ -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 $( "
  • " ) + .data( "ui-autocomplete-item", item ) + .append( "" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") " + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "" ) + .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 = "
    " + patron_name + " ( " + _("Remove") + " )
    "; + $(container).append( div ); + + $(container).parent().show( 800 ); +} + +function RemovePatron( cardnumber, container ) { + $( '#borrower_' + cardnumber ).remove(); + + if ( ! $(container).html() ) { + $(container).parent().hide( 800 ); + } +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt index f348cb61ef..1090dbfe2c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt @@ -6,6 +6,7 @@ [% INCLUDE 'datatables.inc' %] + -- 2.39.5