[Rt-commit] rt branch 5.0/cf-autocomplete-users created. rt-5.0.4-243-g0efb81e713

BPS Git Server git at git.bestpractical.com
Fri Oct 13 22:09:55 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/cf-autocomplete-users has been created
        at  0efb81e713279c189a99518457a597ef0152dfb6 (commit)

- Log -----------------------------------------------------------------
commit 0efb81e713279c189a99518457a597ef0152dfb6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Oct 13 17:39:22 2023 -0400

    Support to autocomplete users/groups for Autocomplete custom fields

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 79c1f1f5a5..76bf5c4c0a 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -646,6 +646,10 @@ sub Values {
     my $self = shift;
 
     my $class = $self->ValuesClass;
+
+    # For back compatibility, autocomplete user/group cfs are not supposed to use Values
+    $class = 'RT::CustomFieldValues' if $class =~ /^RT::(?:Users|Groups)::/;
+
     if ( $class ne 'RT::CustomFieldValues') {
         RT::StaticUtil::RequireModule($class) or die "Can't load $class: $@";
     }
@@ -870,6 +874,7 @@ sub ValidateValuesClass {
 
     return 1 if !$class || $class eq 'RT::CustomFieldValues';
     return 1 if grep $class eq $_, RT->Config->Get('CustomFieldValuesSources');
+    return 1 if $self->Type eq 'Autocomplete' && $class =~ /^RT::(?:Users|Groups)::/;
     return undef;
 }
 
diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index beee4675a0..88d6923424 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -82,7 +82,7 @@
 </&>
 % }
 
-% if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) {
+% if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and ( $CustomFieldObj->Type eq 'Autocomplete' or ( RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) ) ) {
 
 <&| /Elements/LabeledValue, Label => loc("Field values source") &>
     <& /Admin/Elements/EditCustomFieldValuesSource, CustomField => $CustomFieldObj &>
diff --git a/share/html/Admin/Elements/EditCustomFieldValuesSource b/share/html/Admin/Elements/EditCustomFieldValuesSource
index b84b77aef1..aff94671c9 100644
--- a/share/html/Admin/Elements/EditCustomFieldValuesSource
+++ b/share/html/Admin/Elements/EditCustomFieldValuesSource
@@ -72,6 +72,11 @@ foreach my $class( 'RT::CustomFieldValues', RT->Config->Get('CustomFieldValuesSo
     push @sources, \%res;
 }
 
+if ( $CustomField->Type eq 'Autocomplete' ) {
+    push @sources, { Class => "RT::Users::$_", Description => loc('RT user [_1]', $_) } for qw/id Name EmailAddress/;
+    push @sources, { Class => "RT::Groups::$_", Description => loc('RT group [_1]', $_) } for qw/id Name/;
+}
+
 return unless grep $_->{'Class'} ne 'RT::CustomFieldValues', @sources;
 
 </%INIT>
diff --git a/share/html/Elements/EditCustomFieldAutocomplete b/share/html/Elements/EditCustomFieldAutocomplete
index 40104555ae..9a393d0820 100644
--- a/share/html/Elements/EditCustomFieldAutocomplete
+++ b/share/html/Elements/EditCustomFieldAutocomplete
@@ -53,8 +53,14 @@ cols="<% $Cols %>" \
 % if ( defined $Rows ) {
 rows="<% $Rows %>" \
 % }
-name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control"><% $Default || '' %></textarea>
+name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control no-selectize"
+% if ( $CustomField->ValuesClass =~ /^RT::(Users|Groups)::(\w+)/ ) {
+data-autocomplete="<% $1 %>" data-autocomplete-return="<% $2 %>" data-autocomplete-multiple="1"
+% }
+
+><% $Default || '' %></textarea>
 
+% if ( $CustomField->ValuesClass !~ /^RT::(?:Users|Groups)::/ ) {
 <script type="text/javascript">
 var id = <% "$name" |n,j%>;
 id = id.replace(/:/g,'\\:');
@@ -77,8 +83,17 @@ jQuery('#'+id).autocomplete( {
     }
 }
 );
+% }
+
 % } else {
-<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control" value="<% $Default || '' %>"/>
+<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control" value="<% $Default || '' %>"
+% if ( $CustomField->ValuesClass =~ /^RT::(Users|Groups)::(\w+)/ ) {
+data-autocomplete="<% $1 %>" data-autocomplete-return="<% $2 %>"
+% }
+/>
+
+% if ( $CustomField->ValuesClass !~ /^RT::(?:Users|Groups)::/ ) {
+
 <script type="text/javascript">
 var id = <% $name |n,j%>;
 id = id.replace(/:/g,'\\:');
@@ -86,6 +101,8 @@ jQuery('#'+id).autocomplete( {
     source: RT.Config.WebHomePath + "/Helpers/Autocomplete/CustomFieldValues?"+<% $Context |n,j %>+<% $name |n,u,j%>
 }
 );
+% }
+
 % }
 </script>
 <%INIT>
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index c967050ddf..0fdaad8631 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -43,7 +43,7 @@ Selectize.define('rt_drag_drop', function(options) {
 
 window.RT.Autocomplete.bind = function(from) {
 
-    jQuery("input[data-autocomplete]", from).each(function(){
+    jQuery(":input[data-autocomplete]", from).each(function(){
         var input = jQuery(this);
         var what  = input.attr("data-autocomplete");
         var wants = input.attr("data-autocomplete-return");
@@ -51,7 +51,7 @@ window.RT.Autocomplete.bind = function(from) {
         if (!what || !window.RT.Autocomplete.Classes[what])
             return;
 
-        if ( (what === 'Users' || what === 'Principals') && input.is('[data-autocomplete-multiple]')) {
+        if ( (what === 'Users' || what === 'Principals') && input.is('[data-autocomplete-multiple]') && !input.hasClass('no-selectize') ) {
             var options = input.attr('data-options');
             var items = input.attr('data-items');
             input.selectize({
@@ -151,7 +151,12 @@ window.RT.Autocomplete.bind = function(from) {
 
         if (input.is('[data-autocomplete-multiple]')) {
             if ( what != 'Tickets' ) {
-                queryargs.push("delim=,");
+                if ( input.is('textarea') ) {
+                    queryargs.push("delim=%0A");
+                }
+                else {
+                    queryargs.push("delim=,");
+                }
             }
 
             options.focus = function () {
@@ -160,7 +165,7 @@ window.RT.Autocomplete.bind = function(from) {
             }
 
             options.select = function(event, ui) {
-                var terms = this.value.split(what == 'Tickets' ? /\s+/ : /,\s*/);
+                var terms = this.value.split(what == 'Tickets' ? /\s+/ : input.is('textarea') ? /\n+/ : /,\s*/);
                 terms.pop();                    // remove current input
                 if ( what == 'Tickets' ) {
                     // remove non-integers in case subject search with spaces in (like "foo bar")
@@ -175,7 +180,7 @@ window.RT.Autocomplete.bind = function(from) {
                 }
                 terms.push( ui.item.value );    // add selected item
                 terms.push(''); // add trailing delimeter so user can input another value directly
-                this.value = terms.join(what == 'Tickets' ? ' ' : ", ");
+                this.value = terms.join(what == 'Tickets' ? ' ' : input.is('textarea') ? "\n" : ',');
                 jQuery(this).change();
 
                 return false;

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list