1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 %# <sales@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., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
48 <& /Admin/Elements/Header,
50 Focus => (($added_cfv or $ARGS{FocusAddValue})
51 ? "input[name=CustomField-$id-Value-new-Name]"
55 <& /Elements/ListActions, actions => \@results &>
58 <form method="post" action="Modify.html" name="ModifyCustomField" id="ModifyCustomField">
59 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
63 <tr><td class="label"><&|/l&>Name</&></td>
64 <td><input name="Name" value="<% $CustomFieldObj->Name || $Name || '' %>" size="20" /></td></tr>
66 <tr><td class="label"><&|/l&>Description</&></td>
67 <td><input name="Description" value="<% $CustomFieldObj->Description || $Description || '' %>" size="80" /></td></tr>
69 <tr><td class="label"><&|/l&>Type</&></td>
70 <td><& /Admin/Elements/SelectCustomFieldType,
71 Name => "TypeComposite",
72 Default => $CustomFieldObj->TypeComposite, &>
75 % if ( $CustomFieldObj->Id and $CustomFieldObj->HasRenderTypes ) {
77 <td class="label"><&|/l&>Render Type</&></td>
79 <& /Admin/Elements/SelectCustomFieldRenderType,
81 TypeComposite => $CustomFieldObj->TypeComposite,
82 Default => $CustomFieldObj->RenderType,
83 BasedOn => $CustomFieldObj->BasedOnObj->id, &>
88 % if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) {
89 <tr><td class="label"><&|/l&>Field values source:</&></td><td>
90 <& /Admin/Elements/EditCustomFieldValuesSource, CustomField => $CustomFieldObj &>
94 <tr><td class="label"><&|/l&>Applies to</&></td>
95 <td><& /Admin/Elements/SelectCustomFieldLookupType,
97 Default => $CustomFieldObj->LookupType || $LookupType, &>
100 % if ( $CustomFieldObj->Id
101 % and $CustomFieldObj->LookupType =~ /RT::Transaction/ ) {
102 <tr><td class="label"><&|/l&>Display with</&></td>
103 <td><& /Admin/Elements/EditCustomFieldUILocation,
104 CustomField => $CustomFieldObj &>
108 <tr class="edit_validation"><td class="label"><&|/l&>Validation</&></td>
109 <td><& /Widgets/ComboBox,
111 Default => $CustomFieldObj->Pattern || $Pattern,
113 Values => \@CFvalidations,
116 <tr><td class="label"><&|/l&>Link values to</&></td><td>
117 <input size="60" name="LinkValueTo" value="<% $CustomFieldObj->LinkValueTo || $LinkValueTo || '' %>" />
119 <&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
120 <&|/l&>Fill in this field with a URL.</&>
121 <&|/l_unsafe, '<tt>__id__</tt>', '<tt>__CustomField__</tt>' &>RT will replace [_1] and [_2] with the record's id and the custom field's value, respectively.</&>
124 <tr><td class="label"><&|/l&>Include page</&></td><td>
125 <input size="60" name="IncludeContentForValue" value="<% $CustomFieldObj->IncludeContentForValue || $IncludeContentForValue || '' %>" />
127 <&|/l&>RT can include content from another web service when showing this custom field.</&>
128 <&|/l&>Fill in this field with a URL.</&>
129 <&|/l_unsafe, '<tt>__id__</tt>', '<tt>__CustomField__</tt>' &>RT will replace [_1] and [_2] with the record's id and the custom field's value, respectively.</&>
130 <i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
133 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType ) {
134 <tr class="categoriesbasedon"><td class="label"><&|/l&>Categories are based on</&></td><td>
135 <& /Admin/Elements/SelectCustomField,
137 LookupType => $CustomFieldObj->LookupType,
138 Default => $CustomFieldObj->BasedOnObj || $BasedOn,
139 Not => $CustomFieldObj->id,
144 % $m->callback(CallbackName => 'BeforeEnabled', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
146 <tr><td class="label"> </td><td>
147 <input type="checkbox" class="checkbox" name="Required" value="1" <% $RequiredChecked |n%> />
148 <&|/l&>Required for ticket resolution</&>
151 <tr><td class="label"> </td><td>
152 <input type="checkbox" class="checkbox" name="YesClone" value="1" <% $YesCloneChecked |n%> />
153 <&|/l&>Copy this field to new tickets</&>
156 <tr><td class="label"> </td><td>
157 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
158 <input type="checkbox" class="checkbox" id="Enabled" name="Enabled" value="1" <% $EnabledChecked |n %> />
159 <label for="Enabled"><&|/l&>Enabled (Unchecking this box disables this custom field)</&></label>
162 % $m->callback(CallbackName => 'EndOfTable', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
166 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
167 <h2><&|/l&>Values</&></h2>
169 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
170 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
174 <& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
177 % $m->callback(%ARGS, CallbackName => 'EndOfPage', CustomFieldObj => $CustomFieldObj);
179 my ($title, @results, $added_cfv);
181 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
183 $m->callback(CallbackName => 'Initial', Pattern => \$Pattern, Results => \@results, ARGSRef => \%ARGS);
186 $title = loc("Create a CustomField");
190 if ( $id eq 'new' ) {
191 my ( $val, $msg ) = $CustomFieldObj->Create(
193 TypeComposite => $TypeComposite,
194 LookupType => $LookupType,
195 Description => $Description,
197 LinkValueTo => $LinkValueTo,
198 IncludeContentForValue => $IncludeContentForValue,
200 Disabled => ($Enabled ? 0 : 1),
201 NoClone => !$YesClone,
204 push @results, loc("Could not create CustomField: [_1]", $msg);
205 $title = loc( 'Create a CustomField');
208 push @results, loc("Object created");
209 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
212 push @results, loc('No CustomField')
213 unless $CustomFieldObj->Load( $id );
215 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
219 if ( $ARGS{'Update'} && $id ne 'new' ) {
220 #we're asking about enabled on the web page but really care about disabled.
221 $ARGS{'Disabled'} = $Enabled? 0 : 1;
223 $ARGS{'NoClone'} = $YesClone ? 0 : 1;
225 $ARGS{'Required'} ||= 0;
227 my @attribs = qw(Disabled Required Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue NoClone);
228 push @results, UpdateRecordObject(
229 AttributesRef => \@attribs,
230 Object => $CustomFieldObj,
233 if ( ($ValuesClass||'RT::CustomFieldValues') ne $CustomFieldObj->ValuesClass ) {
234 my $original = $CustomFieldObj->ValuesClass;
235 my ($good, $msg) = $CustomFieldObj->SetValuesClass( $ValuesClass );
237 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
238 loc("Field values source"), $original, $ValuesClass );
243 # Set the render type if we have it, but unset it if the new type doesn't
244 # support render types
245 if ( $CustomFieldObj->HasRenderTypes($TypeComposite) ) {
246 my $original = $CustomFieldObj->RenderType;
248 if ( defined $RenderType and $RenderType ne $original ) {
249 # It's changed! Let's update it.
250 my ($good, $msg) = $CustomFieldObj->SetRenderType( $RenderType );
253 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
254 loc("Render Type"), $original, $RenderType );
261 # Delete it if we no longer support render types
262 $CustomFieldObj->SetRenderType( undef );
265 if (($CustomFieldObj->BasedOn||'') ne ($BasedOn||'')) {
266 my ($good, $msg) = $CustomFieldObj->SetBasedOn( $BasedOn );
270 $CustomFieldObj->SetUILocation( $UILocation );
272 my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
273 # Delete any fields that want to be deleted
274 foreach my $key ( keys %ARGS ) {
275 next unless $key =~ /^Delete-$paramtag-(\d+)$/;
276 my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
277 push (@results, $msg);
281 foreach my $param (grep /^$paramtag-/, keys(%ARGS)) {
282 for ($ARGS{$param}) {
289 # Update any existing values
290 my $values = $CustomFieldObj->ValuesObj;
291 while ( my $value = $values->Next ) {
292 foreach my $attr (qw(Name Description SortOrder Category)) {
293 my $param = join("-", $paramtag, $value->Id, $attr);
294 next unless exists $ARGS{$param};
295 $ARGS{$param} =~ s/^\s+//;
296 $ARGS{$param} =~ s/\s+$//;
297 next if ($value->$attr()||'') eq ($ARGS{$param}||'');
299 my $mutator = "Set$attr";
300 my ($id, $msg) = $value->$mutator( $ARGS{$param} );
301 push (@results, $msg);
303 $m->callback(CallbackName => 'AfterUpdateCustomFieldValue', CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
307 if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
308 my ($id, $msg) = $CustomFieldObj->AddValue(
310 $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
311 $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
312 $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
314 push (@results, $msg);
315 $added_cfv = 1 if $id;
317 my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
319 $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
320 CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
324 if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
326 my $object = $CustomFieldObj->RecordClassFromLookupType->new( $session{'CurrentUser'} );
328 if ( $CustomFieldObj->Disabled && $CustomFieldObj->IsGlobal ) {
329 ( $ret, $msg ) = $CustomFieldObj->RemoveFromObject($object);
331 elsif ( !$CustomFieldObj->Disabled && !$CustomFieldObj->IsGlobal ) {
332 ( $ret, $msg ) = $CustomFieldObj->AddToObject($object);
335 # successful msg("object created" or "object deleted ) is useless here
336 push @results, $msg unless $ret;
339 $id = $CustomFieldObj->id if $CustomFieldObj->id;
341 # This code does automatic redirection if any updates happen.
342 MaybeRedirectForResults(
343 Actions => \@results,
344 Arguments => { id => $id, FocusAddValue => ($added_cfv ? 1 : 0) },
345 ) if $CustomFieldObj->id;
348 my $EnabledChecked = qq[checked="checked"];
349 $EnabledChecked = '' if $CustomFieldObj->Disabled;
351 my $RequiredChecked = '';
352 $RequiredChecked = qq[checked="checked"] if $CustomFieldObj->Required;
354 my $YesCloneChecked = qq[checked="checked"];
355 $YesCloneChecked = '' if $CustomFieldObj->NoClone;
358 my @CFvalidations = (
360 '(?#Digits)^[\d.]+$',
361 '(?#Year)^[12]\d{3}$',
364 $m->callback(CallbackName => 'ValidationPatterns', Values => \@CFvalidations);
369 $TypeComposite => undef
370 $LookupType => RT::Ticket->CustomFieldLookupType
373 $Description => undef
378 $ValuesClass => 'RT::CustomFieldValues'
380 $LinkValueTo => undef
381 $IncludeContentForValue => undef