rt 4.2.13 ticket#13852
[freeside.git] / rt / share / html / Helpers / Autocomplete / Owners
index be4a856..12038c7 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2016 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
@@ -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,
     ];
 }