1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 %# CONTRIBUTION SUBMISSION POLICY:
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
45 %# END BPS TAGGED BLOCK }}}
46 <& /Admin/Elements/Header, Title => $title &>
47 <& /Admin/Elements/CustomFieldTabs,
48 id => $CustomFieldObj->Id ,
49 current_tab => $current_tab,
51 <& /Elements/ListActions, actions => \@results &>
54 <FORM METHOD="POST" ACTION="Modify.html" NAME="ModifyCustomField">
55 <INPUT TYPE=HIDDEN NAME="id" VALUE="<%$id %>">
58 <td class="label"><&|/l&>Name</&></td>
59 <td><input name="Name" VALUE="<%$CustomFieldObj->Name%>" SIZE=20></td></tr>
61 <td class="label"><&|/l&>Description</&></td>
62 <td><input name="Description" VALUE="<%$CustomFieldObj->Description%>" SIZE=80></td>
66 <td class="label"><&|/l&>Type</&></td>
67 <td><& /Admin/Elements/SelectCustomFieldType,
68 Name => "TypeComposite",
69 Default => $CustomFieldObj->TypeComposite, &>
73 <td class="label"><&|/l&>Applies to</&></td>
74 <td><& /Admin/Elements/SelectCustomFieldLookupType,
76 Default => $CustomFieldObj->LookupType, &>
80 <td class="label"> </td>
82 <INPUT TYPE=HIDDEN NAME="SetEnabled" VALUE="1">
83 <INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
88 % if ($CustomFieldObj->Id && $CustomFieldObj->Type =~ /^Select/i) {
89 <H2><&|/l&>Values</&></H2>
91 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
92 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
104 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
105 my ( $title, @results, $EnabledChecked, $Disabled);
106 $EnabledChecked = "CHECKED";
109 $title = loc("Create a CustomField");
114 if ( $id eq 'new' ) {
115 my ( $val, $msg ) = $CustomFieldObj->Create(Name => $Name,
116 TypeComposite => $TypeComposite,
117 LookupType => $LookupType,
118 Description => $Description,);
119 $m->comp("/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless ($val);
121 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name() );
124 $CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
125 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() );
127 my @attribs = qw( Name TypeComposite LookupType Description);
128 my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
129 Object => $CustomFieldObj,
132 push @results, @aresults;
134 #we're asking about enabled on the web page but really care about disabled.
141 if ( ($SetEnabled) and ( $Disabled != $CustomFieldObj->Disabled) ) {
142 my ($code, $msg) = $CustomFieldObj->SetDisabled($Disabled);
143 push @results, loc('Enabled status: [_1]', loc_fuzzy($msg));
146 if ($CustomFieldObj->Disabled()) {
151 $id = $CustomFieldObj->id;
157 my $paramtag = "CustomField-".$CustomFieldObj->Id."-Value-";
158 # Delete any fields that want to be deleted
159 foreach my $key (keys %ARGS) {
161 next unless ($key =~ /^Delete-$paramtag(\d+)$/);
162 my ($val, $msg) = $CustomFieldObj->DeleteValue($1);
163 push (@results, $msg);
167 # Update any existing values
168 my $values = $CustomFieldObj->ValuesObj;
169 while (my $value = $values->Next) {
170 foreach my $attr qw(Name Description SortOrder) {
171 my $param = $paramtag.$value->Id."-".$attr;
173 if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param})) {
174 my $mutator = "Set$attr";
175 my ($id, $msg) = $value->$mutator($ARGS{$param});
176 push (@results, $msg);
186 if ($ARGS{$paramtag."new-Name"}) {
187 my ($id, $msg) = $CustomFieldObj->AddValue ( Name => $ARGS{$paramtag."new-Name"},
188 Description => $ARGS{$paramtag."new-Description"},
189 SortOrder => $ARGS{$paramtag."new-SortOrder"});
190 push (@results, $msg);
194 if ($ARGS{'Create'}){
195 $current_tab = "Admin/CustomFields/Modify.html?Create=1";
197 $current_tab = "Admin/CustomFields/Modify.html?id=".$id;
204 $TypeComposite => undef
208 $Description => undef