rt 4.2.14 (#13852)
[freeside.git] / rt / share / html / Helpers / Autocomplete / Groups
index b6a6f1a..7cfd618 100644 (file)
@@ -2,7 +2,7 @@
 %#
 %# COPYRIGHT:
 %#
-%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2017 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>
 $term => undef
-$max => 10
+$max => undef
 $exclude => ''
 $op => 'LIKE'
 </%ARGS>
@@ -66,6 +66,9 @@ $m->abort unless $CurrentUser->Privileged;
 # Sanity check the operator
 $op = 'LIKE' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
 
+$m->callback( CallbackName => 'ModifyMaxResults', max => \$max );
+$max //= 10;
+
 my $groups = RT::Groups->new( $CurrentUser );
 $groups->RowsPerPage( $max );
 $groups->LimitToUserDefinedGroups();
@@ -73,6 +76,7 @@ $groups->Limit(
     FIELD           => 'Name',
     OPERATOR        => $op,
     VALUE           => $term,
+    CASESENSITIVE   => 0,
 );
 
 # Exclude groups we don't want
@@ -83,6 +87,8 @@ foreach (split /\s*,\s*/, $exclude) {
 my @suggestions;
 
 while ( my $group = $groups->Next ) {
-    push @suggestions, $group->Name;
+    my $suggestion = { id => $group->Id, label => $group->Name, value => $group->Name };
+    $m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, group => $group );
+    push @suggestions, $suggestion;
 }
 </%INIT>