Difference between revisions of "AutoRequestorTicketSearch"

From Request Tracker Wiki
Jump to navigation Jump to search
Line 5: Line 5:
 
In '''Callbacks/AutoRequestorTicketSearch/Ticket/Create.html/AfterRequestors''' :
 
In '''Callbacks/AutoRequestorTicketSearch/Ticket/Create.html/AfterRequestors''' :
 
  <nowiki><script type="text/javascript">
 
  <nowiki><script type="text/javascript">
  jQuery(document).ready(function(){
+
    jQuery(document).ready(function(){
      jQuery('form[name=TicketCreate]').after('<div id="auto-requestor-ticket-search" style="clear:both;"></div>');
+
      jQuery('form[name=TicketCreate]').after('<div id="auto-requestor-ticket-search" style="clear:both;"></div>');
      jQuery('input#Requestors').autocomplete({
+
      jQuery('input#Requestors').autocomplete({
        select:function( event, ui ) {
+
        select:function( event, ui ) {
                jQuery('#auto-requestor-ticket-search').empty().load("/Helpers/AutoRequestorTicketSearch.html?" + jQuery.param({ UserEmail: ui.item.value }));
+
                jQuery('#auto-requestor-ticket-search').empty().load("/Helpers/AutoRequestorTicketSearch.html?" + jQuery.param({ UserEmail: ui.item.value }));
        }
+
        }
      });
+
      });
    });
+
    });
</script></nowiki>
+
  </script></nowiki>
  
 
In '''Helpers/AutoRequestorTicketSearch.html''' :
 
In '''Helpers/AutoRequestorTicketSearch.html''' :
  <nowiki><&|/Widgets/TitleBox, title => "Last 25 tickets for " . $User->RealName &>
+
  <code><&|/Widgets/TitleBox, title => "Last 25 tickets for " . $User->RealName &>
  % if ($Collection->CountAll() > 0) {
+
% if ($Collection->CountAll() > 0) {
  <& /Elements/CollectionList,
+
<& /Elements/CollectionList,
      AllowSorting => 0,
+
    AllowSorting => 0,
      Class => 'RT::Tickets',
+
    Class => 'RT::Tickets',
      Collection => $Collection,
+
    Collection => $Collection,
      ShowNavigation => 0,
+
    ShowNavigation => 0,
      ShowEmpty => 1,
+
    ShowEmpty => 1,
      %query_args,
+
    %query_args,
      &>
+
    &>
  % if ($Collection->CountAll() > 25) {
+
% if ($Collection->CountAll() > 25) {
  <form action="<%RT->Config->Get('WebPath')%>/Search/Results.html" method="get" enctype="multipart/form-data">
+
<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="Query" value="<%$Query%>" />
  <input type="hidden" name="Format" value="<%$query_args{Format}%>" />
+
<input type="hidden" name="Format" value="<%$query_args{Format}%>" />
  <input type="hidden" name="OrderBy" value="<%$query_args{OrderBy}%>" />
+
<input type="hidden" name="OrderBy" value="<%$query_args{OrderBy}%>" />
  <input type="hidden" name="Order" value="<%$query_args{Order}%>" />
+
<input type="hidden" name="Order" value="<%$query_args{Order}%>" />
  <& /Elements/Submit,
+
<& /Elements/Submit,
      Label => loc('Voir tous'),
+
    Label => loc('Voir tous'),
      &>
+
    &>
  </form>
+
</form>
  % }
+
% }
  % } else {
+
% } else {
  <p><&|/l&>No tickets found.</&></p>
+
<nowiki><p><&|/l&>No tickets found.</&></p></nowiki>
  % }
+
% }
  </&>
+
</&>
  <%INIT>
+
<%INIT>
  my $User = RT::User->new($RT::SystemUser);
+
my $User = RT::User->new($RT::SystemUser);
  $User->LoadByEmail($UserEmail);
+
$User->LoadByEmail($UserEmail);
  my $Query = "Requestor.EmailAddress LIKE '${UserEmail}'";
+
my $Query = "Requestor.EmailAddress LIKE '${UserEmail}'";
  my %query_args = (
+
my %query_args = (
      Format  => qq{
+
    Format  => qq{
          '<b><a href="__WebPath__/Ticket/Display.html?id=__id__">__id__</a></b>/TITLE:#',
+
        '<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',
+
        '<b><a href="__WebPath__/Ticket/Display.html?id=__id__">__Subject__</a></b>/TITLE:Subject',
          '__Status__',
+
        '__Status__',
          '__OwnerName__',
+
        '__OwnerName__',
          '<small>__LastUpdatedRelative__</small>'},
+
        '<small>__LastUpdatedRelative__</small>'},
      OrderBy => 'LastUpdated',
+
    OrderBy => 'LastUpdated',
      Order  => 'DESC',
+
    Order  => 'DESC',
      Rows    => 25,
+
    Rows    => 25,
  );
+
);
  my $Collection = RT::Tickets->new( $session{'CurrentUser'} );
+
my $Collection = RT::Tickets->new( $session{'CurrentUser'} );
  $Collection->FromSQL($Query);
+
$Collection->FromSQL($Query);
  </%INIT>
+
</%INIT>
  <%ARGS>
+
<%ARGS>
  $UserEmail
+
$UserEmail
  </%ARGS></nowiki>
+
</%ARGS></code>

Revision as of 16:59, 9 April 2014

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) {





<& /Elements/Submit,
    Label => loc('Voir tous'),
    &>

% }

% } 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{
        '__id__/TITLE:#',
        '__Subject__/TITLE:Subject',
        'Status',
        'OwnerName',
        '__LastUpdatedRelative__'},
    OrderBy => 'LastUpdated',
    Order   => 'DESC',
    Rows    => 25,
);
my $Collection = RT::Tickets->new( $session{'CurrentUser'} );
$Collection->FromSQL($Query);
</%INIT>
<%ARGS>
$UserEmail
</%ARGS>