keep form values when changing queue in ticket creation, #9853
[freeside.git] / rt / share / html / Ticket / Create.html
index 094b5a0..57e3bd4 100755 (executable)
@@ -1,40 +1,40 @@
 %# BEGIN BPS TAGGED BLOCK {{{
-%# 
+%#
 %# COPYRIGHT:
-%# 
-%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
-%#                                          <jesse@bestpractical.com>
-%# 
+%#
+%# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+%#                                          <sales@bestpractical.com>
+%#
 %# (Except where explicitly superseded by other copyright notices)
-%# 
-%# 
+%#
+%#
 %# LICENSE:
-%# 
+%#
 %# This work is made available to you under the terms of Version 2 of
 %# the GNU General Public License. A copy of that license should have
 %# been provided with this software, but in any event can be snarfed
 %# from www.gnu.org.
-%# 
+%#
 %# This work is distributed in the hope that it will be useful, but
 %# WITHOUT ANY WARRANTY; without even the implied warranty of
 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 %# General Public License for more details.
-%# 
+%#
 %# You should have received a copy of the GNU General Public License
 %# along with this program; if not, write to the Free Software
 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 %# 02110-1301 or visit their web page on the internet at
 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%# 
-%# 
+%#
+%#
 %# CONTRIBUTION SUBMISSION POLICY:
-%# 
+%#
 %# (The following paragraph is not intended to limit the rights granted
 %# to you to modify and distribute this software under the terms of
 %# the GNU General Public License and is only of importance to you if
 %# you choose to contribute your changes and enhancements to the
 %# community by submitting them to Best Practical Solutions, LLC.)
-%# 
+%#
 %# By intentionally submitting any modifications, corrections or
 %# derivatives to this work, or any other work intended for use with
 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
@@ -43,8 +43,9 @@
 %# royalty-free, perpetual, license to use, copy, create derivative
 %# works based on those contributions, and sublicense and distribute
 %# those contributions and any derivatives thereof.
-%# 
+%#
 %# END BPS TAGGED BLOCK }}}
+%# use Data::Dumper; warn Dumper \%ARGS; #DEBUG
 <& /Elements/Header,
     Title => $title,
     onload => "function () { hide(document.getElementById('Ticket-Create-details')) }" &>
@@ -70,7 +71,8 @@
   Name => 'Queue', 
   Default => $QueueObj->Name,
   ShowNullOption => 0,
-  OnChange => "document.getElementsByName('id')[0].value = ''; form.submit()" &>
+  ShowAllQueues => 0,
+  OnChange => "document.getElementsByName('id')[0].value = 'refresh'; form.submit()" &>
 </td>
 <td class="label"><&|/l&>Status</&>:
 </td>
@@ -90,7 +92,8 @@
 <&|/l&>Requestors</&>:
 </td>
 <td class="value" colspan="5">
-<& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
+<& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => exists($ARGS{Requestors}) ? $ARGS{Requestors} : $session{CurrentUser}->EmailAddress &>
+% $m->callback( CallbackName => 'AfterRequestors', QueueObj => $QueueObj, ARGSRef => \%ARGS );
 </td>
 </tr>
 <tr>
 <tr><td class="label"><&|/l&>Children</&></td><td><input size="10" name="MemberOf-new" value="<% $ARGS{'MemberOf-new'} || '' %>" /></td></tr>
 <tr><td class="label"><&|/l&>Refers to</&></td><td><input size="10" name="new-RefersTo" value="<% $ARGS{'new-RefersTo'} || '' %>" /></td></tr>
 <tr><td class="label"><&|/l&>Referred to by</&></td><td><input size="10" name="RefersTo-new" value="<% $ARGS{'RefersTo-new'} || '' %>" /></td></tr>
+<tr><td class="label">Customer ID</td><td><input size="10" name="new-Customer" value="<% $ARGS{'new-Customer'} || '' %>" /></td></tr>
 
 
 </table>
@@ -328,6 +332,16 @@ if ($CloneTicket) {
             @cf_values;
     }
 
+    # Pass customer links along (even though cloning of parent links
+    # in general is disabled).
+    my $customers = $CloneTicketObj->Customers;
+    my @customers;
+    while ( my $customer = $customers->Next ) {
+      my ($custnum) = $customer->Target =~ /cust_main\/(\d+)$/;
+      push @customers, $custnum if $custnum;
+    }
+    $clone->{'new-Customer'} = join(' ', @customers);
+
     for ( keys %$clone ) {
         $ARGS{$_} = $clone->{$_} if not defined $ARGS{$_};
     }
@@ -377,7 +391,8 @@ if ($ARGS{'Attach'}) {                      # attachment?
 # }}}
 
 # delete temporary storage entry to make WebUI clean
-unless (keys %{$session{'Attachments'}} and $ARGS{'id'} eq 'new') {
+unless (keys %{$session{'Attachments'}} and 
+        ($ARGS{'id'} eq 'new' or $ARGS{'id'} eq 'refresh')) {
     delete $session{'Attachments'};
 }
 
@@ -421,7 +436,18 @@ $m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create =>
 
 if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
     if ( $ValidCFs && !$checks_failure && !$skip_create ) {
+# CREATE THE TICKET.
+# For some reason it's done by a Mason component named "Display.html"
+# and the call is buried in obscure error-handling stuff.
+# This comment exists to make it more visually obvious.
+# ************************************************************
+
         $m->comp('Display.html', %ARGS);
+
+# ************************************************************
+# Execution should not continue here.  Display.html calls 
+# Redirect() which does an $m->abort.  We only get here if the 
+# code dies before then, hence "$@".
         $RT::Logger->crit("After display call; error is $@");
         $m->abort();
     }