
sunnavy at bestpractical
Feb 27, 2012, 5:54 AM
Post #1 of 1
(116 views)
Permalink
|
|
rt branch, 4.0/selfservice-attach-more, created. rt-4.0.5-79-g6dd0513
|
|
The branch, 4.0/selfservice-attach-more has been created at 6dd0513402d675d8eb0253ab8ab47126e6c50419 (commit) - Log ----------------------------------------------------------------- commit 6dd0513402d675d8eb0253ab8ab47126e6c50419 Author: sunnavy <sunnavy [at] bestpractical> Date: Mon Feb 27 20:41:35 2012 +0800 attach more files support for self service diff --git a/share/html/SelfService/Create.html b/share/html/SelfService/Create.html index e28ab0f..d1bf7dc 100755 --- a/share/html/SelfService/Create.html +++ b/share/html/SelfService/Create.html @@ -91,16 +91,7 @@ <& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $queue_obj &> </td> </tr> -<tr> -<td class="label"> -%# FIXME: if failed customfields validation, attachement needs to be choosen -%# again by user. -<&|/l&>Attach file</&>: -</td> -<td class="value"> -<input name="Attach" type="file" /> -</td> -</tr> +<& /Ticket/Elements/AddAttachments, %ARGS, QueueObj => $queue_obj &> </table> <table width="100%"> <tr> @@ -128,10 +119,37 @@ my $ValidCFs = $m->comp( ARGSRef => \%ARGS ); +# deal with deleting uploaded attachments +foreach my $key (keys %ARGS) { + if ($key =~ m/^DeleteAttach-(.+)$/) { + delete $session{'Attachments'}{$1}; + } + $session{'Attachments'} = { %{$session{'Attachments'} || {}} }; +} + +# store the uploaded attachment in session +if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment? + my $attachment = MakeMIMEEntity( + AttachmentFieldName => 'Attach' + ); + + my $file_path = Encode::decode_utf8("$ARGS{'Attach'}"); + $session{'Attachments'} = { + %{$session{'Attachments'} || {}}, + $file_path => $attachment, + }; +} + +# delete temporary storage entry to make WebUI clean +unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') { + delete $session{'Attachments'}; +} + + my $skip_create = 0; $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, results => \@results ); -if ( defined($ARGS{'id'}) and $ARGS{'id'} eq 'new' ) { # new ticket? +if ( !exists $ARGS{'AddMoreAttach'} and defined($ARGS{'id'}) and $ARGS{'id'} eq 'new' ) { # new ticket? if ( $ValidCFs && !$skip_create ) { $m->comp('Display.html', %ARGS); $RT::Logger->crit("After display call; error is $@"); diff --git a/share/html/SelfService/Display.html b/share/html/SelfService/Display.html index 23c7467..bf87c71 100755 --- a/share/html/SelfService/Display.html +++ b/share/html/SelfService/Display.html @@ -100,21 +100,6 @@ my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id); my $Ticket = RT::Ticket->new( $session{'CurrentUser'} ); -# store the uploaded attachment in session -if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment? - $session{'Attachments'} = {} unless defined $session{'Attachments'}; - - my $attachment = MakeMIMEEntity( - AttachmentFieldName => 'Attach' - ); - - my $file_path = Encode::decode_utf8("$ARGS{'Attach'}"); - $session{'Attachments'} = { - %{ $session{'Attachments'} || {} }, - $file_path => $attachment, - }; -} - if ( defined ($id[0]) && $id[0] eq 'new' ) { # {{{ Create a new ticket @@ -134,7 +119,7 @@ if ( defined ($id[0]) && $id[0] eq 'new' ) { ( $Ticket, @results ) = - CreateTicket( Attachments => $session{'Attachments'}, %ARGS ); + CreateTicket( Attachments => delete $session{'Attachments'}, %ARGS ); unless ( $Ticket->id ) { $m->comp( 'Error.html', Why => join( "\n", @results )); diff --git a/share/html/SelfService/Update.html b/share/html/SelfService/Update.html index 6525d3d..2b9444f 100755 --- a/share/html/SelfService/Update.html +++ b/share/html/SelfService/Update.html @@ -51,7 +51,8 @@ % $m->callback(CallbackName => 'BeforeForm', %ARGS, ARGSRef => \%ARGS, Ticket => $Ticket ); -<form action="Display.html" method="post" enctype="multipart/form-data"> +<form action="Update.html" method="post" enctype="multipart/form-data"> +<input type="hidden" class="hidden" name="QuoteTransaction" value="<% $ARGS{QuoteTransaction}||'' %>" /> <input type="hidden" class="hidden" name="UpdateType" value="response" /> <input type="hidden" class="hidden" name="id" value="<%$Ticket->Id%>" /> <table width="100%"> @@ -68,21 +69,27 @@ <&|/l&>Subject</&> </td> <td class="value"> - <input name="UpdateSubject" size="60" value="<% $Ticket->Subject %>" /> + <input name="UpdateSubject" size="60" value="<% $ARGS{UpdateSubject} || $Ticket->Subject || '' %>" /> </td> </tr> <& /Ticket/Elements/AddAttachments, %ARGS, TicketObj => $Ticket &> <tr><td colspan="2"><& /Ticket/Elements/EditCustomFields, TicketObj => $Ticket &></td></tr> </table> -<& /Elements/MessageBox, - Name => "UpdateContent", - QuoteTransaction => $ARGS{QuoteTransaction} - &> +% if (exists $ARGS{UpdateContent}) { +% # preserve QuoteTransaction so we can use it to set up sane references/in/reply to +% my $temp = $ARGS{'QuoteTransaction'}; +% delete $ARGS{'QuoteTransaction'}; +<& /Elements/MessageBox, Name=>"UpdateContent", Default=>$ARGS{UpdateContent}, IncludeSignature => 0, %ARGS&> +% $ARGS{'QuoteTransaction'} = $temp; +% } else { +% my $IncludeSignature = 1; +<& /Elements/MessageBox, Name=>"UpdateContent", IncludeSignature => $IncludeSignature, %ARGS &> +% } <br /> -<& /Elements/Submit &> +<& /Elements/Submit, Label => loc('Update Ticket'), Name => 'SubmitTicket', id => 'SubmitTicket' &> </form> @@ -102,7 +109,60 @@ Abort( loc("No permission to view update ticket") ) unless ( $Ticket->CurrentUserHasRight('ReplyToTicket') or $Ticket->CurrentUserHasRight('ModifyTicket') ); -$m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%ARGS); +my @results; + +# deal with deleting uploaded attachments +foreach my $key (keys %ARGS) { + if ($key =~ m/^DeleteAttach-(.+)$/) { + delete $session{'Attachments'}{$1}; + } + $session{'Attachments'} = { %{$session{'Attachments'} || {}} }; +} + +# store the uploaded attachment in session +if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment? + my $attachment = MakeMIMEEntity( + AttachmentFieldName => 'Attach' + ); + + my $file_path = Encode::decode_utf8("$ARGS{'Attach'}"); + $session{'Attachments'} = { + %{$session{'Attachments'} || {}}, + $file_path => $attachment, + }; +} + +# delete temporary storage entry to make WebUI clean +unless (keys %{$session{'Attachments'}} and $ARGS{'UpdateAttach'}) { + delete $session{'Attachments'}; +} + +my $checks_failure; +if ( $ARGS{'SubmitTicket'} ) { + my $CFs = $Ticket->TransactionCustomFields; + my $ValidCFs = $m->comp( + '/Elements/ValidateCustomFields', + CustomFields => $CFs, + NamePrefix => "Object-RT::Transaction--CustomField-", + ARGSRef => \%ARGS + ); + unless ( $ValidCFs ) { + $checks_failure = 1; + while (my $CF = $CFs->Next) { + my $msg = $m->notes('InvalidField-' . $CF->Id) or next; + push @results, loc($CF->Name) . ': ' . $msg; + } + } +} + +my $skip_update = 0; +$m->callback( CallbackName => 'BeforeUpdate', ARGSRef => \%ARGS, skip_update => \$skip_update, + checks_failure => $checks_failure, results => \@results, TicketObj => $Ticket ); + +if ( !$checks_failure && !$skip_update && exists $ARGS{SubmitTicket} ) { + $m->callback(CallbackName => 'BeforeDisplay', Ticket => \$Ticket, ARGSRef => \%ARGS); + return $m->comp('Display.html', TicketObj => $Ticket, %ARGS); +} </%INIT> <%ARGS> ----------------------------------------------------------------------- _______________________________________________ Rt-commit mailing list Rt-commit [at] lists http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit
|