1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2012 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, Title => $title &>
50 <& /Elements/ListActions, actions => \@results &>
53 <form method="post" action="Modify.html" name="ModifyCustomField" id="ModifyCustomField">
54 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
58 <tr><td class="label"><&|/l&>Name</&></td>
59 <td><input name="Name" value="<% $CustomFieldObj->Name || $Name || '' %>" size="20" /></td></tr>
61 <tr><td class="label"><&|/l&>Description</&></td>
62 <td><input name="Description" value="<% $CustomFieldObj->Description || $Description || '' %>" size="80" /></td></tr>
64 <tr><td class="label"><&|/l&>Type</&></td>
65 <td><& /Admin/Elements/SelectCustomFieldType,
66 Name => "TypeComposite",
67 Default => $CustomFieldObj->TypeComposite, &>
70 % if ( $CustomFieldObj->Id and $CustomFieldObj->HasRenderTypes ) {
72 <td class="label"><&|/l&>Render Type</&></td>
74 <& /Admin/Elements/SelectCustomFieldRenderType,
76 TypeComposite => $CustomFieldObj->TypeComposite,
77 Default => $CustomFieldObj->RenderType,
78 BasedOn => $CustomFieldObj->BasedOnObj->id, &>
83 % if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) {
84 <tr><td class="label"><&|/l&>Field values source:</&></td><td>
85 <& /Admin/Elements/EditCustomFieldValuesSource, CustomField => $CustomFieldObj &>
89 <tr><td class="label"><&|/l&>Applies to</&></td>
90 <td><& /Admin/Elements/SelectCustomFieldLookupType,
92 Default => $CustomFieldObj->LookupType || $LookupType, &>
95 % if ( $CustomFieldObj->Id
96 % and $CustomFieldObj->LookupType =~ /RT::Transaction/ ) {
97 <tr><td class="label"><&|/l&>Display with</&></td>
98 <td><& /Admin/Elements/EditCustomFieldUILocation,
99 CustomField => $CustomFieldObj &>
103 <tr class="edit_validation"><td class="label"><&|/l&>Validation</&></td>
104 <td><& /Widgets/ComboBox,
106 Default => $CustomFieldObj->Pattern || $Pattern,
108 Values => \@CFvalidations,
111 <tr><td class="label"><&|/l&>Link values to</&></td><td>
112 <input size="60" name="LinkValueTo" value="<% $CustomFieldObj->LinkValueTo || $LinkValueTo || '' %>" />
114 <&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
115 <&|/l&>Fill in this field with a URL.</&>
116 <&|/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.</&>
119 <tr><td class="label"><&|/l&>Include page</&></td><td>
120 <input size="60" name="IncludeContentForValue" value="<% $CustomFieldObj->IncludeContentForValue || $IncludeContentForValue || '' %>" />
122 <&|/l&>RT can include content from another web service when showing this custom field.</&>
123 <&|/l&>Fill in this field with a URL.</&>
124 <&|/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.</&>
125 <i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
128 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
129 <tr class="categoriesbasedon"><td class="label"><&|/l&>Categories are based on</&></td><td>
130 <& /Admin/Elements/SelectCustomField,
132 LookupType => $CustomFieldObj->LookupType,
133 Default => $CustomFieldObj->BasedOnObj || $BasedOn,
134 Not => $CustomFieldObj->id,
139 % $m->callback(CallbackName => 'BeforeEnabled', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
141 <tr><td class="label"> </td><td>
142 <input type="checkbox" class="checkbox" name="Required" value="1" <% $RequiredChecked |n%> />
143 <&|/l&>Required for ticket resolution</&>
146 <tr><td class="label"> </td><td>
147 <input type="checkbox" class="checkbox" name="YesClone" value="1" <% $YesCloneChecked |n%> />
148 <&|/l&>Copy this field to new tickets</&>
151 <tr><td class="label"> </td><td>
152 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
153 <input type="checkbox" class="checkbox" name="Enabled" value="1" <% $EnabledChecked |n%> />
154 <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
157 % $m->callback(CallbackName => 'EndOfTable', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
161 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
162 <h2><&|/l&>Values</&></h2>
164 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
165 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
169 <& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
173 my ($title, @results);
175 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
177 $m->callback(CallbackName => 'Initial', Pattern => \$Pattern, ARGSRef => \%ARGS);
180 $title = loc("Create a CustomField");
184 if ( $id eq 'new' ) {
185 my ( $val, $msg ) = $CustomFieldObj->Create(
187 TypeComposite => $TypeComposite,
188 LookupType => $LookupType,
189 Description => $Description,
191 LinkValueTo => $LinkValueTo,
192 IncludeContentForValue => $IncludeContentForValue,
194 Disabled => !$Enabled,
195 NoClone => !$YesClone,
198 push @results, loc("Could not create CustomField: [_1]", $msg);
199 $title = loc( 'Create a CustomField');
202 push @results, loc("Object created");
203 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
206 push @results, loc('No CustomField')
207 unless $CustomFieldObj->Load( $id );
209 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
213 if ( $ARGS{'Update'} && $id ne 'new' ) {
214 #we're asking about enabled on the web page but really care about disabled.
215 $ARGS{'Disabled'} = $Enabled? 0 : 1;
217 $ARGS{'NoClone'} = $YesClone ? 0 : 1;
219 $ARGS{'Required'} ||= 0;
221 my @attribs = qw(Disabled Required Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue NoClone);
222 push @results, UpdateRecordObject(
223 AttributesRef => \@attribs,
224 Object => $CustomFieldObj,
227 $CustomFieldObj->SetValuesClass( $ValuesClass );
229 # Set the render type if we have it, but unset it if the new type doesn't
230 # support render types
231 if ( $CustomFieldObj->HasRenderTypes($TypeComposite) ) {
232 my $original = $CustomFieldObj->RenderType;
234 if ( defined $RenderType and $RenderType ne $original ) {
235 # It's changed! Let's update it.
236 my ($good, $msg) = $CustomFieldObj->SetRenderType( $RenderType );
239 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
240 loc("Render Type"), $original, $RenderType );
247 # Delete it if we no longer support render types
248 $CustomFieldObj->SetRenderType( undef );
251 if (($CustomFieldObj->BasedOn||'') ne ($BasedOn||'')) {
252 my ($good, $msg) = $CustomFieldObj->SetBasedOn( $BasedOn );
256 $CustomFieldObj->SetUILocation( $UILocation );
258 my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
259 # Delete any fields that want to be deleted
260 foreach my $key ( keys %ARGS ) {
261 next unless $key =~ /^Delete-$paramtag-(\d+)$/o;
262 my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
263 push (@results, $msg);
267 foreach my $param (grep /^$paramtag-/, keys(%ARGS)) {
268 for ($ARGS{$param}) {
275 # Update any existing values
276 my $values = $CustomFieldObj->ValuesObj;
277 while ( my $value = $values->Next ) {
278 foreach my $attr (qw(Name Description SortOrder Category)) {
279 my $param = join("-", $paramtag, $value->Id, $attr);
280 next unless exists $ARGS{$param};
281 $ARGS{$param} =~ s/^\s+//;
282 $ARGS{$param} =~ s/\s+$//;
283 next if ($value->$attr()||'') eq ($ARGS{$param}||'');
285 my $mutator = "Set$attr";
286 my ($id, $msg) = $value->$mutator( $ARGS{$param} );
287 push (@results, $msg);
289 $m->callback(CallbackName => 'AfterUpdateCustomFieldValue', CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
293 if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
294 my ($id, $msg) = $CustomFieldObj->AddValue(
296 $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
297 $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
298 $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
300 push (@results, $msg);
302 my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
304 $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
305 CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
309 $id = $CustomFieldObj->id if $CustomFieldObj->id;
311 # This code does automatic redirection if any updates happen.
312 MaybeRedirectForResults(
313 Actions => \@results,
314 Arguments => { id => $id },
315 ) if $CustomFieldObj->id;
318 my $EnabledChecked = qq[checked="checked"];
319 $EnabledChecked = '' if $CustomFieldObj->Disabled;
321 my $RequiredChecked = '';
322 $RequiredChecked = qq[checked="checked"] if $CustomFieldObj->Required;
324 my $YesCloneChecked = qq[checked="checked"];
325 $YesCloneChecked = '' if $CustomFieldObj->NoClone;
328 my @CFvalidations = (
330 '(?#Digits)^[\d.]+$',
331 '(?#Year)^[12]\d{3}$',
334 $m->callback(CallbackName => 'ValidationPatterns', Values => \@CFvalidations);
339 $TypeComposite => undef
343 $Description => undef
348 $ValuesClass => 'RT::CustomFieldValues'
350 $LinkValueTo => undef
351 $IncludeContentForValue => undef