X-Git-Url: http://git.uio.no/git/?p=usit-rt.git;a=blobdiff_plain;f=share%2Fhtml%2FHelpers%2FAutocomplete%2FOwners;h=6b8147f5acc6786d67aa831976a3cd8afd4ee07b;hp=1d065f2a27ee42ca6d5b27d639417848fbcdcf3e;hb=c33a4027369d767810c2d24ad54d6e61599ff823;hpb=84fb5b46b6d278400211552181bac9e6def7d09d diff --git a/share/html/Helpers/Autocomplete/Owners b/share/html/Helpers/Autocomplete/Owners index 1d065f2..6b8147f 100644 --- a/share/html/Helpers/Autocomplete/Owners +++ b/share/html/Helpers/Autocomplete/Owners @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -45,14 +45,14 @@ %# 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 <%INIT> # Only allow certain return fields @@ -65,13 +65,13 @@ $m->abort unless defined $return 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)$/; @@ -89,22 +89,13 @@ foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) { } 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', @@ -117,7 +108,7 @@ foreach my $spec (map { [split /\-/, $_, 2] } split /\|/, $limit) { next if $user_uniq_hash{ $User->Id }; $user_uniq_hash{ $User->Id() } = [ $User, - $m->scomp('/Elements/ShowUser', User => $User, NoEscape => 1) + $User->Format, ]; } } @@ -127,7 +118,7 @@ my $nobody = qr/^n(?:o(?:b(?:o(?:d(?:y)?)?)?)?)?$/i; 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, ]; }