TimeWorked-like custom fields, RT#11168
[freeside.git] / rt / share / html / Ticket / Update.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2011 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 <& /Elements/Header, Title => $title &>
49 <& /Ticket/Elements/Tabs, 
50     Ticket => $TicketObj, 
51     Title=> $title &>
52     
53 % $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $TicketObj);
54 <& /Elements/ListActions, actions => \@results &>
55
56 <form action="Update.html" name="TicketUpdate"
57     method="post" enctype="multipart/form-data">
58 % $m->callback( CallbackName => 'FormStart', ARGSRef => \%ARGS, Ticket => $TicketObj, CanRespond => $CanRespond, CanComment => $CanComment, ResponseDefault => $ResponseDefault, CommentDefault => $CommentDefault );
59 <input type="hidden" class="hidden" name="QuoteTransaction" value="<% $ARGS{QuoteTransaction}||'' %>" />
60 <input type="hidden" class="hidden" name="DefaultStatus" value="<% $DefaultStatus ||''%>" />
61 <input type="hidden" class="hidden" name="Action" value="<% $ARGS{Action}||'' %>" />
62
63 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
64
65 <table width="100%" border="0">
66 % $m->callback(CallbackName => 'AfterTableOpens', ARGSRef => \%ARGS, Ticket => $TicketObj);
67
68 <tr><td valign="baseline" class="label"><&|/l&>Status</&>:</td>
69 <td valign="baseline">
70 <& /Elements/SelectStatus, Name=>"Status", DefaultLabel => loc("[_1] (Unchanged)", loc($TicketObj->Status)), Default => $ARGS{'Status'} || ($TicketObj->Status eq $DefaultStatus ? undef : $DefaultStatus)&>
71 <span class="label"><&|/l&>Owner</&>:</span>
72 <& /Elements/SelectOwner,
73     Name         => "Owner",
74     TicketObj    => $TicketObj,
75     QueueObj     => $TicketObj->QueueObj,
76     DefaultLabel => loc("[_1] (Unchanged)", $m->scomp('/Elements/ShowUser', User => $TicketObj->OwnerObj)),
77     Default      => $ARGS{'Owner'}
78 &>
79 </td>
80 <td rowspan=4 valign="top">
81 <table style="float:right;">
82 <tr>
83 <td class="label"><&|/l&>Worked</&>:</td>
84 <td><& /Elements/EditTimeValue,
85     Name => 'UpdateTimeWorked',
86     Default => $ARGS{UpdateTimeWorked}||'',
87     InUnits => $ARGS{'UpdateTimeWorked-TimeUnits'}||'minutes',
88 &>
89 </td></tr>
90 <& /Ticket/Elements/EditTransactionCustomFields, 
91     %ARGS,
92     TicketObj   => $TicketObj,
93     UILocation  => 'TimeWorked',
94 &>
95 </table></td></tr>
96 % my $skip;
97 % $m->callback( %ARGS, CallbackName => 'BeforeUpdateType', skip => \$skip );
98 % if (!$skip) {
99 <input type="hidden" class="hidden" name="id" value="<%$TicketObj->Id%>" /><br />
100 % }
101 <tr><td class="label"><&|/l&>Update Type</&>:</td>
102 <td><select name="UpdateType">
103 % if ($CanComment) {
104 <option value="private" <% ($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq "private") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$CommentDefault |n %>><&|/l&>Comments (Not sent to requestors)</&></option>
105 % }
106 % if ($CanRespond) {
107 <option value="response" <% ($ARGS{'UpdateType'} && $ARGS{'UpdateType'} eq "response") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$ResponseDefault |n %>><&|/l&>Reply to requestors</&></option>
108 % }
109 </select> 
110 % $m->callback( %ARGS, CallbackName => 'AfterUpdateType' );
111 </td></tr>
112 <tr><td class="label"><&|/l&>Subject</&>:</td><td> <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || $TicketObj->Subject()%>" />
113 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
114 </td></tr>
115
116 <& /Ticket/Elements/UpdateCc, %ARGS, TicketObj => $TicketObj &>
117
118 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, TicketObj => $TicketObj &>
119
120 % if (exists $session{'Attachments'}) {
121 <tr><td><&|/l&>Attached file</&>:</td>
122 <td>
123 <&|/l&>Check box to delete</&><br />
124 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
125 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
126 % } # end of foreach
127 </td>
128 </tr>
129 % } # end of if
130
131 <tr><td class="label"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
132 </td></tr>
133
134 % if ( $gnupg_widget ) {
135 <tr><td>&nbsp;</td><td>
136 <& /Elements/GnuPG/SignEncryptWidget,
137     self => $gnupg_widget,
138     TicketObj => $TicketObj,
139 &>
140 </td></tr>
141 % }
142 % $m->callback( %ARGS, CallbackName => 'AfterGnuPG' );
143
144 <tr><td class="label" valign="top"><&|/l&>Message</&>:</td><td colspan=2>
145 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
146 % if (exists $ARGS{UpdateContent}) {
147 % # preserve QuoteTransaction so we can use it to set up sane references/in/reply to
148 % my $temp = $ARGS{'QuoteTransaction'};
149 % delete $ARGS{'QuoteTransaction'};
150 <& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&>
151 % $ARGS{'QuoteTransaction'} = $temp;
152 % } else {
153 % my $IncludeSignature = 1;
154 % $IncludeSignature = 0 if $Action ne 'Respond' && !RT->Config->Get('MessageBoxIncludeSignatureOnComment');
155 <& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &>
156 % }
157 </td></tr>
158 </table>
159
160
161
162
163 <& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket' &>
164 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
165 <&|/Widgets/TitleBox, title => loc('Scrips and Recipients') &>
166 <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
167 </&>
168
169 % }
170 </form>
171 <%INIT>
172 my $CanRespond = 0;
173 my $CanComment = 0;
174 my $checks_failure = 0;
175 my $title;
176
177 my $TicketObj = LoadTicket($id);
178
179 my @results;
180
181 $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, checks_failure => \$checks_failure, results => \@results, CallbackName => 'Initial' );
182
183 unless($DefaultStatus){
184     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());
185 }
186
187 unless (RT->Config->Get('SuppressAutoOpenOnUpdate', $session{'CurrentUser'})) {
188     if ($DefaultStatus eq 'new') {
189         $DefaultStatus = 'open';
190     }
191 }
192
193 if ($DefaultStatus eq 'resolved') {
194     $title = loc("Resolve ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
195 } else {
196     $title = loc("Update ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject);
197 }
198
199 # Things needed in the template - we'll do the processing here, just
200 # for the convenience:
201
202 my ($CommentDefault, $ResponseDefault);
203 if ($Action ne 'Respond') {
204     $CommentDefault = qq[ selected="selected"]; 
205     $ResponseDefault = "";
206 } else {
207     $CommentDefault = ""; 
208     $ResponseDefault = qq[ selected="selected"];
209 }
210
211
212
213 $CanRespond = 1 if ( $TicketObj->CurrentUserHasRight('ReplyToTicket') or
214                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
215
216 $CanComment = 1 if ( $TicketObj->CurrentUserHasRight('CommentOnTicket') or
217                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
218
219
220 # {{{ deal with deleting uploaded attachments
221 foreach my $key (keys %ARGS) {
222     if ($key =~ m/^DeleteAttach-(.+)$/) {
223         delete $session{'Attachments'}{$1};
224     }
225     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
226 }
227 # }}}
228
229 # {{{ store the uploaded attachment in session
230 if ($ARGS{'Attach'}) {            # attachment?
231     my $attachment = MakeMIMEEntity(
232         AttachmentFieldName => 'Attach'
233     );
234
235     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
236     $session{'Attachments'} = {
237         %{$session{'Attachments'} || {}},
238         $file_path => $attachment,
239     };
240 }
241 # }}}
242
243 # delete temporary storage entry to make WebUI clean
244 unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) {
245     delete $session{'Attachments'};
246 }
247 # }}}
248
249 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
250 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
251     self => $gnupg_widget,
252     TicketObj => $TicketObj,
253 );
254
255 if ( $ARGS{'SubmitTicket'} ) {
256     my $CFs = $TicketObj->TransactionCustomFields;
257     my $ValidCFs = $m->comp(
258         '/Elements/ValidateCustomFields',
259         CustomFields => $CFs,
260         NamePrefix => "Object-RT::Transaction--CustomField-",
261         ARGSRef => \%ARGS
262     );
263     unless ( $ValidCFs ) {
264         $checks_failure = 1;
265         while (my $CF = $CFs->Next) {
266             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
267             push @results, loc($CF->Name) . ': ' . $msg;
268         }
269     }
270     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
271         self      => $gnupg_widget,
272         TicketObj => $TicketObj,
273     );
274     $checks_failure = 1 unless $status;
275 }
276
277 # check email addresses for RT's
278 {
279     foreach my $field ( qw(UpdateCc UpdateBcc) ) {
280         my $value = $ARGS{ $field };
281         next unless defined $value && length $value;
282
283         my @emails = Email::Address->parse( $value );
284         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
285             push @results, loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $email->format, loc(substr($field, 6)) );
286             $checks_failure = 1;
287             $email = undef;
288         }
289         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
290     }
291 }
292 my $skip_update = 0;
293 $m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update,
294               checks_failure => $checks_failure, results => \@results, TicketObj => $TicketObj );
295
296 if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
297     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
298     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
299 }
300 </%INIT>
301
302 <%ARGS>
303 $id => undef
304 $Action => undef
305 $DefaultStatus => undef
306 </%ARGS>