%# BEGIN LICENSE BLOCK %# %# Copyright (c) 2002-2003 Jesse Vincent %# %# This program is free software; you can redistribute it and/or modify %# it under the terms of version 2 of the GNU General Public License %# as published by the Free Software Foundation. %# %# A copy of that license should have arrived with this %# software, but in any event can be snarfed from www.gnu.org. %# %# This program is distributed in the hope that it will be useful, %# but WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %# GNU General Public License for more details. %# %# END LICENSE BLOCK <& /RTFM/Admin/Elements/CustomFieldTabs, id => $CustomFieldObj->Id , current_tab => $current_subtab, Title => $title &> <& /Elements/ListActions, actions => \@results &>

% if ($CustomFieldObj->Id && $CustomFieldObj->Type =~ /^Select/i) {

<&|/l&>Values

<&|/l&>Name
<&|/l&>Description
<&|/l&>Type <& /RTFM/Admin/Elements/SelectCustomFieldType, Name => "Type", Default => $CustomFieldObj->Type &>
<&|/l&>Sort Order
<& /RTFM/Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &> <& /RTFM/Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
% } <&/Elements/Submit&>
<%INIT> my $CustomFieldObj = RT::FM::CustomField->new( $session{'CurrentUser'} ); my ( $title, @results); if ( !$id ) { $title = loc("Create a CustomField"); $id = 'new'; } else { if ( $id eq 'new' ) { my ( $val, $msg ) = $CustomFieldObj->Create(Name => $Name, Type => $Type, Description => $Description, SortOrder => $SortOrder ); $m->comp("/RTFM/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless ($val); push @results, $msg; $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name() ); } else { $CustomFieldObj->Load($id) || $m->comp("/RTFM/Elements/Error", Why => loc('No CustomField') ); $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() ); my @attribs = qw( Name Type Description SortOrder); my @aresults = UpdateRecordObject( AttributesRef => \@attribs, Object => $CustomFieldObj, ARGSRef => \%ARGS ); push @results, @aresults; } $id = $CustomFieldObj->id; } my $paramtag = "CustomField-".$CustomFieldObj->Id."-Value-"; # Delete any fields that want to be deleted foreach my $key (keys %ARGS) { next unless ($key =~ /^Delete-$paramtag(\d+)$/); my ($val, $msg) = $CustomFieldObj->DeleteValue($1); push (@results, $msg); } # Update any existing values my $values = $CustomFieldObj->ValuesObj; while (my $value = $values->Next) { foreach my $attr qw(Name Description SortOrder) { my $param = $paramtag.$value->Id."-".$attr; if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param})) { my $mutator = "Set$attr"; my ($id, $msg) = $value->$mutator($ARGS{$param}); push (@results, $msg); } } } # Add any new values if ($ARGS{$paramtag."new-Name"}) { my ($id, $msg) = $CustomFieldObj->AddValue ( Name => $ARGS{$paramtag."new-Name"}, Description => $ARGS{$paramtag."new-Description"}, SortOrder => $ARGS{$paramtag."new-SortOrder"}); push (@results, $msg); } my $current_subtab; if ($ARGS{'Create'}){ $current_subtab = "RTFM/Admin/CustomFields/Basics.html?Create=1"; } else { $current_subtab = "RTFM/Admin/CustomFields/Basics.html?id=".$id; } <%ARGS> $id => undef $Type => undef $SortOrder => undef $Description => undef $Name => undef