Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / rt / share / html / Ticket / Update.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %#
3 %# COPYRIGHT:
4 %#
5 %# This software is Copyright (c) 1996-2014 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 <& /Elements/Tabs &>
50
51 % $m->callback(CallbackName => 'BeforeActionList', ARGSRef => \%ARGS, Ticket => $TicketObj);
52 <& /Elements/ListActions, actions => \@results &>
53
54 <form action="Update.html" name="TicketUpdate"
55     method="post" enctype="multipart/form-data">
56 % $m->callback( CallbackName => 'FormStart', ARGSRef => \%ARGS, Ticket => $TicketObj, CanRespond => $CanRespond, CanComment => $CanComment, ResponseDefault => $ResponseDefault, CommentDefault => $CommentDefault );
57 <input type="hidden" class="hidden" name="QuoteTransaction" value="<% $ARGS{QuoteTransaction}||'' %>" />
58 <input type="hidden" class="hidden" name="DefaultStatus" value="<% $DefaultStatus ||''%>" />
59 <input type="hidden" class="hidden" name="Action" value="<% $ARGS{Action}||'' %>" />
60
61 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
62
63 <div id="ticket-update-metadata">
64   <&|/Widgets/TitleBox, title => loc('Ticket and Transaction') &>
65 <table width="100%" border="0">
66 % $m->callback(CallbackName => 'AfterTableOpens', ARGSRef => \%ARGS, Ticket => $TicketObj);
67
68 <& /Ticket/Elements/EditTransactionCustomFields, 
69     %ARGS,
70     TicketObj   => $TicketObj,
71     UILocation  => 'TimeWorked',
72 &>
73
74 % my $skip;
75 % $m->callback( %ARGS, CallbackName => 'BeforeUpdateType', skip => \$skip );
76 % if (!$skip) {
77 <input type="hidden" class="hidden" name="id" value="<%$TicketObj->Id%>" /><br />
78 % }
79 <tr><td class="label"><&|/l&>Update Type</&>:</td>
80 <td><select name="UpdateType" id="UpdateType">
81 % if ($CanComment) {
82 <option value="private" <% ($ARGS{'UpdateType'} &&  $ARGS{'UpdateType'} eq "private") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$CommentDefault |n %>><&|/l&>Comments (Not sent to requestors)</&></option>
83 % }
84 % if ($CanRespond) {
85 <option value="response" <% ($ARGS{'UpdateType'} && $ARGS{'UpdateType'} eq "response") ? qq[ selected="selected"] : !$ARGS{'UpdateType'}&&$ResponseDefault |n %>><&|/l&>Reply to requestors</&></option>
86 % }
87 </select> 
88
89 <script type="text/javascript">
90     jQuery(function() {
91         jQuery("#UpdateType").change(function(ev) {
92             jQuery(".messagebox-container")
93                 .removeClass("action-response action-private")
94                 .addClass("action-"+ev.target.value);
95         });
96     });
97     jQuery(function() {
98         jQuery("input[name=TxnSendMailTo]").change(function(ev) {
99             jQuery("input[name=TxnSendMailTo][value="+ev.target.value+"]")
100                   .attr("checked",jQuery(ev.target).attr('checked'));
101         });
102     });
103 </script>
104
105 % $m->callback( %ARGS, CallbackName => 'AfterUpdateType' );
106 </td></tr>
107
108 <script type="text/javascript">
109 function changeStatus() {
110   var Status_select = document.getElementById('Status');
111   var x = Status_select.options[Status_select.selectedIndex].value;
112   var text = document.getElementById('WillResolve_Date');
113   var button = document.getElementById('WillResolve_Date_date_button');
114   if (x == 'resolved' || x == 'rejected' || x == 'deleted') {
115     text.disabled = true;
116     button.style.display = 'none';
117   }
118   else {
119     text.disabled = false;
120     button.style.display = 'inline';
121   }
122 }
123 </script>
124
125 <& /Ticket/Elements/EditBasics,
126     TicketObj => $TicketObj,
127     InTable   => 1,
128     fields    => [
129         {   name => 'Status',
130             comp => '/Elements/SelectStatus',
131             args => {
132                 Name => 'Status',
133                 DefaultLabel => loc("[_1] (Unchanged)", loc($TicketObj->Status)),
134                 Default => $ARGS{'Status'} || ($TicketObj->Status eq $DefaultStatus ? undef : $DefaultStatus),
135                 TicketObj => $TicketObj,
136                 QueueObj => $TicketObj->QueueObj,
137                 onchange => 'changeStatus()'
138             },
139         },
140         {   name => 'Resolve this Ticket on',
141             comp => '/Elements/SelectDate',
142             args => {
143                 menu_prefix => 'WillResolve',
144                 current => 0,
145                 ShowTime => 0,
146             },
147         },
148         {   name => 'Owner',
149             comp => '/Elements/SelectOwner',
150             args => {
151                 Name         => "Owner",
152                 TicketObj    => $TicketObj,
153                 QueueObj     => $TicketObj->QueueObj,
154                 DefaultLabel => loc("[_1] (Unchanged)", $m->scomp('/Elements/ShowUser', User => $TicketObj->OwnerObj)),
155                 Default      => $ARGS{'Owner'}
156             }
157         },
158         {   name => 'Worked',
159             comp => '/Elements/EditTimeValue',
160             args => {
161                 Name => 'UpdateTimeWorked',
162                 Default => $ARGS{UpdateTimeWorked}||'',
163                 InUnits => $ARGS{'UpdateTimeWorked-TimeUnits'}||'minutes',
164             }
165         },
166     ]
167 &>
168
169 <script type="text/javascript">
170 changeStatus();
171 </script>
172
173 % $m->callback( %ARGS, CallbackName => 'AfterWorked', Ticket => $TicketObj );
174
175 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, TicketObj => $TicketObj, AsTable => 1 &>
176
177   <!--</table>-->
178   </&>
179 </div>
180
181 <div id="ticket-update-message">
182   <& /Ticket/Elements/ShowSimplifiedRecipients, TicketObj => $TicketObj, %ARGS &>
183
184   <&|/Widgets/TitleBox, title => loc('Message'), class => 'messagedetails' &>
185   <table width="100%" border="0">
186 <& /Ticket/Elements/UpdateCc, %ARGS, TicketObj => $TicketObj &>
187
188 % if ( $gnupg_widget ) {
189 <tr><td>&nbsp;</td><td>
190 <& /Elements/GnuPG/SignEncryptWidget,
191     self => $gnupg_widget,
192     TicketObj => $TicketObj,
193 &>
194 </td></tr>
195 % }
196 % $m->callback( %ARGS, CallbackName => 'AfterGnuPG' );
197
198 <tr><td class="label"><&|/l&>Subject</&>:</td><td> <input type="text" name="UpdateSubject" value="<% $ARGS{UpdateSubject} || $TicketObj->Subject || '' %>" />
199 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
200 </td></tr>
201
202 <tr><td class="label" valign="top"><&|/l&>Message</&>:</td>
203 <td class="messagebox-container action-<% $type %>">
204 <& /Articles/Elements/BeforeMessageBox, %ARGS &>
205 % $m->callback( %ARGS, CallbackName => 'BeforeMessageBox' );
206 % if (exists $ARGS{UpdateContent}) {
207 % # preserve QuoteTransaction so we can use it to set up sane references/in/reply to
208 % my $temp = $ARGS{'QuoteTransaction'};
209 % delete $ARGS{'QuoteTransaction'};
210 <& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&>
211 % $ARGS{'QuoteTransaction'} = $temp;
212 % } else {
213 % my $IncludeSignature = 1;
214 % $IncludeSignature = 0 if $Action ne 'Respond' && !RT->Config->Get('MessageBoxIncludeSignatureOnComment');
215 <& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &>
216 % }
217 % $m->callback( %ARGS, CallbackName => 'AfterMessageBox' );
218 </td></tr>
219
220     <& /Ticket/Elements/AddAttachments, %ARGS, TicketObj => $TicketObj &>
221   </table>
222 </&>
223
224 % $m->callback( %ARGS, CallbackName => 'BeforeSubmit', Ticket => $TicketObj );
225
226   <& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket', id => 'SubmitTicket' &>
227
228 % $m->callback( %ARGS, CallbackName => 'BeforeScrips', Ticket => $TicketObj );
229
230 % if ($TicketObj->CurrentUserHasRight('ShowOutgoingEmail')) {
231   <&|/Widgets/TitleBox, title => loc('Scrips and Recipients'), id => 'previewscrips', rolledup => RT->Config->Get('SimplifiedRecipients', $session{'CurrentUser'}) &>
232     <& /Ticket/Elements/PreviewScrips, TicketObj => $TicketObj, %ARGS &>
233   </&>
234 % }
235 </div>
236
237 % $m->callback( %ARGS, CallbackName => 'AfterScrips', Ticket => $TicketObj );
238
239 % if (my $recips = $m->notes("DryRun-Recipients-".$TicketObj->Id)) {
240 <input type="hidden" name="TxnRecipients" value="<% join ",",sort keys %{$recips} %>" />
241 % }
242
243 </form>
244 <hr class="clear" />
245
246 % $m->callback( %ARGS, CallbackName => 'AfterForm', Ticket => $TicketObj );
247
248 <%INIT>
249 my $CanRespond = 0;
250 my $CanComment = 0;
251 my $checks_failure = 0;
252
253 my $TicketObj = LoadTicket($id);
254
255 my @results;
256
257 $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, checks_failure => \$checks_failure, results => \@results, CallbackName => 'Initial' );
258
259 unless($DefaultStatus){
260     $DefaultStatus=($ARGS{'Status'} ||$TicketObj->Status());
261 }
262
263 my $title = loc("Update ticket #[_1] ([_2])", $TicketObj->id, $TicketObj->Subject||'');
264
265 # Things needed in the template - we'll do the processing here, just
266 # for the convenience:
267
268 my ($CommentDefault, $ResponseDefault);
269 if ($Action ne 'Respond') {
270     $CommentDefault = qq[ selected="selected"]; 
271     $ResponseDefault = "";
272 } else {
273     $CommentDefault = ""; 
274     $ResponseDefault = qq[ selected="selected"];
275 }
276
277 my $type =             $ARGS{'UpdateType'} ? $ARGS{'UpdateType'} :
278            lc $ARGS{'Action'} eq 'respond' ? 'response'          :
279            lc $ARGS{'Action'} eq 'comment' ? 'private'           :
280                                              'none'              ;
281
282
283 $CanRespond = 1 if ( $TicketObj->CurrentUserHasRight('ReplyToTicket') or
284                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
285
286 $CanComment = 1 if ( $TicketObj->CurrentUserHasRight('CommentOnTicket') or
287                      $TicketObj->CurrentUserHasRight('ModifyTicket') ); 
288
289
290 ProcessAttachments(ARGSRef => \%ARGS);
291
292 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
293 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
294     self => $gnupg_widget,
295     TicketObj => $TicketObj,
296 );
297
298 if ( $ARGS{'SubmitTicket'} ) {
299
300     my %squelched = ProcessTransactionSquelching( \%ARGS );
301     $ARGS{'SquelchMailTo'} = [keys %squelched] if keys %squelched;
302
303     my $CFs = $TicketObj->TransactionCustomFields;
304     my $ValidCFs = $m->comp(
305         '/Elements/ValidateCustomFields',
306         CustomFields => $CFs,
307         NamePrefix => "Object-RT::Transaction--CustomField-",
308         ARGSRef => \%ARGS
309     );
310     unless ( $ValidCFs ) {
311         $checks_failure = 1;
312         while (my $CF = $CFs->Next) {
313             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
314             push @results, loc($CF->Name) . ': ' . $msg;
315         }
316     }
317     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
318         self      => $gnupg_widget,
319         TicketObj => $TicketObj,
320     );
321     $checks_failure = 1 unless $status;
322 }
323
324 # check email addresses for RT's
325 {
326     foreach my $field ( qw(UpdateCc UpdateBcc) ) {
327         my $value = $ARGS{ $field };
328         next unless defined $value && length $value;
329
330         my @emails = Email::Address->parse( $value );
331         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
332             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)) );
333             $checks_failure = 1;
334             $email = undef;
335         }
336         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
337     }
338 }
339 my $skip_update = 0;
340 $m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update,
341               checks_failure => $checks_failure, results => \@results, TicketObj => $TicketObj );
342
343 if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) {
344     $m->callback( Ticket => $TicketObj, ARGSRef => \%ARGS, CallbackName => 'BeforeDisplay' );
345     return $m->comp('Display.html', TicketObj => $TicketObj, %ARGS);
346 }
347 </%INIT>
348
349 <%ARGS>
350 $id => undef
351 $Action => undef
352 $DefaultStatus => undef
353 </%ARGS>