Difference between revisions of "QuickTicket"

From Request Tracker Wiki
Jump to navigation Jump to search
(Created page with " You can quickly create a ticket using the QuickCreate-portlet (Homepage Component) on "RT-at-a-glance" home page. But you can neighter directly change the status of the new t...")
 
Line 11: Line 11:
==Add custom fields to portlet==
==Add custom fields to portlet==
To add the custom fields of the current selected queue is a bit more complicated, because the fields has to change if the user selects another queue. To prevent a new page load every time the user changes the queue you can load the fields in background using AJAX.<br />First you need a component that returns the custom fields for a queue. Create local/html/QuickTicketCustomFields.html with the following content:
To add the custom fields of the current selected queue is a bit more complicated, because the fields has to change if the user selects another queue. To prevent a new page load every time the user changes the queue you can load the fields in background using AJAX.<br />First you need a component that returns the custom fields for a queue. Create local/html/QuickTicketCustomFields.html with the following content:
<table id="result">
 
<& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
<& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &> <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
<& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>
<table id="result"></table> <%INIT>
</table>
<%INIT>
  my $Queue = $ARGS{Queue};
  my $Queue = $ARGS{Queue};
  my $QueueObj = RT::Queue->new($session{'CurrentUser'});
  my $QueueObj = RT::Queue->new($session{'CurrentUser'});
Line 23: Line 21:
  <tr>
  <tr>
  <td colspan="2">
  <td colspan="2">
     <span id="custom-fields"></span>
      
  </td>
  </td>
  </tr>
  </tr>
Line 46: Line 44:
         var postdata = {Queue: queue
         var postdata = {Queue: queue
  % while((my $key, my $value) =  each(%ARGS)) {
  % while((my $key, my $value) =  each(%ARGS)) {
% if($key ne "Queue") {
       , "<% $key %>" : "<% $value %>"
       , "<% $key %>" : "<% $value %>"
% }
  % }
  % }
         };
         };
Line 55: Line 55:
     }
     }
  </script>
  </script>
To save entered values for custom fields you have to change index.html.
To save entered values for custom fields you have to change index.html.  
Copy html/index.html to local/html/index.html and add the following lines:
Copy html/index.html to local/html/index.html and add the following lines:
  if ( $ARGS{'QuickTicket'} ) {
  if ( $ARGS{'QuickTicket'} ) {
     my $QueueObj = RT::Queue->new($session{'CurrentUser'});
     my $QueueObj = RT::Queue->new($session{'CurrentUser'});

Revision as of 04:39, 17 September 2012

You can quickly create a ticket using the QuickCreate-portlet (Homepage Component) on "RT-at-a-glance" home page. But you can neighter directly change the status of the new ticket nor add values to a custom field. Sometimes you just want to quickly create a ticket for documentation purpose. Because of that it would be helpfull to create it with status "resolved" and some values for custom fields.

Create new portlet

First create a new portlet that is called "QuickTicket":
Copy html/Elements/QuickCreate to local/html/Elements/QuickTicket
To use it on your homepage you have to change etc/RT_Config.pm. Look for $HomepageComponents and add "QuickTicket" to it; e.g.:

Set($HomepageComponents, [qw(QuickCreate QuickTicket Quicksearch MyAdminQueues MySupportQueues MyReminders RefreshHomepage Dashboards SavedSearches)]);

Now you can add your new portlet "QuickTicket" to your homepage but it is just a clone of QuickCreate.

Add status to portlet

Adding a select-box for the ticket-status, which has resolved-status preselected:

<&|/l&>Status: <& /Elements/SelectStatus, Name=>"Status", Default => "resolved" &>

Add custom fields to portlet

To add the custom fields of the current selected queue is a bit more complicated, because the fields has to change if the user selects another queue. To prevent a new page load every time the user changes the queue you can load the fields in background using AJAX.
First you need a component that returns the custom fields for a queue. Create local/html/QuickTicketCustomFields.html with the following content:

<& /Ticket/Elements/EditCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &> <& /Ticket/Elements/EditTransactionCustomFields, %ARGS, QueueObj => $QueueObj, InTable => 1 &>

<%INIT>

my $Queue = $ARGS{Queue};
my $QueueObj = RT::Queue->new($session{'CurrentUser'});
$QueueObj->Load($Queue) || Abort(loc("Queue could not be loaded."));

Now add a new row to local/html/Elements/QuickTicket to display the custom fields

and some JavaScript to load the custom fields and display them: To save entered values for custom fields you have to change index.html. Copy html/index.html to local/html/index.html and add the following lines: if ( $ARGS{'QuickTicket'} ) { my $QueueObj = RT::Queue->new($session{'CurrentUser'}); $QueueObj->Load($ARGS{Queue}) or Abort(loc("Queue could not be loaded.")); my $CFs = $QueueObj->TicketCustomFields(); my $ValidCFs = $m->comp( '/Elements/ValidateCustomFields', CustomFields => $CFs, ARGSRef => \%ARGS ); if ( $ValidCFs && !$skip_create && $ARGS{'Subject'} && $ARGS{'Requestors'}) { my ($t, $msg) = CreateTicket( From => $session{'CurrentUser'}->EmailAddress, %ARGS,); push @results, $msg; %ARGS = undef; if ( $t && $t->Id && RT->Config->Get('DisplayTicketAfterQuickCreate', $session{'CurrentUser'}) ) { MaybeRedirectForResults( Actions => \@results, Path => '/Ticket/Display.html', Arguments => { id => $t->Id }, ); } } elsif (!($ARGS{'Subject'} && $ARGS{'Requestors'})) { push @results, loc("Please set subject and requestors"); } elsif (!$ValidCFs) { push @results, loc("Please set required custom fields"); } delete $ARGS{'QuickTicket'}; #otherwise there will be a redirect loop delete $ARGS{'QuickCreate'}; MaybeRedirectForResults( Actions => \@results, Path => '/', Arguments => \%ARGS, ); }

Show entered values again

If you want previously entered values to be visible again after submitting the form with invalid data,
change line 78 of /local/html/index.html to:

<& /Elements/MyRT, %ARGS &>

Copy /html/Elements/MyRT to local/html/Elements/MyRT and change line 95 and following lines to

my %newArgs = (%{ $entry->{arguments} || {} }, %ARGS);
# XXX: security check etc.
$m->comp( $name, %newArgs );

Because of that QuickTicket is called with the arguments and previously entered values can be shown again.