From 6acb4189edd964e45fb48cbd7b98a98c6004363e 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. --- koha-tmpl/intranet-tmpl/js/autocomplete/patrons.pl | 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.pl diff --git a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.pl b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.pl new file mode 100644 index 0000000..fa041b0 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.pl @@ -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 b55da33..67bf9e3 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.1.0