1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2015 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') &>
178 my ($title, @results, $added_cfv);
180 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
182 $m->callback(CallbackName => 'Initial', Pattern => \$Pattern, ARGSRef => \%ARGS);
185 $title = loc("Create a CustomField");
189 if ( $id eq 'new' ) {
190 my ( $val, $msg ) = $CustomFieldObj->Create(
192 TypeComposite => $TypeComposite,
193 LookupType => $LookupType,
194 Description => $Description,
196 LinkValueTo => $LinkValueTo,
197 IncludeContentForValue => $IncludeContentForValue,
199 Disabled => ($Enabled ? 0 : 1),
200 NoClone => !$YesClone,
203 push @results, loc("Could not create CustomField: [_1]", $msg);
204 $title = loc( 'Create a CustomField');
207 push @results, loc("Object created");
208 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
211 push @results, loc('No CustomField')
212 unless $CustomFieldObj->Load( $id );
214 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
218 if ( $ARGS{'Update'} && $id ne 'new' ) {
219 #we're asking about enabled on the web page but really care about disabled.
220 $ARGS{'Disabled'} = $Enabled? 0 : 1;
222 $ARGS{'NoClone'} = $YesClone ? 0 : 1;
224 $ARGS{'Required'} ||= 0;
226 my @attribs = qw(Disabled Required Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue NoClone);
227 push @results, UpdateRecordObject(
228 AttributesRef => \@attribs,
229 Object => $CustomFieldObj,
232 if ( ($ValuesClass||'RT::CustomFieldValues') ne $CustomFieldObj->ValuesClass ) {
233 my $original = $CustomFieldObj->ValuesClass;
234 my ($good, $msg) = $CustomFieldObj->SetValuesClass( $ValuesClass );
236 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
237 loc("Field values source"), $original, $ValuesClass );
242 # Set the render type if we have it, but unset it if the new type doesn't
243 # support render types
244 if ( $CustomFieldObj->HasRenderTypes($TypeComposite) ) {
245 my $original = $CustomFieldObj->RenderType;
247 if ( defined $RenderType and $RenderType ne $original ) {
248 # It's changed! Let's update it.
249 my ($good, $msg) = $CustomFieldObj->SetRenderType( $RenderType );
252 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
253 loc("Render Type"), $original, $RenderType );
260 # Delete it if we no longer support render types
261 $CustomFieldObj->SetRenderType( undef );
264 if (($CustomFieldObj->BasedOn||'') ne ($BasedOn||'')) {
265 my ($good, $msg) = $CustomFieldObj->SetBasedOn( $BasedOn );
269 $CustomFieldObj->SetUILocation( $UILocation );
271 my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
272 # Delete any fields that want to be deleted
273 foreach my $key ( keys %ARGS ) {
274 next unless $key =~ /^Delete-$paramtag-(\d+)$/;
275 my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
276 push (@results, $msg);
280 foreach my $param (grep /^$paramtag-/, keys(%ARGS)) {
281 for ($ARGS{$param}) {
288 # Update any existing values
289 my $values = $CustomFieldObj->ValuesObj;
290 while ( my $value = $values->Next ) {
291 foreach my $attr (qw(Name Description SortOrder Category)) {
292 my $param = join("-", $paramtag, $value->Id, $attr);
293 next unless exists $ARGS{$param};
294 $ARGS{$param} =~ s/^\s+//;
295 $ARGS{$param} =~ s/\s+$//;
296 next if ($value->$attr()||'') eq ($ARGS{$param}||'');
298 my $mutator = "Set$attr";
299 my ($id, $msg) = $value->$mutator( $ARGS{$param} );
300 push (@results, $msg);
302 $m->callback(CallbackName => 'AfterUpdateCustomFieldValue', CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
306 if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
307 my ($id, $msg) = $CustomFieldObj->AddValue(
309 $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
310 $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
311 $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
313 push (@results, $msg);
314 $added_cfv = 1 if $id;
316 my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
318 $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
319 CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
323 if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
325 my $object = $CustomFieldObj->RecordClassFromLookupType->new( $session{'CurrentUser'} );
327 if ( $CustomFieldObj->Disabled && $CustomFieldObj->IsGlobal ) {
328 ( $ret, $msg ) = $CustomFieldObj->RemoveFromObject($object);
330 elsif ( !$CustomFieldObj->Disabled && !$CustomFieldObj->IsGlobal ) {
331 ( $ret, $msg ) = $CustomFieldObj->AddToObject($object);
334 # successful msg("object created" or "object deleted ) is useless here
335 push @results, $msg unless $ret;
338 $id = $CustomFieldObj->id if $CustomFieldObj->id;
340 # This code does automatic redirection if any updates happen.
341 MaybeRedirectForResults(
342 Actions => \@results,
343 Arguments => { id => $id, FocusAddValue => ($added_cfv ? 1 : 0) },
344 ) if $CustomFieldObj->id;
347 my $EnabledChecked = qq[checked="checked"];
348 $EnabledChecked = '' if $CustomFieldObj->Disabled;
350 my $RequiredChecked = '';
351 $RequiredChecked = qq[checked="checked"] if $CustomFieldObj->Required;
353 my $YesCloneChecked = qq[checked="checked"];
354 $YesCloneChecked = '' if $CustomFieldObj->NoClone;
357 my @CFvalidations = (
359 '(?#Digits)^[\d.]+$',
360 '(?#Year)^[12]\d{3}$',
363 $m->callback(CallbackName => 'ValidationPatterns', Values => \@CFvalidations);
368 $TypeComposite => undef
369 $LookupType => RT::Ticket->CustomFieldLookupType
372 $Description => undef
377 $ValuesClass => 'RT::CustomFieldValues'
379 $LinkValueTo => undef
380 $IncludeContentForValue => undef