import rt 3.4.4
[freeside.git] / rt / html / Admin / CustomFields / Modify.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2005 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., 675 Mass Ave, Cambridge, MA 02139, USA.
26 %# 
27 %# 
28 %# CONTRIBUTION SUBMISSION POLICY:
29 %# 
30 %# (The following paragraph is not intended to limit the rights granted
31 %# to you to modify and distribute this software under the terms of
32 %# the GNU General Public License and is only of importance to you if
33 %# you choose to contribute your changes and enhancements to the
34 %# community by submitting them to Best Practical Solutions, LLC.)
35 %# 
36 %# By intentionally submitting any modifications, corrections or
37 %# derivatives to this work, or any other work intended for use with
38 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 %# you are the copyright holder for those contributions and you grant
40 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
41 %# royalty-free, perpetual, license to use, copy, create derivative
42 %# works based on those contributions, and sublicense and distribute
43 %# those contributions and any derivatives thereof.
44 %# 
45 %# END BPS TAGGED BLOCK }}}
46 <& /Admin/Elements/Header, Title => $title &>
47 <& /Admin/Elements/CustomFieldTabs,
48     id => $CustomFieldObj->Id ,
49     current_tab => $current_tab,
50     Title => $title &>
51 <& /Elements/ListActions, actions => \@results &>
52
53
54 <FORM METHOD="POST" ACTION="Modify.html" NAME="ModifyCustomField">
55 <INPUT TYPE=HIDDEN NAME="id" VALUE="<%$id %>">
56 <table>
57 <tr>
58 <td class="label"><&|/l&>Name</&></td>
59 <td><input name="Name" VALUE="<%$CustomFieldObj->Name%>" SIZE=20></td></tr>
60 <tr>
61 <td class="label"><&|/l&>Description</&></td>
62 <td><input name="Description" VALUE="<%$CustomFieldObj->Description%>" SIZE=80></td>
63 </tr>
64
65 <tr>
66 <td class="label"><&|/l&>Type</&></td>
67 <td><& /Admin/Elements/SelectCustomFieldType, 
68         Name => "TypeComposite", 
69         Default => $CustomFieldObj->TypeComposite, &>
70 </td>
71 </tr>
72 <tr>
73 <td class="label"><&|/l&>Applies to</&></td>
74 <td><& /Admin/Elements/SelectCustomFieldLookupType, 
75         Name => "LookupType", 
76         Default => $CustomFieldObj->LookupType, &>
77 </td>
78 </tr>
79 <tr>
80 <td class="label">&nbsp;</td>
81 <td>
82 <INPUT TYPE=HIDDEN NAME="SetEnabled" VALUE="1">
83 <INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
84 </td>
85 </tr>
86 </table>
87 <BR>
88 % if ($CustomFieldObj->Id && $CustomFieldObj->Type =~ /^Select/i) {
89 <H2><&|/l&>Values</&></H2>
90 <div>
91 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
92 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
93 </div>
94 % }
95 <&/Elements/Submit&>
96 </FORM>
97
98
99
100 <%INIT>
101
102
103
104 my $CustomFieldObj = RT::CustomField->new( $session{'CurrentUser'} );
105 my ( $title, @results, $EnabledChecked, $Disabled);
106 $EnabledChecked = "CHECKED";
107
108 if ( !$id ) {
109     $title = loc("Create a CustomField");
110     $id    = 'new';
111 }
112 else {
113
114     if ( $id eq 'new' ) {
115         my ( $val, $msg ) = $CustomFieldObj->Create(Name        => $Name,
116                                                     TypeComposite => $TypeComposite,
117                                                     LookupType => $LookupType,
118                                                     Description => $Description,);
119         $m->comp("/Elements/Error", Why =>  loc( "Could not create CustomField", $msg ) ) unless ($val);
120         push @results, $msg;
121         $title = loc( 'Created CustomField [_1]', $CustomFieldObj->Name() );
122     }
123     else {
124         $CustomFieldObj->Load($id) || $m->comp("/Elements/Error", Why =>  loc('No CustomField') );
125         $title = loc( 'Editing CustomField [_1]', $CustomFieldObj->Name() );
126
127         my @attribs = qw( Name TypeComposite LookupType Description);
128         my @aresults = UpdateRecordObject( AttributesRef => \@attribs,
129                                            Object        => $CustomFieldObj,
130                                            ARGSRef       => \%ARGS );
131
132         push @results, @aresults;
133
134         #we're asking about enabled on the web page but really care about disabled.
135         if ($Enabled == 1) {
136             $Disabled = 0;
137         }       
138         else {
139             $Disabled = 1;
140         }
141         if  ( ($SetEnabled) and ( $Disabled != $CustomFieldObj->Disabled) ) { 
142             my  ($code, $msg) = $CustomFieldObj->SetDisabled($Disabled);
143             push @results, loc('Enabled status: [_1]', loc_fuzzy($msg));
144         }
145         
146         if ($CustomFieldObj->Disabled()) {
147             $EnabledChecked ="";
148         }
149     }
150
151     $id = $CustomFieldObj->id;
152 }
153
154
155
156
157 my $paramtag = "CustomField-".$CustomFieldObj->Id."-Value-";
158 # Delete any fields that want to be deleted
159 foreach my $key (keys %ARGS) {
160         
161         next unless ($key =~ /^Delete-$paramtag(\d+)$/);
162         my ($val, $msg) = $CustomFieldObj->DeleteValue($1);
163         push (@results, $msg);
164
165
166 }
167 # Update any existing values
168 my $values = $CustomFieldObj->ValuesObj;
169 while (my $value = $values->Next) {
170         foreach my $attr qw(Name Description SortOrder) {
171         my $param = $paramtag.$value->Id."-".$attr;
172
173         if ( $ARGS{$param} && ($value->$attr() ne $ARGS{$param}))  {
174                 my $mutator = "Set$attr";
175                 my ($id, $msg) = $value->$mutator($ARGS{$param});
176         push (@results, $msg);
177                 }
178         }
179
180
181 }
182
183
184
185 # Add any new values
186 if ($ARGS{$paramtag."new-Name"}) {
187         my ($id, $msg) = $CustomFieldObj->AddValue ( Name => $ARGS{$paramtag."new-Name"},
188                                                  Description => $ARGS{$paramtag."new-Description"},
189                                                  SortOrder => $ARGS{$paramtag."new-SortOrder"});
190         push (@results, $msg);
191 }
192
193 my $current_tab;
194 if ($ARGS{'Create'}){ 
195     $current_tab = "Admin/CustomFields/Modify.html?Create=1";
196 } else {
197     $current_tab = "Admin/CustomFields/Modify.html?id=".$id;
198     }
199
200
201 </%INIT>
202 <%ARGS>
203 $id => undef
204 $TypeComposite => undef
205 $LookupType => undef
206 $MaxValues => undef
207 $SortOrder => undef
208 $Description => undef
209 $Name => undef
210 $SetEnabled => undef
211 $Enabled => undef
212 </%ARGS>