%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2019 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 }}}
-<& /Admin/Elements/Header, Title => $title &>
+<& /Admin/Elements/Header,
+ Title => $title,
+ Focus => (($added_cfv or $ARGS{FocusAddValue})
+ ? "input[name=CustomField-$id-Value-new-Name]"
+ : undef),
+ &>
<& /Elements/Tabs &>
<& /Elements/ListActions, actions => \@results &>
<i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
</div></td></tr>
-% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
+% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType ) {
<tr class="categoriesbasedon"><td class="label"><&|/l&>Categories are based on</&></td><td>
<& /Admin/Elements/SelectCustomField,
Name => "BasedOn",
<tr><td class="label"> </td><td>
<input type="hidden" class="hidden" name="SetEnabled" value="1" />
-<input type="checkbox" class="checkbox" name="Enabled" value="1" <% $EnabledChecked |n%> />
-<&|/l&>Enabled (Unchecking this box disables this custom field)</&>
+<input type="checkbox" class="checkbox" id="Enabled" name="Enabled" value="1" <% $EnabledChecked |n %> />
+<label for="Enabled"><&|/l&>Enabled (Unchecking this box disables this custom field)</&></label>
</td></tr>
% $m->callback(CallbackName => 'EndOfTable', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
<& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
</form>
+% $m->callback(%ARGS, CallbackName => 'EndOfPage', CustomFieldObj => $CustomFieldObj);
<%INIT>
-my ($title, @results);
+my ($title, @results, $added_cfv);
my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
-$m->callback(CallbackName => 'Initial', Pattern => \$Pattern, ARGSRef => \%ARGS);
+$m->callback(CallbackName => 'Initial', Pattern => \$Pattern, Results => \@results, ARGSRef => \%ARGS);
unless ( $id ) {
$title = loc("Create a CustomField");
LinkValueTo => $LinkValueTo,
IncludeContentForValue => $IncludeContentForValue,
BasedOn => $BasedOn,
- Disabled => !$Enabled,
+ Disabled => ($Enabled ? 0 : 1),
NoClone => !$YesClone,
);
if (!$val) {
$_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
);
push (@results, $msg);
+ $added_cfv = 1 if $id;
my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
$cfv->Load($id);
}
}
+if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
+ my ( $ret, $msg );
+ my $object = $CustomFieldObj->RecordClassFromLookupType->new( $session{'CurrentUser'} );
+
+ if ( $CustomFieldObj->Disabled && $CustomFieldObj->IsGlobal ) {
+ ( $ret, $msg ) = $CustomFieldObj->RemoveFromObject($object);
+ }
+ elsif ( !$CustomFieldObj->Disabled && !$CustomFieldObj->IsGlobal ) {
+ ( $ret, $msg ) = $CustomFieldObj->AddToObject($object);
+ }
+
+ # successful msg("object created" or "object deleted ) is useless here
+ push @results, $msg unless $ret;
+}
+
$id = $CustomFieldObj->id if $CustomFieldObj->id;
# This code does automatic redirection if any updates happen.
MaybeRedirectForResults(
Actions => \@results,
- Arguments => { id => $id },
+ Arguments => { id => $id, FocusAddValue => ($added_cfv ? 1 : 0) },
) if $CustomFieldObj->id;