smarter form refresh
[freeside.git] / rt / share / html / Ticket / Create.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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,
49     Title => $title,
50     onload => "function () { hide(document.getElementById('Ticket-Create-details')) }" &>
51 <& /Elements/Tabs, 
52     current_toptab => "Ticket/Create.html", 
53     Title => $title,
54     actions => $actions &>
55 <& /Elements/ListActions, actions => \@results &>
56 <form action="<% RT->Config->Get('WebPath') %>/Ticket/Create.html" method="post" enctype="multipart/form-data" name="TicketCreate">
57 <input type="hidden" class="hidden" name="id" value="new" />
58 % $m->callback( CallbackName => 'FormStart', QueueObj => $QueueObj, ARGSRef => \%ARGS );
59 % if ($gnupg_widget) {
60 <& /Elements/GnuPG/SignEncryptWidget:ShowIssues, self => $gnupg_widget &>
61 % }
62 <div id="Ticket-Create-basics">
63 <a name="basics"></a>
64 <&| /Widgets/TitleBox, title => $title &>
65 <table border="0" cellpadding="0" cellspacing="0">
66 <tr><td class="label"><&|/l&>Queue</&>:</td>
67 %#<td class="value"><& Elements/ShowQueue, QueueObj => $QueueObj &>
68 %#<input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Name %>" />
69 <td class="value"><& /Elements/SelectQueue, 
70   Name => 'Queue', 
71   Default => $QueueObj->Name,
72   ShowNullOption => 0,
73   OnChange => "document.getElementsByName('id')[0].value = ''; form.submit()" &>
74 </td>
75 <td class="label"><&|/l&>Status</&>:
76 </td>
77 <td class="value">
78 <& /Elements/SelectStatus, Name => "Status", Default => $ARGS{Status}||'new', DefaultValue => 0, SkipDeleted => 1 &>
79 </td>
80 <td class="label">
81 <&|/l&>Owner</&>:
82 </td>
83 <td class="value">
84 <& /Elements/SelectOwner, Name => "Owner", QueueObj => $QueueObj, Default => $ARGS{Owner}||$RT::Nobody->Id, DefaultValue => 0 &>
85 </td>
86 % $m->callback( CallbackName => 'AfterOwner', ARGSRef => \%ARGS );
87 </tr>
88 <tr>
89 <td class="label">
90 <&|/l&>Requestors</&>:
91 </td>
92 <td class="value" colspan="5">
93 <& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
94 </td>
95 </tr>
96 <tr>
97 <td class="label">
98 <&|/l&>Cc</&>:
99 </td>
100 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'Cc', Size => '40', Default => $ARGS{Cc} &></td>
101 <td class="comment" colspan="2"><i><font size="-2">
102 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of email addresses. These people <strong>will</strong> receive future updates.)</&></font></i>
103 </td>
104 </tr>
105 <tr>
106 <td class="label">
107 <&|/l&>Admin Cc</&>:
108 </td>
109 <td class="value" colspan="3"><& /Elements/EmailInput, Name => 'AdminCc', Size => '40', Default => $ARGS{AdminCc} &></td>
110 <td class="comment" colspan="2"><i><font size="-2">
111 <&|/l&>(Sends a carbon-copy of this update to a comma-delimited list of administrative email addresses. These people <strong>will</strong> receive future updates.)</&></font></i>
112 </td>
113 </tr>
114 <tr>
115 <td class="label">
116 <&|/l&>Subject</&>:
117 </td>
118 <td class="value" colspan="5">
119 <input name="Subject" size="60" maxsize="200" value="<%$ARGS{Subject} || ''%>" />
120 % $m->callback( %ARGS, CallbackName => 'AfterSubject' );
121 </td>
122 </tr>
123 <tr>
124 <td colspan="6">
125 <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj &>
126 </td>
127 </tr>
128 <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj &>
129 <tr>
130 % if (exists $session{'Attachments'}) {
131 <td class="label">
132 <&|/l&>Attached file</&>:
133 </td>
134 <td colspan="5">
135 <&|/l&>Check box to delete</&><br />
136 % foreach my $attach_name (keys %{$session{'Attachments'}}) {
137 <input type="checkbox" class="checkbox" name="DeleteAttach-<%$attach_name%>" value="1" /><%$attach_name%><br />
138 % } # end of foreach
139 </td>
140 </tr>
141 <tr>
142 % } # end of if
143 <td class="label">
144 <&|/l&>Attach file</&>:
145 </td>
146 <td class="value" colspan="5">
147 <input type="file" name="Attach" />
148 <input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" />
149 </td>
150 </tr>
151
152 % if ( $gnupg_widget ) {
153 <tr><td>&nbsp;</td><td colspan="5">
154 <& /Elements/GnuPG/SignEncryptWidget, self => $gnupg_widget, QueueObj => $QueueObj &>
155 </td></tr>
156 % }
157
158 <tr>
159 <td colspan="6">
160 <&|/l&>Describe the issue below</&>:<br />
161 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'BeforeMessageBox' );
162 % if (exists $ARGS{Content}) {
163 <& /Elements/MessageBox, Default => $ARGS{Content}, IncludeSignature => 0 &>
164 % } else {
165 <& /Elements/MessageBox, QuoteTransaction => $QuoteTransaction &>
166 %}
167 % $m->callback( %ARGS, QueueObj => $QueueObj, CallbackName => 'AfterMessageBox' );
168
169 <br />
170 </td>
171 </tr>
172 </table>
173 </&>
174 <& /Elements/Submit, Label => loc("Create")&>
175 </div>
176
177 <div id="Ticket-Create-details">
178 <a name="details"></a>
179 <table width="100%" border="0">
180 <tr>
181 <td width="50%" valign="top" class="boxcontainer">
182     <div class="ticket-info-basics">
183           <&| /Widgets/TitleBox, title => loc('The Basics'), 
184                 title_class=> 'inverse',  
185                 color => "#993333" &>
186 <table border="0">
187 <tr><td class="label"><&|/l&>Priority</&>:</td>
188 <td><& /Elements/SelectPriority,
189     Name => "InitialPriority",
190     Default => $ARGS{InitialPriority} ? $ARGS{InitialPriority} : $QueueObj->InitialPriority,
191 &></td></tr>
192 <tr><td class="label"><&|/l&>Final Priority</&>:</td>
193 <td><& /Elements/SelectPriority,
194     Name => "FinalPriority",
195     Default => $ARGS{FinalPriority} ? $ARGS{FinalPriority} : $QueueObj->FinalPriority,
196 &></td></tr>
197 <tr><td class="label"><&|/l&>Time Estimated</&>:</td>
198 <td>
199 <& /Elements/EditTimeValue, Name => 'TimeEstimated', Default => $ARGS{TimeEstimated} || '', InUnits => $ARGS{'TimeEstimated-TimeUnits'} &>
200
201 </td></tr>
202 <tr><td class="label"><&|/l&>Time Worked</&>:</td>
203 <td>
204 <& /Elements/EditTimeValue, Name => 'TimeWorked', Default => $ARGS{TimeWorked} || '', InUnits => $ARGS{'TimeWorked-TimeUnits'} &>
205 </td></tr>
206 <tr>
207 <td class="label"><&|/l&>Time Left</&>:</td>
208 <td>
209 <& /Elements/EditTimeValue, Name => 'TimeLeft', Default => $ARGS{TimeLeft} || '', InUnits => $ARGS{'TimeLeft-TimeUnits'} &>
210 </td></tr>
211 </table>
212 </&>
213 <br />
214 <div class="ticket-info-dates">
215 <&|/Widgets/TitleBox, title => loc("Dates"),
216                 title_class=> 'inverse',  
217                  color => "#663366" &>
218
219 <table>
220 <tr><td class="label"><&|/l&>Starts</&>:</td><td><& /Elements/SelectDate, Name => "Starts", Default => $ARGS{Starts} || '' &></td></tr>
221 <tr><td class="label"><&|/l&>Due</&>:</td><td><& /Elements/SelectDate, Name => "Due", Default => $ARGS{Due} || '' &></td></tr>
222 </table>
223 </&>
224 </div>
225 </div>
226 <br />
227 </td>
228
229 <td valign="top" class="boxcontainer">
230 <div class="ticket-info-links">
231 <&| /Widgets/TitleBox, title => loc('Links'), title_class=> 'inverse' &>
232
233 <em><&|/l&>(Enter ticket ids or URLs, separated with spaces)</&></em>
234 <table border="0">
235 <tr><td class="label"><&|/l&>Depends on</&></td><td><input size="10" name="new-DependsOn" value="<% $ARGS{'new-DependsOn'} || '' %>" /></td></tr>
236 <tr><td class="label"><&|/l&>Depended on by</&></td><td><input size="10" name="DependsOn-new" value="<% $ARGS{'DependsOn-new'} || '' %>" /></td></tr>
237 <tr><td class="label"><&|/l&>Parents</&></td><td><input size="10" name="new-MemberOf" value="<% $ARGS{'new-MemberOf'} || '' %>" /></td></tr>
238 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
239 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
240 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
241
242
243 </table>
244 </&>
245 </div>
246 <br />
247
248 </td>
249 </tr>
250 </table>
251 <& /Elements/Submit, Label => loc("Create") &>
252 </div>
253 </form>
254
255 <%INIT>
256 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
257 my $Queue = $ARGS{Queue};
258
259 my $CloneTicketObj;
260 if ($CloneTicket) {
261     $CloneTicketObj = RT::Ticket->new( $session{CurrentUser} );
262     $CloneTicketObj->Load($CloneTicket)
263         or Abort( loc("Ticket could not be loaded") );
264
265     my $clone = {
266         Requestors => join( ',', $CloneTicketObj->RequestorAddresses ),
267         Cc         => join( ',', $CloneTicketObj->CcAddresses ),
268         AdminCc    => join( ',', $CloneTicketObj->AdminCcAddresses ),
269         InitialPriority => $CloneTicketObj->Priority,
270     };
271
272     $clone->{$_} = $CloneTicketObj->$_()
273         for qw/Owner Subject FinalPriority TimeEstimated TimeWorked
274         Status TimeLeft/;
275
276     $clone->{$_} = $CloneTicketObj->$_->AsString
277         for grep { $CloneTicketObj->$_->Unix }
278         map      { $_ . "Obj" } qw/Starts Started Due Resolved/;
279
280     my $members = $CloneTicketObj->Members;
281     my ( @members, @members_of, @refers, @refers_by, @depends, @depends_by );
282     my $refers = $CloneTicketObj->RefersTo;
283     while ( my $refer = $refers->Next ) {
284         push @refers, $refer->LocalTarget;
285     }
286     $clone->{'new-RefersTo'} = join ' ', @refers;
287
288     my $refers_by = $CloneTicketObj->ReferredToBy;
289     while ( my $refer_by = $refers_by->Next ) {
290         push @refers_by, $refer_by->LocalBase;
291     }
292     $clone->{'RefersTo-new'} = join ' ', @refers_by;
293     if (0) {    # Temporarily disabled
294         my $depends = $CloneTicketObj->DependsOn;
295         while ( my $depend = $depends->Next ) {
296             push @depends, $depend->LocalTarget;
297         }
298         $clone->{'new-DependsOn'} = join ' ', @depends;
299
300         my $depends_by = $CloneTicketObj->DependedOnBy;
301         while ( my $depend_by = $depends_by->Next ) {
302             push @depends_by, $depend_by->LocalBase;
303         }
304         $clone->{'DependsOn-new'} = join ' ', @depends_by;
305
306         while ( my $member = $members->Next ) {
307             push @members, $member->LocalBase;
308         }
309         $clone->{'MemberOf-new'} = join ' ', @members;
310
311         my $members_of = $CloneTicketObj->MemberOf;
312         while ( my $member_of = $members_of->Next ) {
313             push @members_of, $member_of->LocalTarget;
314         }
315         $clone->{'new-MemberOf'} = join ' ', @members_of;
316
317     }
318
319     my $cfs = $CloneTicketObj->QueueObj->TicketCustomFields();
320     while ( my $cf = $cfs->Next ) {
321         my $cf_id     = $cf->id;
322         my $cf_values = $CloneTicketObj->CustomFieldValues( $cf->id );
323         my @cf_values;
324         while ( my $cf_value = $cf_values->Next ) {
325             push @cf_values, $cf_value->Content;
326         }
327         $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
328             @cf_values;
329     }
330
331     for ( keys %$clone ) {
332         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
333     }
334
335 }
336
337 my @results;
338
339 my $title = loc("Create a new ticket");
340
341 my $QueueObj = new RT::Queue($session{'CurrentUser'});
342 $QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));
343
344 $m->callback( QueueObj => $QueueObj, title => \$title, results => \@results, ARGSRef => \%ARGS );
345
346 $QueueObj->Disabled && Abort(loc("Cannot create tickets in a disabled queue."));
347
348 my $CFs = $QueueObj->TicketCustomFields();
349
350 my $ValidCFs = $m->comp(
351     '/Elements/ValidateCustomFields',
352     CustomFields => $CFs,
353     ARGSRef => \%ARGS
354 );
355
356 # {{{ deal with deleting uploaded attachments
357 foreach my $key (keys %ARGS) {
358     if ($key =~ m/^DeleteAttach-(.+)$/) {
359         delete $session{'Attachments'}{$1};
360     }
361     $session{'Attachments'} = { %{$session{'Attachments'} || {}} };
362 }
363 # }}}
364
365 # {{{ store the uploaded attachment in session
366 if ($ARGS{'Attach'}) {                  # attachment?
367     my $attachment = MakeMIMEEntity(
368         AttachmentFieldName => 'Attach'
369     );
370
371     my $file_path = Encode::decode_utf8("$ARGS{'Attach'}");
372     $session{'Attachments'} = {
373         %{$session{'Attachments'} || {}},
374         $file_path => $attachment,
375     };
376 }
377 # }}}
378
379 # delete temporary storage entry to make WebUI clean
380 unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
381     delete $session{'Attachments'};
382 }
383
384 my $checks_failure = 0;
385
386 my $gnupg_widget = $m->comp('/Elements/GnuPG/SignEncryptWidget:new', Arguments => \%ARGS );
387 $m->comp( '/Elements/GnuPG/SignEncryptWidget:Process',
388     self      => $gnupg_widget,
389     QueueObj  => $QueueObj,
390 );
391
392
393 if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
394     my $status = $m->comp('/Elements/GnuPG/SignEncryptWidget:Check',
395         self      => $gnupg_widget,
396         Operation => 'Create',
397         QueueObj  => $QueueObj,
398     );
399     $checks_failure = 1 unless $status;
400 }
401
402 # check email addresses for RT's
403 {
404     foreach my $field ( qw(Requestors Cc AdminCc) ) {
405         my $value = $ARGS{ $field };
406         next unless defined $value && length $value;
407
408         my @emails = Email::Address->parse( $value );
409         foreach my $email ( grep RT::EmailParser->IsRTAddress($_->address), @emails ) {
410             push @results, loc("[_1] is an address RT receives mail at. Adding it as a '[_2]' would create a mail loop", $email->format, loc($field =~ /^(.*?)s?$/) );
411             $checks_failure = 1;
412             $email = undef;
413         }
414         $ARGS{ $field } = join ', ', map $_->format, grep defined, @emails;
415     }
416 }
417
418 my $skip_create = 0;
419 $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, 
420               checks_failure => $checks_failure, results => \@results );
421
422 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
423     if ( $ValidCFs && !$checks_failure && !$skip_create ) {
424         $m->comp('Display.html', %ARGS);
425         $RT::Logger->crit("After display call; error is $@");
426         $m->abort();
427     }
428     elsif ( !$ValidCFs ) {
429         # Invalid CFs
430         while (my $CF = $CFs->Next) {
431             my $msg = $m->notes('InvalidField-' . $CF->Id) or next;
432             push @results, $CF->Name . ': ' . $msg;
433         }
434     }
435 }
436
437 my $actions = {
438     A => {
439         html => q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Show basics') . q[</a>],
440     },
441     B => {
442         html => q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Show details') . q[</a>],
443     },
444 };
445 </%INIT>
446
447 <%ARGS>
448 $DependsOn => undef
449 $DependedOnBy => undef
450 $MemberOf => undef
451 $QuoteTransaction => undef
452 $CloneTicket => undef
453 </%ARGS>