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

(-)a/api/v1/swagger/definitions/patron.yaml (+5 lines)
Lines 359-364 properties: Link Here
359
      - number
359
      - number
360
      - "null"
360
      - "null"
361
    description: Balance of the patron's account
361
    description: Balance of the patron's account
362
  library:
363
    type:
364
      - object
365
      - "null"
366
    description: Library of the patron
362
additionalProperties: false
367
additionalProperties: false
363
required:
368
required:
364
  - surname
369
  - surname
(-)a/api/v1/swagger/paths/patrons.yaml (+1 lines)
Lines 359-364 Link Here
359
            - checkouts+count
359
            - checkouts+count
360
            - overdues+count
360
            - overdues+count
361
            - account_balance
361
            - account_balance
362
            - library
362
        collectionFormat: csv
363
        collectionFormat: csv
363
    responses:
364
    responses:
364
      "200":
365
      "200":
(-)a/circ/ysearch.pl (-100 lines)
Lines 1-100 Link Here
1
#!/usr/bin/perl
2
3
# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
4
5
# Copyright 2007 Tamil s.a.r.l.
6
# Parts copyright 2010-2012 Athens County Public Libraries
7
#
8
# This file is part of Koha.
9
#
10
# Koha is free software; you can redistribute it and/or modify it
11
# under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 3 of the License, or
13
# (at your option) any later version.
14
#
15
# Koha is distributed in the hope that it will be useful, but
16
# WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23
=head1 ysearch.pl
24
25
=cut
26
27
use Modern::Perl;
28
use CGI qw ( -utf8 );
29
use C4::Context;
30
use C4::Auth qw( check_cookie_auth );
31
use Koha::Patrons;
32
use Koha::DateUtils qw( format_sqldatetime );
33
use Koha::Libraries;
34
35
use JSON qw( to_json );
36
37
my $input = CGI->new;
38
my $query = $input->param('term');
39
40
binmode STDOUT, ":encoding(UTF-8)";
41
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
42
43
my ( $auth_status ) = check_cookie_auth( $input->cookie('CGISESSID'), { catalogue => '1' } );
44
if ( $auth_status ne "ok" ) {
45
    exit 0;
46
}
47
48
my $limit_on_branch;
49
if (   C4::Context->preference("IndependentBranches")
50
    && C4::Context->userenv
51
    && !C4::Context->IsSuperLibrarian()
52
    && C4::Context->userenv->{'branch'} ) {
53
    $limit_on_branch = 1;
54
}
55
56
my @parts = split( /,\s|\s/, $query );
57
my @params;
58
foreach my $p (@parts) {
59
    push(
60
        @params,
61
        -or => [
62
            surname    => { -like => "%$p%" },
63
            firstname  => { -like => "%$p%" },
64
            cardnumber => { -like => "$p%" },
65
        ]
66
    );
67
}
68
69
push( @params, { 'me.branchcode' => C4::Context->userenv->{branch} } ) if $limit_on_branch;
70
71
my $borrowers_rs = Koha::Patrons->search_limited(
72
    { -and => \@params },
73
    {
74
        # Get the first 10 results
75
        page     => 1,
76
        rows     => 10,
77
        order_by => [ 'surname', 'firstname' ],
78
        prefetch => 'branchcode',
79
    },
80
);
81
82
my @borrowers;
83
while ( my $b = $borrowers_rs->next ) {
84
    push @borrowers,
85
      { borrowernumber => $b->borrowernumber,
86
        surname        => $b->surname    // '',
87
        firstname      => $b->firstname  // '',
88
        cardnumber     => $b->cardnumber // '',
89
        dateofbirth    => format_sqldatetime($b->dateofbirth, undef, undef, 1) // '',
90
        age            => $b->get_age    // '',
91
        address        => $b->address    // '',
92
        city           => $b->city       // '',
93
        zipcode        => $b->zipcode    // '',
94
        country        => $b->country    // '',
95
        branchcode     => $b->branchcode // '',
96
        branchname     => $b->library->branchname // '',
97
      };
98
}
99
100
print to_json( \@borrowers );
(-)a/koha-tmpl/intranet-tmpl/js/autocomplete/patrons.js (-1 / +1 lines)
Lines 5-11 function patron_autocomplete(params) { Link Here
5
    var field_to_retrieve = params.field_to_retrieve || 'cardnumber';
5
    var field_to_retrieve = params.field_to_retrieve || 'cardnumber';
6
6
7
    $( input_autocomplete ).autocomplete({
7
    $( input_autocomplete ).autocomplete({
8
        source: "/cgi-bin/koha/circ/ysearch.pl",
8
        source: "/api/v1/patrons",
9
        minLength: 3,
9
        minLength: 3,
10
        select: function( event, ui ) {
10
        select: function( event, ui ) {
11
            var field = ui.item.cardnumber;
11
            var field = ui.item.cardnumber;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc (-94 / +10 lines)
Lines 26-31 Link Here
26
[% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
26
[% Asset.js("lib/jquery/plugins/jquery.validate.min.js") | $raw %]
27
<!-- koha core js -->
27
<!-- koha core js -->
28
[% Asset.js("js/staff-global.js") | $raw %]
28
[% Asset.js("js/staff-global.js") | $raw %]
29
[% INCLUDE 'js-date-format.inc' %]
30
[% INCLUDE 'js-patron-get-age.inc' %]
31
[% Asset.js("js/patron-autocomplete.js") | $raw %]
29
32
30
[% INCLUDE 'validator-strings.inc' %]
33
[% INCLUDE 'validator-strings.inc' %]
31
[% IF ( IntranetUserJS ) %]
34
[% IF ( IntranetUserJS ) %]
Lines 65-171 Link Here
65
    </script>
68
    </script>
66
[% END %]
69
[% END %]
67
70
68
[% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
69
    [% IF ( PatronAutoComplete ) %]
70
        <script>
71
            // PatronAutoComplete && CAN_user_circulate_circulate_remaining_permissions
72
            var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
73
            var loggedInClass = "";
74
            $(document).ready(function(){
75
                var obj = $( "#findborrower" ).autocomplete({
76
                    source: "/cgi-bin/koha/circ/ysearch.pl",
77
                    minLength: 3,
78
                    select: function( event, ui ) {
79
                        window.location.href = ui.item.link;
80
                    }
81
                }).data( "ui-autocomplete" );
82
                if( obj ) {
83
                    obj._renderItem = function( ul, item ) {
84
                        item.link = "/cgi-bin/koha/circ/circulation.pl?borrowernumber=" + item.borrowernumber;
85
                        var cardnumber = "";
86
                        if( item.cardnumber != "" ){
87
                            // Display card number in parentheses if it exists
88
                            cardnumber = " (" + item.cardnumber + ") ";
89
                        }
90
                        var itemString = "<a href=\"" + item.link + "\">" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", " + ( item.firstname ? item.firstname.escapeHtml() : "" ) + cardnumber.escapeHtml() + " <small>";
91
92
                        if( item.branchcode == loggedInLibrary ){
93
                            loggedInClass = "ac-currentlibrary";
94
                        } else {
95
                            loggedInClass = "";
96
                        }
97
98
                        if( item.dateofbirth ) {
99
                            itemString += ( item.dateofbirth ? item.dateofbirth.escapeHtml() : "" )
100
                                        + "<span class=\"age_years\"> (" + ( item.age ? item.age.escapeHtml() : "" ) + " " +  _("years") + ")</span>, ";
101
                        }
102
                        itemString += ( item.address ? item.address.escapeHtml() : "" ) + " "
103
                                    + ( item.city    ? item.city.escapeHtml()    : "" ) + " "
104
                                    + ( item.zipcode ? item.zipcode.escapeHtml() : "" ) + " "
105
                                    + ( item.country ? item.country.escapeHtml() : "" )
106
                                    + "</small></a>";
107
                        [% UNLESS ( singleBranchMode ) %]
108
                            itemString += " <span class=\"ac-library\">" + item.branchname + "</span> " + "</a>";
109
                        [% END %]
110
                        return $( "<li></li>" )
111
                        .addClass( loggedInClass )
112
                        .data( "ui-autocomplete-item", item )
113
                        .append( itemString )
114
                        .appendTo( ul );
115
                    };
116
                }
117
            });
118
        </script>
119
    [% END %]
120
[% END %]
121
[% IF ( PatronAutoComplete ) %]
71
[% IF ( PatronAutoComplete ) %]
122
    <script>
72
    <script>
123
    // PatronAutoComplete
73
    // PatronAutoComplete
124
    var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
74
    var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]';
75
    var singleBranchMode = '[% singleBranchMode | html %]';
125
    var loggedInClass = "";
76
    var loggedInClass = "";
126
    $(document).ready(function(){
77
    $(document).ready(function(){
127
        var obj = $( "#searchmember" ).autocomplete({
78
        [% IF ( CAN_user_circulate_circulate_remaining_permissions ) %]
128
            source: "/cgi-bin/koha/circ/ysearch.pl",
79
            if ( $("#findborrower").length ) {
129
            minLength: 3,
80
                patron_autocomplete($("#findborrower"), { 'on-select': 'link-to-circ' });
130
            select: function( event, ui ) {
131
                window.location.href = ui.item.link;
132
            }
81
            }
133
        }).data( "ui-autocomplete" );
82
        [% END %]
134
        if( obj ) {
83
        if ( $("#searchmember").length ) {
135
            obj._renderItem = function( ul, item ) {
84
            patron_autocomplete($("#searchmember"), { 'on-select': 'link-to-patron' });
136
                item.link = "/cgi-bin/koha/members/moremember.pl?borrowernumber=" + item.borrowernumber;
137
                var cardnumber = "";
138
                if( item.cardnumber != "" ){
139
                    // Display card number in parentheses if it exists
140
                    cardnumber = " (" + item.cardnumber + ") ";
141
                }
142
                if( item.branchcode == loggedInLibrary ){
143
                    loggedInClass = "ac-currentlibrary";
144
                } else {
145
                    loggedInClass = "";
146
                }
147
                return $( "<li></li>" )
148
                .addClass( loggedInClass )
149
                .data( "ui-autocomplete-item", item )
150
                .append(
151
                    "<a href=\"" + item.link + "\">" + ( item.surname ? item.surname.escapeHtml() : "" ) + ", "
152
                        + ( item.firstname ? item.firstname.escapeHtml() : "" )
153
                        + cardnumber.escapeHtml()
154
                        + " <small>"
155
                            + ( item.dateofbirth ? item.dateofbirth.escapeHtml() : "" ) + " "
156
                            + ( item.address     ? item.address.escapeHtml() : "" )     + " "
157
                            + ( item.city        ? item.city.escapeHtml() : "" )        + " "
158
                            + ( item.zipcode     ? item.zipcode.escapeHtml() : "" )     + " "
159
                            + ( item.country     ? item.country.escapeHtml() : "" ) + " "
160
                            [% UNLESS ( singleBranchMode ) %]
161
                                + "<span class=\"ac-library\">"
162
                                + ( item.branchname  ? item.branchname.escapeHtml() : "" )
163
                                + "</span>"
164
                            [% END %]
165
                        + "</small>"
166
                    + "</a>" )
167
                .appendTo( ul );
168
            };
169
        }
85
        }
170
    });
86
    });
171
    </script>
87
    </script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc (-1 lines)
Lines 236-242 Link Here
236
    </script>
236
    </script>
237
237
238
    [% INCLUDE 'datatables.inc' %]
238
    [% INCLUDE 'datatables.inc' %]
239
    [% INCLUDE 'js-date-format.inc' %]
240
    [% INCLUDE 'js-patron-get-age.inc' %]
239
    [% INCLUDE 'js-patron-get-age.inc' %]
241
    [% INCLUDE 'js-patron-format.inc' %]
240
    [% INCLUDE 'js-patron-format.inc' %]
242
    [% INCLUDE 'js-patron-format-address.inc' %]
241
    [% INCLUDE 'js-patron-format-address.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt (-1 lines)
Lines 1002-1008 Link Here
1002
    [% INCLUDE 'columns_settings.inc' %]
1002
    [% INCLUDE 'columns_settings.inc' %]
1003
    [% INCLUDE 'select2.inc' %]
1003
    [% INCLUDE 'select2.inc' %]
1004
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
1004
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
1005
    [% INCLUDE 'js-date-format.inc' %]
1006
    <script>
1005
    <script>
1007
        /* Set some variable needed in circulation.js */
1006
        /* Set some variable needed in circulation.js */
1008
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
1007
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course.tt (-28 / +3 lines)
Lines 174-209 Link Here
174
    [% MACRO jsinclude BLOCK %]
174
    [% MACRO jsinclude BLOCK %]
175
        <script>
175
        <script>
176
            $(document).ready(function(){
176
            $(document).ready(function(){
177
                $( "#find_instructor" ).autocomplete({
177
                patron_autocomplete($("#find_instructor"), { 'on-select-callback': function( event, ui ) {
178
                    source: "/cgi-bin/koha/circ/ysearch.pl",
178
                        AddInstructor( ui.item.surname + ", " + ui.item.firstname, ui.item.patron_id );
179
                    minLength: 3,
180
                    select: function( event, ui ) {
181
                        AddInstructor( ui.item.surname + ", " + ui.item.firstname, ui.item.borrowernumber );
182
                        return false;
179
                        return false;
183
                    }
180
                    }
184
                })
181
                });
185
                .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
186
                    return $( "<li></li>" )
187
                    .data( "ui-autocomplete-item", item )
188
                    .append(
189
                        "<a>"
190
                            + ( item.surname ? item.surname.escapeHtml() : "" )
191
                            + ", "
192
                            + ( item.firstname ? item.firstname.escapeHtml() : "" )
193
                            + " (" + ( item.cardnumber ? item.cardnumber.escapeHtml() : "" ) + ")"
194
                            + " "
195
                            + "<small>"
196
                                + ( item.address ? item.address.escapeHtml() : "" )
197
                                + " "
198
                                + ( item.city ? item.city.escapeHtml() : "" )
199
                                + " "
200
                                + ( item.zipcode ? item.zipcode.escapeHtml() : "" )
201
                                + " "
202
                                + ( item.country ? item.country.escapeHtml() : "" )
203
                            + "</small>"
204
                        + "</a>" )
205
                    .appendTo( ul );
206
                };
207
182
208
                if ( ! $('#instructors').html() ) {
183
                if ( ! $('#instructors').html() ) {
209
                    $('#course_instructors').hide();
184
                    $('#course_instructors').hide();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-1 lines)
Lines 843-849 Link Here
843
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
843
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
844
    [% INCLUDE 'columns_settings.inc' %]
844
    [% INCLUDE 'columns_settings.inc' %]
845
    [% INCLUDE 'select2.inc' %]
845
    [% INCLUDE 'select2.inc' %]
846
    [% INCLUDE 'js-date-format.inc' %]
847
    <script>
846
    <script>
848
        /* Set some variable needed in circulation.js */
847
        /* Set some variable needed in circulation.js */
849
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
848
        var logged_in_user_borrowernumber = "[% logged_in_user.borrowernumber | html %]";
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt (-1 lines)
Lines 334-340 Link Here
334
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
334
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
335
    [% Asset.js("js/cashup_modal.js") | $raw %]
335
    [% Asset.js("js/cashup_modal.js") | $raw %]
336
    [% INCLUDE 'calendar.inc' %]
336
    [% INCLUDE 'calendar.inc' %]
337
    [% INCLUDE 'js-date-format.inc' %]
338
    <script>
337
    <script>
339
        var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
338
        var sales_table = $("#sales").dataTable($.extend(true, {}, dataTablesDefaults, {
340
            orderFixed: [ 0, 'asc'],
339
            orderFixed: [ 0, 'asc'],
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reserve/request.tt (-29 / +1 lines)
Lines 1527-1561 Link Here
1527
1527
1528
            [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %]
1528
            [% UNLESS ( patron || patron.borrowernumber || borrowers || noitems || nobiblio ) %]
1529
                [% IF ( PatronAutoComplete ) %]
1529
                [% IF ( PatronAutoComplete ) %]
1530
                $( "#search_patron_filter" ).autocomplete({
1530
                    patron_autocomplete($("#search_patron_filter"), { 'link-to': 'reserve', 'url-params': '[% url_biblio_params | url %]' });
1531
                    source: "/cgi-bin/koha/circ/ysearch.pl",
1532
                    minLength: 3,
1533
                    select: function( event, ui ) {
1534
                        document.location.href = '/cgi-bin/koha/reserve/request.pl?[% url_biblio_params | url %]&borrowernumber=' + ui.item.borrowernumber;
1535
                    }
1536
                })
1537
                .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
1538
                    return $( "<li></li>" )
1539
                    .data( "ui-autocomplete-item", item )
1540
                    .append(
1541
                        "<a>"
1542
                            + ( item.surname ? item.surname.escapeHtml() : "" )
1543
                            + ", "
1544
                            + ( item.firstname ? item.firstname.escapeHtml() : "" )
1545
                            + " (" + ( item.cardnumber ? item.cardnumber.escapeHtml() : "" ) + ")"
1546
                            + " "
1547
                            + "<small>"
1548
                                + ( item.address ? item.address.escapeHtml() : "" )
1549
                                + " "
1550
                                + ( item.city ? item.city.escapeHtml() : "" )
1551
                                + " "
1552
                                + ( item.zipcode ? item.zipcode.escapeHtml() : "" )
1553
                                + " "
1554
                                + ( item.country ? item.country.escapeHtml() : "" )
1555
                            + "</small>"
1556
                        + "</a>" )
1557
                    .appendTo( ul );
1558
                };
1559
                [% END %]
1531
                [% END %]
1560
            [% END %]
1532
            [% END %]
1561
1533
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes.tt (-1 lines)
Lines 149-155 Link Here
149
149
150
[% MACRO jsinclude BLOCK %]
150
[% MACRO jsinclude BLOCK %]
151
    [% Asset.js("js/tools-menu.js") | $raw %]
151
    [% Asset.js("js/tools-menu.js") | $raw %]
152
    [% INCLUDE 'js-date-format.inc' %]
153
    [% INCLUDE 'datatables.inc' %]
152
    [% INCLUDE 'datatables.inc' %]
154
153
155
    <script>
154
    <script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/tags-review.js (-21 / +11 lines)
Lines 1-8 Link Here
1
$.ajaxSetup({
1
review_ajax_params = {
2
    url: "/cgi-bin/koha/tags/review.pl",
2
    url: "/cgi-bin/koha/tags/review.pl",
3
    type: "POST",
3
    type: "POST",
4
    dataType: "script"
4
    dataType: "script"
5
});
5
};
6
6
7
var ok_count  = 0;
7
var ok_count  = 0;
8
var nok_count = 0;
8
var nok_count = 0;
Lines 102-113 $(document).ready(function() { Link Here
102
        var gettitle;
102
        var gettitle;
103
        // window.alert(_("Click detected on ") + event.target + ": " + $(event.target).html);
103
        // window.alert(_("Click detected on ") + event.target + ": " + $(event.target).html);
104
        if ($(event.target).is('.ok')) {
104
        if ($(event.target).is('.ok')) {
105
            $.ajax({
105
            $.ajax(Object.assign({}, review_ajax_params, {
106
                data: {
106
                data: {
107
                    ok: $(event.target).attr("title")
107
                    ok: $(event.target).attr("title")
108
                },
108
                },
109
                success: count_approve // success_approve
109
                success: count_approve // success_approve
110
            });
110
            }));
111
            $(event.target).next(".rej").prop('disabled', false).css("color","#000");
111
            $(event.target).next(".rej").prop('disabled', false).css("color","#000");
112
            $(event.target).next(".rej").html("<i class='fa fa-remove' aria-hidden='false'></i> " + __("Reject"));
112
            $(event.target).next(".rej").html("<i class='fa fa-remove' aria-hidden='false'></i> " + __("Reject"));
113
            $(event.target).prop('disabled', true).css("color","#666");
113
            $(event.target).prop('disabled', true).css("color","#666");
Lines 123-134 $(document).ready(function() { Link Here
123
            }
123
            }
124
        }
124
        }
125
        if ($(event.target).is('.rej')) {
125
        if ($(event.target).is('.rej')) {
126
            $.ajax({
126
            $.ajax(Object.assign({}, review_ajax_params, {
127
                data: {
127
                data: {
128
                    rej: $(event.target).attr("title")
128
                    rej: $(event.target).attr("title")
129
                },
129
                },
130
                success: count_reject // success_reject
130
                success: count_reject // success_reject
131
            });
131
            }));
132
            $(event.target).prev(".ok").prop('disabled', false).css("color","#000");
132
            $(event.target).prev(".ok").prop('disabled', false).css("color","#000");
133
            $(event.target).prev(".ok").html("<i class='fa fa-check' aria-hidden='false'></i> " + __("Approve"));
133
            $(event.target).prev(".ok").html("<i class='fa fa-check' aria-hidden='false'></i> " + __("Approve"));
134
            $(event.target).prop('disabled', true).css("color","#666");
134
            $(event.target).prop('disabled', true).css("color","#666");
Lines 146-157 $(document).ready(function() { Link Here
146
        }
146
        }
147
        if ($(event.target).is('#test_button')) {
147
        if ($(event.target).is('#test_button')) {
148
            $(event.target).text( __("Testing...") ).prop('disabled', true);
148
            $(event.target).text( __("Testing...") ).prop('disabled', true);
149
            $.ajax({
149
            $.ajax(Object.assign({}, review_ajax_params, {
150
                data: {
150
                data: {
151
                    test: $('#test').attr("value")
151
                    test: $('#test').attr("value")
152
                },
152
                },
153
                success: success_test_call // success_reject
153
                success: success_test_call // success_reject
154
            });
154
            }));
155
            return false;   // cancel submit
155
            return false;   // cancel submit
156
        }
156
        }
157
    });
157
    });
Lines 159-177 $(document).ready(function() { Link Here
159
        if ((alerted +=1) <= 1){ window.alert( __("AJAX error (%s alert)").format(alerted) ); }
159
        if ((alerted +=1) <= 1){ window.alert( __("AJAX error (%s alert)").format(alerted) ); }
160
    });
160
    });
161
161
162
    var reviewerField = $("#approver");
162
    patron_autocomplete($("#approver"), { 'on-select-callback': function( event, ui ) {
163
    reviewerField.autocomplete({
163
            $("#approver").val( ui.item.patron_id );
164
        source: "/cgi-bin/koha/circ/ysearch.pl",
165
        minLength: 3,
166
        select: function( event, ui ) {
167
            reviewerField.val( ui.item.borrowernumber );
168
            return false;
164
            return false;
169
        }
165
        }
170
    })
166
    });
171
    .data( "ui-autocomplete" )._renderItem = function( ul, item ) {
172
        return $( "<li></li>" )
173
        .data( "ui-autocomplete-item", item )
174
        .append( "<a>" + item.surname + ", " + item.firstname + " (" + item.cardnumber + ") <small>" + item.address + " " + item.city + " " + item.zipcode + " " + item.country + "</small></a>" )
175
        .appendTo( ul );
176
    };
177
});
167
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/patron-autocomplete.js (+109 lines)
Line 0 Link Here
1
function patron_autocomplete(node, options) {
2
    let link_to;
3
    let url_params;
4
    let on_select_callback;
5
    if ( options ) {
6
        if ( options['link-to'] ) {
7
            link_to = options['link-to'];
8
        }
9
        if ( options['url-params'] ) {
10
            url_params = options['url-params'];
11
        }
12
        if ( options['on-select-callback'] ) {
13
            on_select_callback = options['on-select-callback'];
14
        }
15
    }
16
    return node.autocomplete({
17
        source: function( request, response ) {
18
                let params = {
19
                    '_page': 1,
20
                    '_per_page': 10,
21
                    'q': JSON.stringify([
22
                        {"me.firstname": {"like": "%"+request.term+"%"}},
23
                        {"me.surname": {"like": "%"+request.term+"%"}},
24
                        {"me.cardnumber": {"like": request.term+"%"}}
25
                    ]),
26
                    '_order_by': '+me.surname,+me.firstname',
27
                };
28
                $.ajax({
29
                    data: params,
30
                    type: 'GET',
31
                    url: '/api/v1/patrons',
32
                    headers: {
33
                        "x-koha-embed": "library"
34
                    },
35
                    success: function(data) {
36
                        return response(data);
37
                    },
38
                    error: function() {
39
                        alert( _("An error occurred. Check the logs") );
40
                        return response();
41
                    }
42
                });
43
        },
44
        minLength: 3,
45
        select: function( event, ui ) {
46
            if ( ui.item.link ) {
47
                window.location.href = ui.item.link;
48
            } else if ( on_select_callback ) {
49
                return on_select_callback(event, ui);
50
            }
51
        },
52
    })
53
    .data( "ui-autocomplete" )
54
    ._renderItem = function( ul, item ) {
55
        if ( link_to ) {
56
            item.link = link_to == 'circ'
57
                ? "/cgi-bin/koha/circ/circulation.pl"
58
                : link_to == 'reserve'
59
                    ? "/cgi-bin/koha/reserve/request.pl"
60
                    : "/cgi-bin/koha/members/moremember.pl";
61
            item.link += ( url_params ? '?' + url_params + '&' : "?" ) + 'borrowernumber=' + item.patron_id;
62
        } else {
63
            item.link = null;
64
        }
65
66
        var cardnumber = "";
67
        if( item.cardnumber != "" ){
68
            // Display card number in parentheses if it exists
69
            cardnumber = " (" + item.cardnumber + ") ";
70
        }
71
        if( item.branchcode == loggedInLibrary ){
72
            loggedInClass = "ac-currentlibrary";
73
        } else {
74
            loggedInClass = "";
75
        }
76
        return $( "<li></li>" )
77
        .addClass( loggedInClass )
78
        .data( "ui-autocomplete-item", item )
79
        .append(
80
            ""
81
            + ( item.link ? "<a href=\"" + item.link + "\">" : "<a>" )
82
                + ( item.surname ? item.surname.escapeHtml() : "" ) + ", "
83
                + ( item.firstname ? item.firstname.escapeHtml() : "" )
84
                + cardnumber.escapeHtml()
85
                + " <small>"
86
                    + ( item.date_of_birth
87
                        ?   $date(item.date_of_birth)
88
                          + "<span class=\"age_years\"> ("
89
                          + $get_age(item.date_of_birth)
90
                          + " "
91
                          + __("years")
92
                          + ")</span>,"
93
                        : ""
94
                    ) + " "
95
                    + ( item.address     ? item.address.escapeHtml() : "" )     + " "
96
                    + ( item.city        ? item.city.escapeHtml() : "" )        + " "
97
                    + ( item.zipcode     ? item.zipcode.escapeHtml() : "" )     + " "
98
                    + ( item.country     ? item.country.escapeHtml() : "" ) + " "
99
                    + ( !singleBranchMode
100
                        ?
101
                              "<span class=\"ac-library\">"
102
                            + item.library.name.escapeHtml()
103
                            + "</span>"
104
                        : "" )
105
                + "</small>"
106
            + "</a>" )
107
        .appendTo( ul );
108
    };
109
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/viewlog.js (-27 / +3 lines)
Lines 144-175 $(document).ready(function(){ Link Here
144
        e.preventDefault();
144
        e.preventDefault();
145
        $(".compare:checked").prop("checked", false).change();
145
        $(".compare:checked").prop("checked", false).change();
146
    });
146
    });
147
    var obj = $("#user").autocomplete({
147
    patron_autocomplete($("#user"), { 'on-select-callback': function ( event, ui ) {
148
        source: "/cgi-bin/koha/circ/ysearch.pl",
148
            $("#user").val( ui.item.patron_id );
149
        minLength: 3,
150
        select: function ( event, ui ) {
151
            $("#user").val( ui.item.borrowernumber );
152
            return false;
149
            return false;
153
        }
150
        }
154
    }).data("ui-autocomplete");
151
    });
155
    if (obj) {
156
        obj._renderItem = function (ul, item) {
157
            var cardnumber = "";
158
            if (item.cardnumber != "") {
159
                // Display card number in parentheses if it exists
160
                cardnumber = " (" + item.cardnumber + ") ";
161
            }
162
            var itemString = "<a href=\"#\">" + (item.surname ? item.surname.escapeHtml() : "") + ", " + (item.firstname ? item.firstname.escapeHtml() : "") + cardnumber.escapeHtml() + " <small>";
163
            itemString += (item.address ? item.address.escapeHtml() : "") + " "
164
                + (item.city ? item.city.escapeHtml() : "") + " "
165
                + (item.zipcode ? item.zipcode.escapeHtml() : "") + " "
166
                + (item.country ? item.country.escapeHtml() : "")
167
                + "</small></a>";
168
            return $("<li></li>")
169
                .data("ui-autocomplete-item", item)
170
                .append(itemString)
171
                .appendTo(ul);
172
        };
173
    }
174
175
});
152
});
176
- 

Return to bug 30578