View | Details | Raw Unified | Return to bug 31782
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js (-49 lines)
Lines 1-48 Link Here
1
function patron_autocomplete(params) {
2
    var patron_container = params.patron_container;
3
    var input_autocomplete = params.input_autocomplete;
4
    var patron_input_name = params.patron_input_name || 'cardnumber';
5
    var field_to_retrieve = params.field_to_retrieve || 'cardnumber';
6
7
    $( input_autocomplete ).autocomplete({
8
        source: "/api/v1/patrons",
9
        minLength: 3,
10
        select: function( event, ui ) {
11
            var field = ui.item.cardnumber;
12
            if ( field_to_retrieve == 'borrowernumber' ) {
13
                field = ui.item.borrowernumber;
14
            }
15
            AddPatron( ui.item.firstname + " " + ui.item.middle_name + " " + ui.item.surname, field, patron_container, patron_input_name );
16
            input_autocomplete.val('').focus();
17
            return false;
18
        }
19
    })
20
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
21
        return $( "<li></li>" )
22
        .data( "ui-autocomplete-item", item )
23
        .append( "<a>" + item.surname + ", " + item.firstname + " " + item.middle_name + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
24
        .appendTo( ul );
25
    };
26
27
    $("body").on("click",".removePatron",function(e){
28
        e.preventDefault();
29
        var divid = $(this).parent().attr("id");
30
        var cardnumber = divid.replace("borrower_","");
31
        RemovePatron(cardnumber, patron_container);
32
    });
33
}
34
35
function AddPatron( patron_name, value, container, input_name ) {
36
    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>";
37
    $(container).append( div );
38
39
    $(container).parent().show( 800 );
40
}
41
42
function RemovePatron( cardnumber, container ) {
43
    $( '#borrower_' + cardnumber ).remove();
44
45
    if ( ! $(container).html() ) {
46
        $(container).parent().hide( 800 );
47
    }
48
}
49
- 

Return to bug 31782