[Rt-commit] rt branch 5.0/admin-user-search-cf-inputs created. rt-5.0.3-224-g8404b5dba1

BPS Git Server git at git.bestpractical.com
Wed Jan 4 21:19:49 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/admin-user-search-cf-inputs has been created
        at  8404b5dba172a18ed83dbab0b1d3a3771653fd32 (commit)

- Log -----------------------------------------------------------------
commit 8404b5dba172a18ed83dbab0b1d3a3771653fd32
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jan 5 05:02:37 2023 +0800

    Show customized operator/value inputs for cfs on admin user search page
    
    This is to mirror the similar behavior on query builder.

diff --git a/share/html/Admin/Users/index.html b/share/html/Admin/Users/index.html
index bb76a12efe..c7afd2d45e 100644
--- a/share/html/Admin/Users/index.html
+++ b/share/html/Admin/Users/index.html
@@ -134,6 +134,69 @@ jQuery(function(){
         UserString      => $UserString3,
     &>
   </div>
+% foreach ( @lines ) {
+  <& /Search/Elements/ConditionRow, Condition => $_ &>
+% }
+
+<script type="text/javascript">
+jQuery(function() {
+    var orig_op;
+    var orig_value;
+    jQuery('select[name^=UserField]').change(function() {
+        var form = jQuery(this).closest('form');
+        var row = jQuery(this).closest('div.form-row');
+        var val = jQuery(this).val();
+
+        orig_op ||= form.find(':input[name=UserOp]').clone().val('LIKE');
+        orig_value ||= form.find(':input[name=UserString]').clone().val('');
+
+        var new_operator;
+        var new_value;
+        if ( val.match(/CustomField-/) ) {
+            new_operator = form.find(':input[name="' + val + 'Op"]:first').clone();
+
+            var new_value = form.find(':input[name="ValueOf' + val + '"]:first');
+            if ( new_value.hasClass('ui-autocomplete-input') ) {
+                var source = new_value.autocomplete( "option" ).source;
+                new_value = new_value.clone();
+                new_value.autocomplete({ source: source });
+            }
+            else {
+                new_value = new_value.clone();
+            }
+
+            new_value.attr('id', null);
+        }
+        else {
+            new_operator = orig_op;
+            new_value = orig_value;
+        }
+
+        new_operator.attr('name', jQuery(this).attr('name').replace(/Field/, 'Op'));
+        new_value.attr('name', jQuery(this).attr('name').replace(/Field/, 'String'));
+
+        row.children('div.operator').children().remove();
+        row.children('div.operator').append(new_operator);
+        row.children('div.operator').find('select.selectpicker').selectpicker();
+
+        row.children('div.value').children().remove();
+        row.children('div.value').append(new_value);
+        row.children('div.value').find('select.selectpicker').selectpicker();
+        if ( new_value.hasClass('datepicker') ) {
+            new_value.removeClass('hasDatepicker');
+            initDatePicker(row);
+        }
+    });
+
+%   for my $suffix ( '', 2 .. 3 ) {
+%       if ( ($DECODED_ARGS->{"UserField$suffix"} // '') =~ /^CustomField-/ ) {
+            jQuery('select[name=UserField<% $suffix %>]').change();
+            jQuery(':input[name=UserOp<% $suffix %>]').val(<% $DECODED_ARGS->{"UserOp$suffix"} |n,j %>).change();
+            jQuery(':input[name=UserString<% $suffix %>]').val(<% $DECODED_ARGS->{"UserString$suffix"} |n,j %>).change();
+%       }
+%   }
+});
+</script>
 
   <div class="form-row">
     <div class="label col-3 text-left pt-1">
@@ -284,6 +347,52 @@ for my $name (@attrs) {
 
     push @fields, [ $name, $label || $name ];
 }
+
+my $CustomFields = RT::CustomFields->new($session{'CurrentUser'});
+$CustomFields->LimitToLookupType('RT::User');
+
+# Based on /Search/Elements/PickCFs, with different input names
+my @lines;
+while ( my $CustomField = $CustomFields->Next ) {
+    my %line = ( Class => 'hidden' );
+    $line{'Name'} = "CustomField-" . $CustomField->id;
+    $line{'Field'} = $CustomField->Name;
+
+    # Op
+    if ($CustomField->Type =~ /^Date(Time)?$/ ) {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectDateRelation',
+            Arguments => {},
+        };
+    }
+    elsif ($CustomField->Type =~ /^IPAddress(Range)?$/ ) {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectIPRelation',
+            Arguments => {},
+        };
+    } else {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectCustomFieldOperator',
+            Arguments => { True => loc("is"),
+                           False => loc("isn't"),
+                           TrueVal=> '=',
+                           FalseVal => '!=',
+                         },
+        };
+    }
+
+    # Value
+    $line{'Value'} = {
+        Type => 'component',
+        Path => '/Elements/SelectCustomFieldValue',
+        Arguments => { CustomField => $CustomField },
+    };
+
+    push @lines, \%line;
+}
 </%INIT>
 <%ARGS>
 $Format => undef,
diff --git a/share/html/Elements/SelectUsers b/share/html/Elements/SelectUsers
index 65f1794794..0c0aba5e52 100644
--- a/share/html/Elements/SelectUsers
+++ b/share/html/Elements/SelectUsers
@@ -56,10 +56,10 @@
 % }
   </select>
 </div>
-<div class="col-3">
+<div class="col-3 operator">
   <& /Elements/SelectMatch, Name => $SelectOpName, Default => $UserOp &>
 </div>
-<div class="col-3">
+<div class="col-3 value">
   <input type="text" size="8" name="<% $InputStringName %>" value="<% $UserString %>" class="form-control" />
 </div>
 <%INIT>

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list