]> git.uio.no Git - usit-rt.git/blame - share/html/Admin/CustomFields/Modify.html
Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / share / html / Admin / CustomFields / Modify.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
403d7b0b 5%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
6%# <sales@bestpractical.com>
7%#
8%# (Except where explicitly superseded by other copyright notices)
9%#
10%#
11%# LICENSE:
12%#
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
16%# from www.gnu.org.
17%#
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.
22%#
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.
28%#
29%#
30%# CONTRIBUTION SUBMISSION POLICY:
31%#
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.)
37%#
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.
46%#
47%# END BPS TAGGED BLOCK }}}
af59614d
MKG
48<& /Admin/Elements/Header,
49 Title => $title,
50 Focus => (($added_cfv or $ARGS{FocusAddValue})
51 ? "input[name=CustomField-$id-Value-new-Name]"
52 : undef),
53 &>
84fb5b46
MKG
54<& /Elements/Tabs &>
55<& /Elements/ListActions, actions => \@results &>
56
57
58<form method="post" action="Modify.html" name="ModifyCustomField" id="ModifyCustomField">
59<input type="hidden" class="hidden" name="id" value="<% $id %>" />
60
61<table>
62
63<tr><td class="label"><&|/l&>Name</&></td>
64<td><input name="Name" value="<% $CustomFieldObj->Name || $Name || '' %>" size="20" /></td></tr>
65
66<tr><td class="label"><&|/l&>Description</&></td>
67<td><input name="Description" value="<% $CustomFieldObj->Description || $Description || '' %>" size="80" /></td></tr>
68
69<tr><td class="label"><&|/l&>Type</&></td>
70<td><& /Admin/Elements/SelectCustomFieldType,
71 Name => "TypeComposite",
72 Default => $CustomFieldObj->TypeComposite, &>
73</td></tr>
74
75% if ( $CustomFieldObj->Id and $CustomFieldObj->HasRenderTypes ) {
76<tr>
77 <td class="label"><&|/l&>Render Type</&></td>
78 <td>
79 <& /Admin/Elements/SelectCustomFieldRenderType,
80 Name => "RenderType",
81 TypeComposite => $CustomFieldObj->TypeComposite,
82 Default => $CustomFieldObj->RenderType,
83 BasedOn => $CustomFieldObj->BasedOnObj->id, &>
84 </td>
85</tr>
86% }
87
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 &>
91</td></tr>
92% }
93
94<tr><td class="label"><&|/l&>Applies to</&></td>
95<td><& /Admin/Elements/SelectCustomFieldLookupType,
96 Name => "LookupType",
97 Default => $CustomFieldObj->LookupType || $LookupType, &>
98</td></tr>
99
100<tr class="edit_validation"><td class="label"><&|/l&>Validation</&></td>
101<td><& /Widgets/ComboBox,
102 Name => 'Pattern',
103 Default => $CustomFieldObj->Pattern || $Pattern,
104 Size => 20,
105 Values => \@CFvalidations,
106&></td></tr>
107
108<tr><td class="label"><&|/l&>Link values to</&></td><td>
109<input size="60" name="LinkValueTo" value="<% $CustomFieldObj->LinkValueTo || $LinkValueTo || '' %>" />
110<div class="hints">
111<&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
112<&|/l&>Fill in this field with a URL.</&>
113<&|/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.</&>
114</div></td></tr>
115
116<tr><td class="label"><&|/l&>Include page</&></td><td>
117<input size="60" name="IncludeContentForValue" value="<% $CustomFieldObj->IncludeContentForValue || $IncludeContentForValue || '' %>" />
118<div class="hints">
119<&|/l&>RT can include content from another web service when showing this custom field.</&>
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.</&>
122<i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
123</div></td></tr>
124
125% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
126<tr class="categoriesbasedon"><td class="label"><&|/l&>Categories are based on</&></td><td>
127<& /Admin/Elements/SelectCustomField,
128 Name => "BasedOn",
129 LookupType => $CustomFieldObj->LookupType,
130 Default => $CustomFieldObj->BasedOnObj || $BasedOn,
131 Not => $CustomFieldObj->id,
132&>
133</td></tr>
134% }
135
136% $m->callback(CallbackName => 'BeforeEnabled', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
137
138<tr><td class="label">&nbsp;</td><td>
139<input type="hidden" class="hidden" name="SetEnabled" value="1" />
af59614d
MKG
140<input type="checkbox" class="checkbox" id="Enabled" name="Enabled" value="1" <% $EnabledChecked |n %> />
141<label for="Enabled"><&|/l&>Enabled (Unchecking this box disables this custom field)</&></label>
84fb5b46
MKG
142</td></tr>
143
144% $m->callback(CallbackName => 'EndOfTable', CustomField => $CustomFieldObj, CFvalidations => \@CFvalidations);
145
146</table>
147
148% if ( $CustomFieldObj->Id && $CustomFieldObj->IsSelectionType && !$CustomFieldObj->IsExternalValues ) {
149<h2><&|/l&>Values</&></h2>
150<div>
151<& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
152<& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
153</div>
154% }
155
156<& /Elements/Submit, Name => 'Update', Label => $id eq 'new'? loc('Create'): loc('Save Changes') &>
157
158</form>
159<%INIT>
af59614d 160my ($title, @results, $added_cfv);
84fb5b46
MKG
161
162my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
163
164$m->callback(CallbackName => 'Initial', Pattern => \$Pattern, ARGSRef => \%ARGS);
165
166unless ( $id ) {
167 $title = loc("Create a CustomField");
168 $id = 'new';
169}
170else {
171 if ( $id eq 'new' ) {
172 my ( $val, $msg ) = $CustomFieldObj->Create(
173 Name => $Name,
174 TypeComposite => $TypeComposite,
175 LookupType => $LookupType,
176 Description => $Description,
177 Pattern => $Pattern,
178 LinkValueTo => $LinkValueTo,
179 IncludeContentForValue => $IncludeContentForValue,
180 BasedOn => $BasedOn,
af59614d 181 Disabled => ($Enabled ? 0 : 1),
84fb5b46
MKG
182 );
183 if (!$val) {
184 push @results, loc("Could not create CustomField: [_1]", $msg);
185 $title = loc( 'Create a CustomField');
186 }
187 else {
188 push @results, loc("Object created");
189 $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name );
190 }
191 } else {
192 push @results, loc('No CustomField')
193 unless $CustomFieldObj->Load( $id );
194
195 $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name );
196 }
197}
198
199if ( $ARGS{'Update'} && $id ne 'new' ) {
200
201 #we're asking about enabled on the web page but really care about disabled.
202 $ARGS{'Disabled'} = $Enabled? 0 : 1;
203
204 my @attribs = qw(Disabled Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
205 push @results, UpdateRecordObject(
206 AttributesRef => \@attribs,
207 Object => $CustomFieldObj,
208 ARGSRef => \%ARGS
209 );
c36a7e1d
MKG
210 if ( ($ValuesClass||'RT::CustomFieldValues') ne $CustomFieldObj->ValuesClass ) {
211 my $original = $CustomFieldObj->ValuesClass;
212 my ($good, $msg) = $CustomFieldObj->SetValuesClass( $ValuesClass );
213 if ( $good ) {
214 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
215 loc("Field values source"), $original, $ValuesClass );
216 }
217 push @results, $msg;
218 }
84fb5b46
MKG
219
220 # Set the render type if we have it, but unset it if the new type doesn't
221 # support render types
222 if ( $CustomFieldObj->HasRenderTypes($TypeComposite) ) {
223 my $original = $CustomFieldObj->RenderType;
224
225 if ( defined $RenderType and $RenderType ne $original ) {
226 # It's changed! Let's update it.
227 my ($good, $msg) = $CustomFieldObj->SetRenderType( $RenderType );
228
229 if ( $good ) {
230 $msg = loc("[_1] changed from '[_2]' to '[_3]'",
231 loc("Render Type"), $original, $RenderType );
232 }
233
234 push @results, $msg;
235 }
236 }
237 else {
238 # Delete it if we no longer support render types
239 $CustomFieldObj->SetRenderType( undef );
240 }
241
242 if (($CustomFieldObj->BasedOn||'') ne ($BasedOn||'')) {
243 my ($good, $msg) = $CustomFieldObj->SetBasedOn( $BasedOn );
244 push @results, $msg;
245 }
246
247 my $paramtag = "CustomField-". $CustomFieldObj->Id ."-Value";
248 # Delete any fields that want to be deleted
249 foreach my $key ( keys %ARGS ) {
403d7b0b 250 next unless $key =~ /^Delete-$paramtag-(\d+)$/;
84fb5b46
MKG
251 my ($val, $msg) = $CustomFieldObj->DeleteValue( $1 );
252 push (@results, $msg);
253 }
254
255 # Update any existing values
256 my $values = $CustomFieldObj->ValuesObj;
257 while ( my $value = $values->Next ) {
258 foreach my $attr (qw(Name Description SortOrder Category)) {
259 my $param = join("-", $paramtag, $value->Id, $attr);
260 next unless exists $ARGS{$param};
261 $ARGS{$param} =~ s/^\s+//;
262 $ARGS{$param} =~ s/\s+$//;
263 next if ($value->$attr()||'') eq ($ARGS{$param}||'');
264
265 my $mutator = "Set$attr";
266 my ($id, $msg) = $value->$mutator( $ARGS{$param} );
267 push (@results, $msg);
268 }
269 $m->callback(CallbackName => 'AfterUpdateCustomFieldValue', CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $value, ARGSRef => \%ARGS );
270 }
271
272 # Add any new values
273 if ( defined $ARGS{ $paramtag ."-new-Name" } && length $ARGS{ $paramtag ."-new-Name" } ) {
274 my ($id, $msg) = $CustomFieldObj->AddValue(
275 map {
276 $ARGS{$paramtag."-new-$_"} =~ s/^\s+//;
277 $ARGS{$paramtag."-new-$_"} =~ s/\s+$//;
278 $_ => $ARGS{ $paramtag ."-new-$_" } } qw/ Name Description SortOrder Category/
279 );
280 push (@results, $msg);
af59614d 281 $added_cfv = 1 if $id;
84fb5b46
MKG
282
283 my $cfv = RT::CustomFieldValue->new( $session{CurrentUser} );
284 $cfv->Load($id);
285 $m->callback(CallbackName => 'AfterCreateCustomFieldValue',
286CustomFieldObj => $CustomFieldObj, CustomFieldValueObj => $cfv, ARGSRef => \%ARGS );
287 }
288}
289
af59614d
MKG
290if ( $CustomFieldObj->id && $CustomFieldObj->IsOnlyGlobal ) {
291 my ( $ret, $msg );
292 my $object = $CustomFieldObj->RecordClassFromLookupType->new( $session{'CurrentUser'} );
293
294 if ( $CustomFieldObj->Disabled && $CustomFieldObj->IsGlobal ) {
295 ( $ret, $msg ) = $CustomFieldObj->RemoveFromObject($object);
296 }
297 elsif ( !$CustomFieldObj->Disabled && !$CustomFieldObj->IsGlobal ) {
298 ( $ret, $msg ) = $CustomFieldObj->AddToObject($object);
299 }
300
301 # successful msg("object created" or "object deleted ) is useless here
302 push @results, $msg unless $ret;
303}
304
84fb5b46
MKG
305$id = $CustomFieldObj->id if $CustomFieldObj->id;
306
307# This code does automatic redirection if any updates happen.
308MaybeRedirectForResults(
309 Actions => \@results,
af59614d 310 Arguments => { id => $id, FocusAddValue => ($added_cfv ? 1 : 0) },
84fb5b46
MKG
311) if $CustomFieldObj->id;
312
313
314my $EnabledChecked = qq[checked="checked"];
315$EnabledChecked = '' if $CustomFieldObj->Disabled;
316
317my @CFvalidations = (
318 '(?#Mandatory).',
319 '(?#Digits)^[\d.]+$',
320 '(?#Year)^[12]\d{3}$',
321);
322
323$m->callback(CallbackName => 'ValidationPatterns', Values => \@CFvalidations);
324
325</%INIT>
326<%ARGS>
327$id => undef
328$TypeComposite => undef
af59614d 329$LookupType => RT::Ticket->CustomFieldLookupType
84fb5b46
MKG
330$MaxValues => undef
331$SortOrder => undef
332$Description => undef
333$Pattern => undef
334$Name => undef
335$SetEnabled => undef
336$Enabled => 0
337$ValuesClass => 'RT::CustomFieldValues'
338$RenderType => undef
339$LinkValueTo => undef
340$IncludeContentForValue => undef
341$BasedOn => undef
342</%ARGS>