%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2019 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-% $r->content_type('application/json');
+% $r->content_type('application/json; charset=utf-8');
<% JSON( \@suggestions ) |n %>
% $m->abort;
<%ARGS>
$return => 'Name'
$limit => undef
$term => undef
-$max => 10
+$max => undef
</%ARGS>
<%INIT>
# Only allow certain return fields
my $CurrentUser = $session{'CurrentUser'};
-my %fields = %{ RT->Config->Get('UserAutocompleteFields')
- || { EmailAddress => 1, Name => 1, RealName => 'LIKE' } };
-
my %user_uniq_hash;
my $isSU = $session{CurrentUser}
->HasRight( Right => 'SuperUser', Object => $RT::System );
+$m->callback( CallbackName => 'ModifyMaxResults', max => \$max );
+$max //= 10;
+
# Turn RT::Ticket-1|RT::Queue-2 into ['RT::Ticket', 1], ['RT::Queue', 2]
foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) {
next unless $spec->[0] =~ /^RT::(Ticket|Queue)$/;
}
my $Users = RT::Users->new( $session{CurrentUser} );
- $Users->RowsPerPage( $max );
-
# Limit by our autocomplete term BEFORE we limit to OwnTicket because that
# does a funky union hack
- while (my ($name, $op) = each %fields) {
- $op = 'STARTSWITH'
- unless $op =~ /^(?:LIKE|(?:START|END)SWITH)$/i;
-
- $Users->Limit(
- FIELD => $name,
- OPERATOR => $op,
- VALUE => $term,
- ENTRYAGGREGATOR => 'OR',
- SUBCLAUSE => 'autocomplete',
- );
- }
+ $Users->SimpleSearch(
+ Max => $max,
+ Term => $term,
+ Return => $return,
+ );
$Users->WhoHaveRight(
Right => 'OwnTicket',
next if $user_uniq_hash{ $User->Id };
$user_uniq_hash{ $User->Id() } = [
$User,
- $m->scomp('/Elements/ShowUser', User => $User, NoEscape => 1)
+ $User->Format,
];
}
}
if ( not $user_uniq_hash{RT->Nobody->id} and $term =~ $nobody ) {
$user_uniq_hash{RT->Nobody->id} = [
RT->Nobody,
- $m->scomp('/Elements/ShowUser', User => RT->Nobody, NoEscape => 1)
+ RT->Nobody->Format,
];
}