%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2012 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>
# 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();
FIELD => 'Name',
OPERATOR => $op,
VALUE => $term,
+ CASESENSITIVE => 0,
);
# Exclude groups we don't want
foreach (split /\s*,\s*/, $exclude) {
- $groups->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=');
+ $groups->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=', ENTRYAGGREGATOR => 'AND');
}
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>