AutoRequestorTicketSearch

From Request Tracker Wiki
Revision as of 16:56, 9 April 2014 by Jcharaoui (talk)
Jump to navigation Jump to search

When creating tickets in RT on behalf of a user, it's often useful to look over the list of tickets in which the user is a requestor in order to avoid duplicates. Opening a tab, moving to the search page and building a new search can however be uselessly time-consuming.

With this simple customisation, upon selecting a Requestor through the autocomplete dropdown on the ticket creation page, a panel will appear on the bottom of the page listing this user's most recent tickets.

In Callbacks/AutoRequestorTicketSearch/Ticket/Create.html/AfterRequestors :


<script type="text/javascript">
  jQuery(document).ready(function(){
     jQuery('form[name=TicketCreate]').after('<div id="auto-requestor-ticket-search" style="clear:both;"></div>');
     jQuery('input#Requestors').autocomplete({
       select:function( event, ui ) {
               jQuery('#auto-requestor-ticket-search').empty().load("/Helpers/AutoRequestorTicketSearch.html?" + jQuery.param({ UserEmail: ui.item.value }));
       }
     });
   });
 </script>


In Helpers/AutoRequestorTicketSearch.html :

<&|/Widgets/TitleBox, title => "Last 25 tickets for " . $User->RealName &>
  % if ($Collection->CountAll() > 0) {
  <& /Elements/CollectionList,
      AllowSorting => 0,
      Class => 'RT::Tickets',
      Collection => $Collection,
      ShowNavigation => 0,
      ShowEmpty => 1,
      %query_args,
      &>
  % if ($Collection->CountAll() > 25) {

<form action="<%RT->Config->Get('WebPath')%>/Search/Results.html" method="get" enctype="multipart/form-data">
  <input type="hidden" name="Query" value="<%$Query%>" />
  <input type="hidden" name="Format" value="<%$query_args{Format}%>" />
  <input type="hidden" name="OrderBy" value="<%$query_args{OrderBy}%>" />
  <input type="hidden" name="Order" value="<%$query_args{Order}%>" />
  <& /Elements/Submit,
      Label => loc('Voir tous'),
      &>
  </form>

% }
  % } else {

<p><&|/l&>No tickets found.</&></p>

% }
  </&>
 <%INIT>
  my $User = RT::User->new($RT::SystemUser);
  $User->LoadByEmail($UserEmail);
  my $Query = "Requestor.EmailAddress LIKE '${UserEmail}'";
  my %query_args = (
      Format  => qq{
          '<b><a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></b>/TITLE:#',
          '<b><a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></b>/TITLE:Subject',
          '<strong>Status</strong>',
          '<strong>OwnerName</strong>',
          '<small>__LastUpdatedRelative__</small>'},
      OrderBy => 'LastUpdated',
      Order   => 'DESC',
      Rows    => 25,
  );
  my $Collection = RT::Tickets->new( $session{'CurrentUser'} );
  $Collection->FromSQL($Query);
  </%INIT>
  <%ARGS>
  $UserEmail
  </%ARGS>