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

(-)a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js (+48 lines)
Line 0 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: "/cgi-bin/koha/circ/ysearch.pl",
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.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.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'> " + _("Remove") + " </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
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/patron_lists/list.tt (-37 / +5 lines)
Lines 6-11 Link Here
6
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
6
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
7
[% INCLUDE 'datatables.inc' %]
7
[% INCLUDE 'datatables.inc' %]
8
8
9
<script type="text/javascript" src="[% interface %]/js/autocomplete/patrons.js"></script>
9
<script type="text/javascript">
10
<script type="text/javascript">
10
//<![CDATA[
11
//<![CDATA[
11
$(document).ready(function() {
12
$(document).ready(function() {
Lines 21-46 $(document).ready(function() { Link Here
21
            "sPaginationType": "four_button"
22
            "sPaginationType": "four_button"
22
        } ));
23
        } ));
23
24
24
    $( "#find_patron" ).autocomplete({
25
    patron_autocomplete({
25
        source: "/cgi-bin/koha/circ/ysearch.pl",
26
        patron_container: $("#patrons_to_add"),
26
        minLength: 3,
27
        input_autocomplete: $("#find_patron"),
27
        select: function( event, ui ) {
28
        patron_input_name = 'patrons_to_add'
28
            AddPatron( ui.item.firstname + " " + ui.item.surname, ui.item.cardnumber );
29
            return false;
30
        }
31
    })
32
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
33
        return $( "<li></li>" )
34
        .data( "ui-autocomplete-item", item )
35
        .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
36
        .appendTo( ul );
37
    };
38
39
    $("body").on("click",".removePatron",function(e){
40
        e.preventDefault();
41
        var divid = $(this).parent().attr("id");
42
        var cardnumber = divid.replace("borrower_","");
43
        RemovePatron(cardnumber);
44
    });
29
    });
45
30
46
    var checkBoxes = $("input[type='checkbox']","#patron-list-table");
31
    var checkBoxes = $("input[type='checkbox']","#patron-list-table");
Lines 74-95 $(document).ready(function() { Link Here
74
    });
59
    });
75
});
60
});
76
61
77
function AddPatron( name, cardnumber ) {
78
    div = "<div id='borrower_" + cardnumber + "'>" + name + " ( <a href='#' class='removePatron'> " + _("Remove") + " </a> ) <input type='hidden' name='patrons_to_add' value='" + cardnumber + "' /></div>";
79
    $('#patrons_to_add').append( div );
80
81
    $('#find_patron').val('').focus();
82
83
    $('#patrons_to_add_fieldset').show( 800 );
84
}
85
86
function RemovePatron( cardnumber ) {
87
    $( '#borrower_' + cardnumber ).remove();
88
89
    if ( ! $('#patrons_to_add').html() ) {
90
        $('#patrons_to_add_fieldset').hide( 800 );
91
    }
92
}
93
//]]>
62
//]]>
94
</script>
63
</script>
95
64
96
- 

Return to bug 12944