import rt 3.4.6
[freeside.git] / rt / html / Admin / Elements / EditCustomField
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 <& /Elements/ListActions, actions => \@results &>
47
48
49 <FORM METHOD=POST ACTION="CustomField.html">
50 <INPUT TYPE=HIDDEN NAME="CustomField" VALUE="<%$id %>">
51 <INPUT TYPE=HIDDEN name="Queue" value="<%$Queue%>">
52
53 <TABLE WIDTH="100%" BORDER="0">
54 <TR><TD ALIGN="RIGHT">
55 <&|/l&>Name</&>:
56 </TD><TD>
57 <input name="Name" VALUE="<%$CustomFieldObj->Name%>" SIZE=20>
58 </TD></TR>
59 <TR><TD ALIGN="RIGHT">
60 <&|/l&>Description</&>:
61 </TD><TD>
62 <input name="Description" VALUE="<%$CustomFieldObj->Description%>" SIZE=80>
63 </TD></TR>
64 <TR><TD ALIGN="RIGHT">
65 <&|/l&>Type</&>:
66 </TD><TD>
67 <& /Admin/Elements/SelectCustomFieldType, Name => "Type", Default => $CustomFieldObj->Type &>
68 </TD></TR>
69 <TR><TD>
70 </TD><TD>
71 <INPUT TYPE=HIDDEN NAME="SetEnabled" VALUE="1">
72 <INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
73 </TD></TR>
74 </TABLE>
75
76 <P>
77 % if ($CustomFieldObj->Id and $CustomFieldObj->Type =~ /Select/) {
78 <h2><&|/l&>Values</&></h2>
79 <font size=-1>
80 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
81 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
82 </font>
83 % }
84 <&/Elements/Submit, Label => loc('Create') &>
85 </FORM>
86
87
88
89 <%INIT>
90
91 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
92 my $EnabledChecked = "CHECKED";
93 my (@results);
94
95 if (! $CustomField ) { 
96   $title = loc("Create a CustomField");
97   $id = 'new';
98 } else {
99
100     if ($CustomField eq 'new') {
101       my ($val, $msg) =  $CustomFieldObj->Create(Queue => $Queue, 
102                                                  Name => $Name, 
103                                                  Type => $Type,
104                                                  Description => $Description,
105                                                  );
106       
107       # if there is an error, then abort.  But since at this point there's
108       # stuff already printed, clear it out.
109       # (This only works in conjunction with temporarily turning autoflush
110       #  off in the files that use this component.)
111       unless ($val) {
112           $m->clear_buffer;
113           Abort(loc("Could not create CustomField: [_1]", $msg));
114       }
115       push @results, $msg;
116       $CustomFieldObj->SetSortOrder($CustomFieldObj->id);
117       $title = loc('Created CustomField [_1]', $CustomFieldObj->Name()); 
118     } else {
119       $CustomFieldObj->Load($CustomField) || Abort(loc('No CustomField'));
120       $title = loc('Editing CustomField [_1]', $CustomFieldObj->Name()); 
121
122       my @aresults = ProcessCustomFieldUpdates ( 
123                         CustomFieldObj => $CustomFieldObj,
124                         ARGSRef => \%ARGS );
125       push @results, @aresults;
126     }
127
128
129 $id = $CustomFieldObj->id;
130
131   #we're asking about enabled on the web page but really care about disabled.
132   my $Disabled = ($Enabled ? 0 : 1);
133
134   if  ( ($SetEnabled) and ( $Disabled != $CustomFieldObj->Disabled) ) { 
135       my  ($code, $msg) = $CustomFieldObj->SetDisabled($Disabled);
136       push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
137   }
138   
139   if ($CustomFieldObj->Disabled()) {
140       $EnabledChecked ="";
141   }
142
143 }
144
145
146 </%INIT>
147 <%ARGS>
148 $id => undef
149 $title => undef
150 $Queue => undef
151 $CustomField => undef
152 $Type => undef
153 $Description => undef
154 $Name => undef
155 $SetEnabled => undef
156 $Enabled => undef
157 </%ARGS>