Skip to content

Commit

Permalink
Merge branch '6.0/edit-custom-field-content'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrandtbuffalo committed Feb 14, 2025
2 parents bb88aca + 8546c5c commit cc6a508
Showing 1 changed file with 93 additions and 69 deletions.
162 changes: 93 additions & 69 deletions share/html/Elements/EditCustomField
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,96 @@
%#
%# END BPS TAGGED BLOCK }}}

% if ( $ShowLabel ) {
<&| /Elements/LabeledValue,
Label => ( $Label ? $Label : $CustomField->Name ),
LabelFor => $Name,
LabelTooltip => $CustomField->EntryHint,
FormText => $FormText &>
<& SELF:Content, %ARGS, Name => $Name, Default => $Default, CFHintId => $CFHintId &>
</&>
% } else {
<& SELF:Content, %ARGS, Name => $Name, Default => $Default, CFHintId => $CFHintId &>
% }

<%INIT>
my $Type = $CustomField->Type;
unless ( $Type ) {
# Type is required, bail if we can't get it
RT->Logger->error( "Unable to load a type for Custom field #". $CustomField->id );
return;
}

$Grouping =~ s/\W//g if $Grouping;
my $Name;
if ( !$NamePrefix ) {
$Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
}

my $CFHintId;
my $cf_name_prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );

if ($ShowHints and $CustomField->FriendlyPattern) {
$CFHintId = $cf_name_prefix . 'Hint';
}

# Always fill $Default with submited values if it's empty
if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
my %TOP = %$DECODED_ARGS;
$Default = $TOP{ $Name } if $Name;
# check both -Values and -Value for back compatibility
if ( $NamePrefix ) {
$Default //= $TOP{ $NamePrefix . $CustomField->Id . '-Values' }
// $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
}
else {
$Default //= $TOP{ $cf_name_prefix . 'Values' } // $TOP{ $cf_name_prefix . 'Value' };
}
}

if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
$Default = $CustomField->DefaultValues(Object => $on || RT->System);
}

my $FormText;
if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

</%INIT>
<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$ShowLabel => 1
</%ARGS>

<%METHOD Content>

<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$Name => undef
$CFHintId => undef
</%ARGS>
<%perl>
$m->comp(
$EditComponent,
Expand All @@ -69,32 +153,23 @@ $m->comp(
$CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
DescribedBy => $CFHintId,
AddClass => $AddClass,
);
);

if ( $error_msg ) {
</%perl>
<span id="<% $CFHintId %>" class="form-text invalid-feedback cfinvalidfield d-inline-block"><% $error_msg %></span>
<span id="<% $CFHintId %>" class="form-text invalid-feedback cfinvalidfield d-inline-block"><% $error_msg %></span>
% } elsif ($ShowHints and $CustomField->FriendlyPattern) {
<span id="<% $CFHintId %>" class="form-text cfhints d-inline-block">
<% $CustomField->FriendlyPattern %>
</span>
<span id="<% $CFHintId %>" class="form-text cfhints d-inline-block">
<% $CustomField->FriendlyPattern %>
</span>
% }
% $m->callback( CallbackName => 'AfterCustomFieldValue', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );
</&>
% $m->callback( CallbackName => 'AfterCustomFieldValue', CallbackPage => '/Elements/EditCustomField', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );

<%INIT>

my $Type = $CustomField->Type;
unless ( $Type ) {
# if we can't see the type, all hell will break loose.
$RT::Logger->error( "Custom field #". $CustomField->id ." has empty type" );
return;
}

my $Values;
if ( $Object ) {
$Grouping =~ s/\W//g if $Grouping;

if ( $Object ) {
if ( $Object->Id ) {
$Values = $Object->CustomFieldValues( $CustomField->id );
$Values->Columns(
Expand All @@ -107,37 +182,6 @@ if ( $Object ) {
}
}

my $Name;
if ( !$NamePrefix ) {
$Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
}

my $CFHintId;
my $cf_name_prefix = GetCustomFieldInputNamePrefix(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );

if ($ShowHints and $CustomField->FriendlyPattern) {
$CFHintId = $cf_name_prefix . 'Hint';
}

# Always fill $Default with submited values if it's empty
if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
my %TOP = %$DECODED_ARGS;
$Default = $TOP{ $Name } if $Name;
# check both -Values and -Value for back compatibility
if ( $NamePrefix ) {
$Default //= $TOP{ $NamePrefix . $CustomField->Id . '-Values' }
// $TOP{ $NamePrefix . $CustomField->Id . '-Value' };
}
else {
$Default //= $TOP{ $cf_name_prefix . 'Values' } // $TOP{ $cf_name_prefix . 'Value' };
}
}

if ( (!$Object || !$Object->id) && ( !defined $Default || !length $Default ) && $CustomField->SupportDefaultValues ) {
my ( $on ) = grep {$_->isa($CustomField->RecordClassFromLookupType)} $CustomField->ACLEquivalenceObjects;
$Default = $CustomField->DefaultValues(Object => $on || RT->System);
}

my $MaxValues = $CustomField->MaxValues;
if ($MaxValues == 1 && $Values) {
# what exactly is this doing? Without the "unless" it breaks RTFM
Expand Down Expand Up @@ -183,27 +227,7 @@ if ( $m->notes('InvalidField-' . $CustomField->Id . ($Grouping ? "-$Grouping" :
}

my $EditComponent = "EditCustomField$Type";
$m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$m->callback( %ARGS, CallbackName => 'EditComponentName', CallbackPage => '/Elements/EditCustomField', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$EditComponent = "EditCustomField$Type" unless $m->comp_exists($EditComponent);

my $FormText;

if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

</%INIT>
<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$Label => undef
</%ARGS>
</%METHOD>

0 comments on commit cc6a508

Please sign in to comment.