7baed168bbb072f441b2d2a6c1f666c0c0755fb1
[freeside.git] / rt / html / Admin / Elements / EditCustomField
1 %# BEGIN LICENSE BLOCK
2 %# 
3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4 %# 
5 %# (Except where explictly superceded by other copyright notices)
6 %# 
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
10 %# from www.gnu.org.
11 %# 
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 %# General Public License for more details.
16 %# 
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
21 %# 
22 %# 
23 %# END LICENSE BLOCK
24 <& /Elements/ListActions, actions => \@results &>
25
26
27 <FORM METHOD=POST ACTION="CustomField.html">
28 <INPUT TYPE=HIDDEN NAME="CustomField" VALUE="<%$id %>">
29 <INPUT TYPE=HIDDEN name="Queue" value="<%$Queue%>">
30
31 <TABLE WIDTH="100%" BORDER="0">
32 <TR><TD ALIGN="RIGHT">
33 <&|/l&>Name</&>:
34 </TD><TD>
35 <input name="Name" VALUE="<%$CustomFieldObj->Name%>" SIZE=20>
36 </TD></TR>
37 <TR><TD ALIGN="RIGHT">
38 <&|/l&>Description</&>:
39 </TD><TD>
40 <input name="Description" VALUE="<%$CustomFieldObj->Description%>" SIZE=80>
41 </TD></TR>
42 <TR><TD ALIGN="RIGHT">
43 <&|/l&>Type</&>:
44 </TD><TD>
45 <& /Admin/Elements/SelectCustomFieldType, Name => "Type", Default => $CustomFieldObj->Type &>
46 </TD></TR>
47 <TR><TD>
48 </TD><TD>
49 <INPUT TYPE=HIDDEN NAME="SetEnabled" VALUE="1">
50 <INPUT TYPE=CHECKBOX NAME="Enabled" VALUE="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this custom field)</&>
51 </TD></TR>
52 </TABLE>
53
54 <P>
55 % if ($CustomFieldObj->Id and $CustomFieldObj->Type =~ /Select/) {
56 <h2><&|/l&>Values</&></h2>
57 <font size=-1>
58 <& /Admin/Elements/EditCustomFieldValues, CustomField => $CustomFieldObj &>
59 <& /Admin/Elements/AddCustomFieldValue, CustomField => $CustomFieldObj &>
60 </font>
61 % }
62 <&/Elements/Submit&>
63 </FORM>
64
65
66
67 <%INIT>
68
69 my $CustomFieldObj = RT::CustomField->new($session{'CurrentUser'});
70 my $EnabledChecked = "CHECKED";
71 my (@results);
72
73 if (! $CustomField ) { 
74   $title = loc("Create a CustomField");
75   $id = 'new';
76 } else {
77
78     if ($CustomField eq 'new') {
79       my ($val, $msg) =  $CustomFieldObj->Create(Queue => $Queue, 
80                                                  Name => $Name, 
81                                                  Type => $Type,
82                                                  Description => $Description,
83                                                  );
84       Abort(loc("Could not create CustomField", $msg)) unless ($val);
85      push @results, $msg;
86      $CustomFieldObj->SetSortOrder($CustomFieldObj->id);
87      $title = loc('Created CustomField [_1]', $CustomFieldObj->Name()); 
88     } else {
89        $CustomFieldObj->Load($CustomField) || Abort(loc('No CustomField'));
90       $title = loc('Editing CustomField [_1]', $CustomFieldObj->Name()); 
91
92       my @aresults = ProcessCustomFieldUpdates ( 
93                         CustomFieldObj => $CustomFieldObj,
94                         ARGSRef => \%ARGS );
95      push @results, @aresults;
96     }
97
98
99 $id = $CustomFieldObj->id;
100
101   #we're asking about enabled on the web page but really care about disabled.
102   my $Disabled = ($Enabled ? 0 : 1);
103
104   if  ( ($SetEnabled) and ( $Disabled != $CustomFieldObj->Disabled) ) { 
105       my  ($code, $msg) = $CustomFieldObj->SetDisabled($Disabled);
106       push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
107   }
108   
109   if ($CustomFieldObj->Disabled()) {
110       $EnabledChecked ="";
111   }
112
113 }
114
115
116 </%INIT>
117 <%ARGS>
118 $id => undef
119 $title => undef
120 $Queue => undef
121 $CustomField => undef
122 $Type => undef
123 $Description => undef
124 $Name => undef
125 $SetEnabled => undef
126 $Enabled => undef
127 </%ARGS>