1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 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., 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 &>
49 <& /Admin/Elements/CustomFieldTabs,
50 id => $CustomFieldObj->Id ,
51 current_tab => $current_tab,
53 <& /Elements/ListActions, actions => \@results &>
56 <form method="post" action="Modify.html" name="ModifyCustomField">
57 <input type="hidden" class="hidden" name="id" value="<% $id %>" />
61 <tr><td class="label"><&|/l&>Name</&></td>
62 <td><input name="Name" value="<% $CustomFieldObj->Name || '' %>" size="20" /></td></tr>
64 <tr><td class="label"><&|/l&>Description</&></td>
65 <td><input name="Description" value="<% $CustomFieldObj->Description || '' %>" size="80" /></td></tr>
67 <tr><td class="label"><&|/l&>Type</&></td>
68 <td><& /Admin/Elements/SelectCustomFieldType,
69 Name => "TypeComposite",
70 Default => $CustomFieldObj->TypeComposite, &>
73 % if ( $CustomFieldObj->Id and $CustomFieldObj->IsSelectionType and RT->Config->Get('CustomFieldValuesSources') and ( scalar(@{RT->Config->Get('CustomFieldValuesSources')}) > 0 ) ) {
74 <tr><td class="label"><&|/l&>Field values source:</&></td><td>
75 <& /Admin/Elements/EditCustomFieldValuesSource, CustomField => $CustomFieldObj &>
79 <tr><td class="label"><&|/l&>Applies to</&></td>
80 <td><& /Admin/Elements/SelectCustomFieldLookupType,
82 Default => $CustomFieldObj->LookupType, &>
85 <tr><td class="label"><&|/l&>Validation</&></td>
86 <td><& /Widgets/ComboBox,
88 Default => $CustomFieldObj->Pattern,
90 Values => \@CFvalidations,
93 <tr><td class="label"><&|/l&>Link values to</&></td><td>
94 <input size="60" name="LinkValueTo" value="<% $CustomFieldObj->LinkValueTo || '' %>" />
96 <&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
97 <&|/l&>Fill in this field with a URL.</&>
98 <&|/l&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
101 <tr><td class="label"><&|/l&>Include page</&></td><td>
102 <input size="60" name="IncludeContentForValue" value="<% $CustomFieldObj->IncludeContentForValue || '' %>" />
104 <&|/l&>RT can include content from another web service when showing this custom field.</&>
105 <&|/l&>Fill in this field with a URL.</&>
106 <&|/l&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
107 <i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
110 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
111 <tr><td class="label"><&|/l&>Categories are based on</&></td><td>
112 <& /Admin/Elements/SelectCustomField,
114 LookupType => $CustomFieldObj->LookupType,
115 Default => $CustomFieldObj->BasedOnObj,
116 Not => $CustomFieldObj->id,
121 <tr><td class="label"> </td><td>
122 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
123 <input type="checkbox" class="checkbox" name="Enabled" value="1" <% $EnabledChecked |n%> />
124 <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
129 % if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
130 <h2><&|/l&>Values</&></h2>
132 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
133 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
137 <& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
141 my ($title, @results, $Disabled);
143 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
144 my $current_tab = 'Admin/CustomFields/Modify.html';
147 $title = loc("Create a CustomField");
149 $current_tab .= '?Create=1';
152 if ( $id eq 'new' ) {
153 my ( $val, $msg ) = $CustomFieldObj->Create(
155 TypeComposite => $TypeComposite,
156 LookupType => $LookupType,
157 Description => $Description,
159 LinkValueTo => $LinkValueTo,
160 IncludeContentForValue => $IncludeContentForValue,
163 $m->comp( "/Elements/Error", Why => loc( "Could not create CustomField", $msg ) ) unless $val;
165 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
167 $CustomFieldObj->Load( $id ) || $m->comp("/Elements/Error", Why => loc('No CustomField') );
168 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
170 $current_tab .= "?id=$id";
173 if ( $ARGS{'Update'} && $id ne 'new' ) {
175 #we're asking about enabled on the web page but really care about disabled.
176 $ARGS{'Disabled'} = $Disabled = $Enabled? 0 : 1;
178 my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
179 push @results, UpdateRecordObject(
180 AttributesRef => \@attribs,
181 Object => $CustomFieldObj,
184 $CustomFieldObj->SetValuesClass( $ValuesClass );
186 $CustomFieldObj->SetBasedOn( $BasedOn );
188 my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
189 # Delete any fields that want to be deleted
190 foreach my $key ( keys %ARGS ) {
191 next unless $key =~ /^Delete-$paramtag-(\d+)$/o;
192 my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
193 push (@results, $msg);
196 # Update any existing values
197 my $values = $CustomFieldObj->ValuesObj;
198 while ( my $value = $values->Next ) {
199 foreach my $attr qw(Name Description SortOrder Category) {
200 my $param = join("-", $paramtag, $value->Id, $attr);
201 next unless exists $ARGS{$param};
202 next if ($value->$attr()||'') eq ($ARGS{$param}||'');
204 my $mutator = "Set$attr";
205 my ($id, $msg) = $value->$mutator( $ARGS{$param} );
206 push (@results, $msg);
211 if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
212 my ($id, $msg) = $CustomFieldObj->AddValue(
213 map { $_ => $ARGS{ $paramtag ."-new-$_" } }
214 qw( Name Description SortOrder Category )
216 push (@results, $msg);
220 $id = $CustomFieldObj->id if $CustomFieldObj->id;
222 my $EnabledChecked = qq[checked="checked"];
223 $EnabledChecked = '' if $CustomFieldObj->Disabled;
225 my @CFvalidations = (
227 '(?#Digits)^[\d.]+$',
228 '(?#Year)^[12]\d{3}$',
231 $m->callback(CallbackName => 'ValidationPatterns', Values => \@CFvalidations);
236 $TypeComposite => undef
240 $Description => undef
245 $ValuesClass => 'RT::CustomFieldValues'
246 $LinkValueTo => undef
247 $IncludeContentForValue => undef