import rt 3.8.11
[freeside.git] / rt / html / Admin / CustomFields / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
6 %#                                          <jesse@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 }}}
48 <& /Admin/Elements/Header, Title => $title &>
49 <& /Admin/Elements/CustomFieldTabs,
50     id => $CustomFieldObj->Id ,
51     current_tab => $current_tab,
52     Title => $title &>
53 <& /Elements/ListActions, actions => \@results &>
54
55
56 <form method="post" action="Modify.html" name="ModifyCustomField">
57 <input type="hidden" class="hidden" name="id" value="<%$id %>" />
58 <table>
59 <tr>
60 <td class="label"><&|/l&>Name</&></td>
61 <td><input name="Name" value="<%$CustomFieldObj->Name%>" size="20" /></td></tr>
62 <tr>
63 <td class="label"><&|/l&>Description</&></td>
64 <td><input name="Description" value="<%$CustomFieldObj->Description%>" size="80" /></td>
65 </tr>
66
67 <tr>
68 <td class="label"><&|/l&>Type</&></td>
69 <td><& /Admin/Elements/SelectCustomFieldType, 
70         Name => "TypeComposite", 
71         Default => $CustomFieldObj->TypeComposite, &>
72 </td>
73 </tr>
74 <tr>
75 <td class="label"><&|/l&>Applies to</&></td>
76 <td><& /Admin/Elements/SelectCustomFieldLookupType, 
77         Name => "LookupType", 
78         Default => $CustomFieldObj->LookupType, &>
79 </td>
80 </tr>
81 <tr>
82 <td class="label"><&|/l&>Validation</&></td>
83 <td>
84 <& /Widgets/ComboBox,
85     Name    => 'Pattern',
86     Default => $CustomFieldObj->Pattern,
87     Size    => 20,
88     Values  => [
89         '(?#Mandatory).',
90         '(?#Digits)^[\d.]+$',
91         '(?#Year)^[12]\d{3}$',
92     ],
93 &>
94 </td></tr>
95 </tr>
96 <tr>
97 <td class="label">&nbsp;</td>
98 <td>
99 <input type="hidden" class="hidden" name="SetEnabled" value="1" />
100 <input type="checkbox" class="checkbox" name="Enabled" value="1" <%$EnabledChecked%> /> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
101 </td>
102 </tr>
103 <tr>
104 <td class="label"><&|/l&>Link values to</&></td>
105 </td>
106 <td><input size="60" name="LinkValueTo"  value="<%$CustomFieldObj->LinkValueTo%>" />
107 <div class="hints">
108 <&|/l&>RT can make this custom field's values into hyperlinks to another service.</&>
109 <&|/l&>Fill in this field with a URL.</&>
110 <&|/l&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
111 </div>
112 </td>
113 </tr>
114 <tr>
115 <td class="label"><&|/l&>Include page</&></td>
116 </td>
117 <td><input size="60" name="IncludeContentForValue"  value="<%$CustomFieldObj->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&>RT will replace <tt>__id__</tt> and <tt>__CustomField__</tt> with the record id and custom field value, respectively</&>
122 <i><&|/l&>Some browsers may only load content from the same domain as your RT server.</&></i>
123 </div>
124 </td>
125 </tr>
126
127
128
129 </table>
130 <br />
131 % if ($CustomFieldObj->Id && $CustomFieldObj->IsSelectionType) {
132 <h2><&|/l&>Values</&></h2>
133 <div>
134 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
135 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
136 </div>
137 % }
138 <&/Elements/Submit&>
139 </form>
140
141
142
143 <%INIT>
144
145
146
147 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
148 my ( $title, @results, $EnabledChecked, $Disabled);
149 $EnabledChecked = "CHECKED";
150
151 if ( !$id ) {
152     $title = loc("Create a CustomField");
153     $id    = 'new';
154 }
155 else {
156
157     if ( $id eq 'new' ) {
158         my ( $val, $msg ) = $CustomFieldObj->Create(Name        => $Name,
159                                                     TypeComposite => $TypeComposite,
160                                                     LookupType => $LookupType,
161                                                     Description => $Description,
162                                                     Pattern => $Pattern,);
163         $m->comp("/Elements/Error", Why =>  loc( "Could not create CustomField", $msg ) ) unless ($val);
164         push @results, $msg;
165         $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name() );
166     }
167     else {
168         $CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why =>  loc('No CustomField') );
169         $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() );
170
171         my @attribs = qw( Pattern Name TypeComposite LookupType Description LinkValueTo IncludeContentForValue);
172         my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
173                                            Object        => $CustomFieldObj,
174                                            ARGSRef       => \%ARGS );
175
176         push @results, @aresults;
177
178         #we're asking about enabled on the web page but really care about disabled.
179         if ($Enabled == 1) {
180             $Disabled = 0;
181         }       
182         else {
183             $Disabled = 1;
184         }
185         if  ( ($SetEnabled) and ( $Disabled != $CustomFieldObj->Disabled) ) { 
186             my  ($code, $msg) = $CustomFieldObj->SetDisabled($Disabled);
187             push @results, loc('Enabled status: [_1]', loc_fuzzy($msg));
188         }
189         
190         if ($CustomFieldObj->Disabled()) {
191             $EnabledChecked ="";
192         }
193     }
194
195     $id = $CustomFieldObj->id;
196 }
197
198
199
200
201 my $paramtag = "CustomField-".$CustomFieldObj->Id."-Value-";
202 # Delete any fields that want to be deleted
203 foreach my $key (keys %ARGS) {
204         
205         next unless ($key =~ /^Delete-$paramtag(\d+)$/);
206         my ($val, $msg) = $CustomFieldObj->DeleteValue($1);
207         push (@results, $msg);
208
209
210 }
211 # Update any existing values
212 my $values = $CustomFieldObj->ValuesObj;
213 while (my $value = $values->Next) {
214         foreach my $attr qw(Name Description SortOrder Category) {
215         my $param = $paramtag.$value->Id."-".$attr;
216
217         if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param}))  {
218                 my $mutator = "Set$attr";
219                 my ($id, $msg) = $value->$mutator($ARGS{$param});
220         push (@results, $msg);
221                 }
222         }
223
224
225 }
226
227
228
229 # Add any new values
230 if ($ARGS{$paramtag."new-Name"}) {
231         my ($id, $msg) = $CustomFieldObj->AddValue (
232             map { $_ => $ARGS{$paramtag."new-$_"} }
233                 qw( Name Description SortOrder Category )
234         );
235         push (@results, $msg);
236 }
237
238 my $current_tab;
239 if ($ARGS{'Create'}){ 
240     $current_tab = "Admin/CustomFields/Modify.html?Create=1";
241 } else {
242     $current_tab = "Admin/CustomFields/Modify.html?id=".$id;
243     }
244
245
246 </%INIT>
247 <%ARGS>
248 $id => undef
249 $TypeComposite => undef
250 $LookupType => undef
251 $MaxValues => undef
252 $SortOrder => undef
253 $Description => undef
254 $Pattern => undef
255 $Name => undef
256 $SetEnabled => undef
257 $Enabled => undef
258 </%ARGS>