X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Fshare%2Fhtml%2FHelpers%2FAutocomplete%2FCustomFieldValues;h=b8b21e4fead8c3459a088ab0928a1b736fa39c47;hb=43a06151e47d2c59b833cbd8c26d97865ee850b6;hp=85323ccc3994e09ce4685d57da5ea730c57eb5fc;hpb=6587f6ba7d047ddc1686c080090afe7d53365bd4;p=freeside.git diff --git a/rt/share/html/Helpers/Autocomplete/CustomFieldValues b/rt/share/html/Helpers/Autocomplete/CustomFieldValues index 85323ccc3..b8b21e4fe 100644 --- a/rt/share/html/Helpers/Autocomplete/CustomFieldValues +++ b/rt/share/html/Helpers/Autocomplete/CustomFieldValues @@ -2,7 +2,7 @@ %# %# COPYRIGHT: %# -%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC +%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) @@ -45,37 +45,50 @@ %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} - +% $r->content_type('application/json'); +<% JSON( \@suggestions ) |n %> % $m->abort; <%INIT> -my ($CustomField, $Value); -while( my($k, $v) = each %ARGS ) { +# Only autocomplete the last value +my $term = (split /\n/, $ARGS{term} || '')[-1]; + +my $CustomField; +for my $k ( keys %ARGS ) { next unless $k =~ /^Object-.*?-\d*-CustomField-(\d+)-Values?$/; - ($CustomField, $Value) = ($1, $v); + $CustomField = $1; last; } + $m->abort unless $CustomField; my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} ); $CustomFieldObj->Load( $CustomField ); + my $values = $CustomFieldObj->Values; $values->Limit( FIELD => 'Name', OPERATOR => 'LIKE', - VALUE => $Value, - SUBCLAUSE => 'autcomplete', + VALUE => $term, + SUBCLAUSE => 'autocomplete', + CASESENSITIVE => 0, ); $values->Limit( ENTRYAGGREGATOR => 'OR', FIELD => 'Description', OPERATOR => 'LIKE', - VALUE => $Value, - SUBCLAUSE => 'autcomplete', + VALUE => $term, + SUBCLAUSE => 'autocomplete', + CASESENSITIVE => 0, ); +my @suggestions; + +while( my $value = $values->Next ) { + push @suggestions, + { + value => $value->Name, + label => $value->Description + ? $value->Name . ' (' . $value->Description . ')' + : $value->Name, + }; +}