Fixed relative path for rt-libs.
[usit-rt.git] / share / html / Admin / Articles / Classes / Modify.html
CommitLineData
84fb5b46
MKG
1%# BEGIN BPS TAGGED BLOCK {{{
2%#
3%# COPYRIGHT:
4%#
403d7b0b 5%# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
84fb5b46
MKG
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>
af59614d
MKG
71<td>
72 <input type="checkbox" id="Enabled" name="Enabled" value="1" <%$EnabledChecked%>>
73 <label for="Enabled"><&|/l&>Enabled (Unchecking this box disables this class)</&></label>
74</td>
84fb5b46
MKG
75</tr>
76<tr>
77<td>&nbsp;</td>
af59614d
MKG
78<td>
79 <input type="checkbox" id="HotList" name="HotList" value="1" <%$HotListChecked%>>
80 <label for="HotList"><&|/l&>All Articles in this class should be listed in a dropdown of the ticket reply page</&></label>
81</td>
84fb5b46
MKG
82</tr>
83</table>
84
85<h3>When inserting articles in this class into emails:</h3>
86<ul>
af59614d
MKG
87<li>
88 <input type="checkbox" id="Include-Name" name="Include-Name" value="1" <% $include{Name} %>>
89 <label for="Include-Name"><&|/l&>Include article name</&></label>
90</li>
91<li>
92 <input type="checkbox" id="Include-Summary" name="Include-Summary" value="1" <% $include{Summary} %>>
93 <label for="Include-Summary"><&|/l&>Include article summary</&></label>
94</li>
84fb5b46
MKG
95% if ( $cfs ) {
96% while (my $cf = $cfs->Next) {
97<li>Include custom field '<% $cf->Name %>'
98 <ul>
af59614d
MKG
99 <li>
100 <input type="checkbox" id="Include-CF-Title-<% $cf->Id %>" name="Include-CF-Title-<% $cf->Id %>" <% $include{"CF-Title-".$cf->Id} %> />
101 <label for="Include-CF-Title-<% $cf->Id %>"><&|/l&>Title</&></label>
102 </li>
103 <li>
104 <input type="checkbox" id="Include-CF-Value-<% $cf->Id %>" name="Include-CF-Value-<% $cf->Id %>" <% $include{"CF-Value-".$cf->Id} %> />
105 <label for="Include-CF-Value-<% $cf->Id %>"><&|/l&>Value</&></label>
106 </li>
84fb5b46
MKG
107 </ul>
108</li>
109% } }
110</ul>
111
af59614d
MKG
112% if ( @$subject_cfs ) {
113<h3>Change email subject:</h3>
114<p><&|/l&>If a Custom Field is selected, the Subject of your outgoing email will be overridden by this article.</&></p>
115
116<& /Widgets/Form/Select,
117 Name => 'SubjectOverride',
118 DefaultLabel => 'No Subject Override',
119 Values => $subject_cfs,
120 ValuesLabel => $subject_cf_labels,
121 CurrentValue => $ClassObj->SubjectOverride,
122&>
123% }
124
84fb5b46
MKG
125%$m->callback( CallbackName => 'BeforeSubmit', CustomFields => $cfs, ClassObj => $ClassObj );
126
127% if ( $Create ) {
128<& /Elements/Submit, Label => loc('Create') &>
129% } else {
130<& /Elements/Submit, Label => loc('Save Changes') &>
131% }
132</form>
133
134<%INIT>
135
136my $ClassObj = RT::Class->new($session{'CurrentUser'});
137my ($title, @results, $Disabled);
138
139if ($Create) {
140 $title = loc("Create a Class");
141} else {
142 my ( $val, $msg );
143 if ($id eq 'new') {
144 ($val, $msg) = $ClassObj->Create(Name => $Name);
145 if ( $val ) {
146 push @results, $msg;
147 }
148 else {
149 push @results, loc('Class could not be created: [_1]', $msg);
150 }
151 } else {
152 $ClassObj->Load($id) || $ClassObj->Load($Name) || $m->comp("/Elements/Error", Why => "Couldn't load class '$Name'");
153 $val = $ClassObj->id;
154 }
155
156 if ( $val ) {
157 $title = loc('Modify the Class [_1]', $ClassObj->Name);
158 }
159 else {
160 $title = loc("Create a Class");
161 $Create = 1;
162 }
163}
164
165if ($ClassObj->Id()) {
af59614d
MKG
166
167 if ($ARGS{SubjectOverride}) {
168 $ARGS{SubjectOverride} = $m->comp('/Widgets/Form/Select:Process',
169 Arguments => \%ARGS,
170 Name => 'SubjectOverride',
171 DefaultValue => (''),
172 );
173 }
174
84fb5b46 175 $ARGS{HotList} ||= 0 if $Submitted;
af59614d 176 my @attribs= qw(Description Name HotList SubjectOverride);
84fb5b46
MKG
177 $m->callback( CallbackName => 'AttributeList', Attributes => \@attribs, ARGSRef => \%ARGS );
178 push @results, UpdateRecordObject( AttributesRef => \@attribs,
179 Object => $ClassObj,
180 ARGSRef => \%ARGS);
181}
182
183#we're asking about enabled on the web page but really care about disabled.
184if ((defined $Enabled && $Enabled == 1) or (not defined $Enabled and $Create)) {
185 $Disabled = 0;
186} else {
187 $Disabled = 1;
188}
189
190my %include = (Name => 1, Summary => 1);
af59614d
MKG
191my $subject_cfs = [];
192my $subject_cf_labels = {};
84fb5b46
MKG
193
194my $cfs;
195if ( $ClassObj->id ) {
196 $cfs = $ClassObj->ArticleCustomFields;
af59614d
MKG
197 while ( my $cf = $cfs->Next ) {
198 $include{"CF-Title-".$cf->Id} = $include{"CF-Value-".$cf->Id} = 1;
199 push @$subject_cfs,$cf->Id;
200 $subject_cf_labels->{$cf->Id} = $cf->Name;
201 }
84fb5b46
MKG
202}
203
204if ( $ClassObj->id && $Submitted ) {
205 if ( $Disabled != $ClassObj->Disabled) {
206 my ($code, $msg) = $ClassObj->SetDisabled($Disabled);
207 push @results, loc('Enabled status [_1]', loc_fuzzy($msg));
208 }
209
210 for (keys %include) {
211 if ($ARGS{"Include-$_"}) {
212 $ClassObj->DeleteAttribute("Skip-$_");
213 } else {
214 $ClassObj->SetAttribute(Name => "Skip-$_", Content => 1);
215 }
216 }
217}
218
219# This code does automatic redirection if any updates happen.
220MaybeRedirectForResults(
221 Actions => \@results,
222 Arguments => { id => $ClassObj->Id },
223) if $ClassObj->id;
224
225
226if ( $ClassObj->id ) {
227 $include{$_} = not $ClassObj->FirstAttribute("Skip-$_") for keys %include;
228}
229
230$include{$_} = $include{$_} ? " CHECKED" : "" for keys %include;
231
232my $EnabledChecked = ($Create ? $Disabled : $ClassObj->Disabled()) ? "" : "CHECKED";
233my $HotListChecked = $ClassObj->id && $ClassObj->HotList ? "CHECKED" : "";
234</%INIT>
235
236
237<%ARGS>
238$id => undef
239$result => undef
240$Name => undef
241$Create => undef
242$Description => undef
243$Submitted => undef
244$Enabled => undef
245</%ARGS>