Initial commit 4.0.5-3
[usit-rt.git] / share / html / Admin / Articles / Classes / Modify.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
5%# This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
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 }}}
48<& /Admin/Elements/Header, Title => $title &>
49<& /Elements/Tabs &>
50<& /Elements/ListActions, actions => \@results &>
51
52<form name="ModifyClass" action="<% RT->Config->Get('WebPath') %>/Admin/Articles/Classes/Modify.html" method="post">
53<input type="hidden" name="Submitted" value="1" />
54%if ($Create ) {
55<input type="hidden" name="id" value="new" />
56% } else {
57<input type="hidden" name="id" value="<%$ClassObj->Id%>" />
58% }
59
60<table>
61<tr>
62<td align="right"><&|/l&>Class Name</&>: </td>
63<td><input name="Name" value="<% $ClassObj->Name || $Name || ''%>" /></td>
64</tr>
65<tr>
66<td align="right"><&|/l&>Description</&>:</td>
67<td><input name="Description" value="<% $ClassObj->Description || $Description || '' %>" size=60 /></td>
68</tr>
69<tr>
70<td>&nbsp;</td>
71<td><input type="checkbox" name="Enabled" value="1" <%$EnabledChecked%>> <&|/l&>Enabled (Unchecking this box disables this class)</&></td>
72</tr>
73<tr>
74<td>&nbsp;</td>
75<td><input type="checkbox" name="HotList" value="1" <%$HotListChecked%>> <&|/l&>All Articles in this class should be listed in a dropdown of the ticket reply page</&></td>
76</tr>
77</table>
78
79<h3>When inserting articles in this class into emails:</h3>
80<ul>
81<li><input type="checkbox" name="Include-Name" value="1" <% $include{Name} %>> Include article name</li>
82<li><input type="checkbox" name="Include-Summary" value="1" <% $include{Summary} %>> Include article summary</li>
83% if ( $cfs ) {
84% while (my $cf = $cfs->Next) {
85<li>Include custom field '<% $cf->Name %>'
86 <ul>
87 <li><input type="checkbox" name="Include-CF-Title-<% $cf->Id %>" <% $include{"CF-Title-".$cf->Id} %> />Title</li>
88 <li><input type="checkbox" name="Include-CF-Value-<% $cf->Id %>" <% $include{"CF-Value-".$cf->Id} %> />Value</li>
89 </ul>
90</li>
91% } }
92</ul>
93
94%$m->callback( CallbackName => 'BeforeSubmit', CustomFields => $cfs, ClassObj => $ClassObj );
95
96% if ( $Create ) {
97<& /Elements/Submit, Label => loc('Create') &>
98% } else {
99<& /Elements/Submit, Label => loc('Save Changes') &>
100% }
101</form>
102
103<%INIT>
104
105my $ClassObj = RT::Class->new($session{'CurrentUser'});
106my ($title, @results, $Disabled);
107
108if ($Create) {
109 $title = loc("Create a Class");
110} else {
111 my ( $val, $msg );
112 if ($id eq 'new') {
113 ($val, $msg) = $ClassObj->Create(Name => $Name);
114 if ( $val ) {
115 push @results, $msg;
116 }
117 else {
118 push @results, loc('Class could not be created: [_1]', $msg);
119 }
120 } else {
121 $ClassObj->Load($id) || $ClassObj->Load($Name) || $m->comp("/Elements/Error", Why => "Couldn't load class '$Name'");
122 $val = $ClassObj->id;
123 }
124
125 if ( $val ) {
126 $title = loc('Modify the Class [_1]', $ClassObj->Name);
127 }
128 else {
129 $title = loc("Create a Class");
130 $Create = 1;
131 }
132}
133
134if ($ClassObj->Id()) {
135 $ARGS{HotList} ||= 0 if $Submitted;
136 my @attribs= qw(Description Name HotList);
137 $m->callback( CallbackName => 'AttributeList', Attributes => \@attribs, ARGSRef => \%ARGS );
138 push @results, UpdateRecordObject( AttributesRef => \@attribs,
139 Object => $ClassObj,
140 ARGSRef => \%ARGS);
141}
142
143#we're asking about enabled on the web page but really care about disabled.
144if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
145 $Disabled = 0;
146} else {
147 $Disabled = 1;
148}
149
150my %include = (Name => 1, Summary => 1);
151
152my $cfs;
153if ( $ClassObj->id ) {
154 $cfs = $ClassObj->ArticleCustomFields;
155 $include{"CF-Title-".$_->Id} = $include{"CF-Value-".$_->Id} = 1 while $_ = $cfs->Next;
156}
157
158if ( $ClassObj->id && $Submitted ) {
159 if ( $Disabled != $ClassObj->Disabled) {
160 my ($code, $msg) = $ClassObj->SetDisabled($Disabled);
161 push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
162 }
163
164 for (keys %include) {
165 if ($ARGS{"Include-$_"}) {
166 $ClassObj->DeleteAttribute("Skip-$_");
167 } else {
168 $ClassObj->SetAttribute(Name => "Skip-$_", Content => 1);
169 }
170 }
171}
172
173# This code does automatic redirection if any updates happen.
174MaybeRedirectForResults(
175 Actions => \@results,
176 Arguments => { id => $ClassObj->Id },
177) if $ClassObj->id;
178
179
180if ( $ClassObj->id ) {
181 $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
182}
183
184$include{$_} = $include{$_} ? " CHECKED" : "" for keys %include;
185
186my $EnabledChecked = ($Create ? $Disabled : $ClassObj->Disabled()) ? "" : "CHECKED";
187my $HotListChecked = $ClassObj->id && $ClassObj->HotList ? "CHECKED" : "";
188</%INIT>
189
190
191<%ARGS>
192$id => undef
193$result => undef
194$Name => undef
195$Create => undef
196$Description => undef
197$Submitted => undef
198$Enabled => undef
199</%ARGS>