Wikia

Request Tracker Wiki

SelectRequestor

Comments0
852pages on
this wiki

Our support staff requested a way to make it easier to enter a ticket when a customer calls in. Having to know or ask for their email address, is tedious, especially for those with long email addresses. They wanted a way to select the user from a drop down list; see also AutocompleteRequestors

I wanted them to be able to chose the organization first so as not to have one drop down with all the users in the system. So, I came up with this.

It uses javascript, so your browser must have that enabled. The page that gets built ends up having every user in your database, so this may not work well for you if you have thousands of users. I basically took the share/html/Elements/SelectOwner piece from the RT 3.8.8 release and built the file below, SelectRequestor, which should go into local/html/Elements. To change the Create Ticket page to use it, copy share/html/Ticket/Create.html to local/html/Ticket/Create.html and apply the diff below.

rtserver:~# diff -u   /usr/share/request-tracker3.8/html/Ticket/Create.html /usr/local/share/request-tracker3.8/html/Ticket/Create.html 
--- /usr/share/request-tracker3.8/html/Ticket/Create.html       2011-04-19 10:52:57.000000000 -0500
+++ /usr/local/share/request-tracker3.8/html/Ticket/Create.html 2012-03-12 11:22:45.000000000 -0500
@@ -85,7 +85,8 @@
 <&|/l&>Requestors</&>:
 </td>
 <td class="value" colspan="5">
-<& /Elements/EmailInput, Name => 'Requestors', Size => '40', Default => $ARGS{Requestors} || $session{CurrentUser}->EmailAddress &>
+<& /Elements/SelectRequestor, Name => "Requestors", QueueObj => $QueueObj, Default  => $ARGS{Requestors}||$session{CurrentUser}->EmailAddress, DefaultValue=> 0 &>
+
 </td>
 </tr>
 <tr>

Also, if you want to be able to select from unprivileged users, comment out this line in SelectRequestor (below):

$Users->WhoHaveRight(Right => 'CreateTicket', Object => $object, IncludeSystemRights => 1, IncludeSuperusers => 0);

The contents of local/html/Elements/SelectRequestor:

 %# BEGIN BPS TAGGED BLOCK {{{
     %#
     %# COPYRIGHT:
     %#
     %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
     %#                                          <jesse@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., 675 Mass Ave, Cambridge, MA 02139, USA.
     %#
     %#
     %# 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
     %# you are the copyright holder for those contributions and you grant
     %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
     %# 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 }}}
     
     <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
     
     var store = new Array();
     
     store[0] = new Array(
       "Select an Organization at left"
     );
     %my $bucket=1;
     %foreach my $org (sort { lc($a) cmp lc($b) } keys %org_hash) {
     %  my $arrayref = $org_hash{$org};
     store[<% $bucket %>] = new Array(
        "Select a user"
     %  foreach my $user (sort @{$arrayref}) {
        ,'<% $user %>'
     %  }
     );
     %  $bucket++;
     %}
     
     function populate()
     {
       var box = document.TicketCreate.org_select;
       var number = box.options[box.selectedIndex].value;
       if (!number) return;
       var list = store[number];
       document.TicketCreate.user_select.options.length = 0;
       for(i=0;i<list.length;i++)
       {
         document.TicketCreate.user_select.options[i] = new Option(list[i],i);
       }
     }
     
     function set_requestor()
     {
       document.TicketCreate.Requestors.value =
         document.TicketCreate.user_select.options[document.TicketCreate.user_select.selectedIndex].text;
     }
     
     </SCRIPT>
     
     
     
     <INPUT Name="Requestors" Value="<%$Default%>" SIZE=40>
     
     <SELECT NAME="org_select", onChange="populate()">
     <OPTION SELECTED VALUE="0">Select an Organization</OPTION>
     % $bucket = 1;
     %foreach my $org ( sort { lc($a) cmp lc($b) } keys %org_hash )  {
     <OPTION VALUE="<% $bucket %>"><% $org %></OPTION>
     % $bucket++;
     %}
     </SELECT>
     
     <SELECT NAME="user_select", onChange="set_requestor()">
     <OPTION SELECTED VALUE="0">Select an Organization at left</OPTION>
     </SELECT>
     
     
     <%INIT>
     my @objects;
     my %org_hash;
     
     if ($TicketObj) {
       @objects = ($TicketObj);
     }
     elsif ($QueueObj) {
       @objects = ($QueueObj);
     }
     elsif ($cfqueues) {
       @objects = keys %{$cfqueues};
     }
     else {
       # Let's check rights on an empty queue object. that will do a search for any queue.
       my $queue = RT::Queue->new($session{'CurrentUser'});
       push( @objects, $queue );
     }
     
     foreach my $object (@objects) {
       my $Users = RT::Users->new($session{CurrentUser});
       $Users->WhoHaveRight(Right => 'CreateTicket', Object => $object, IncludeSystemRights => 1, IncludeSuperusers => 0);
       while (my $User = $Users->Next()) {
         next if ($User->id == $RT::Nobody->id); # skip nobody here, so we can make them first later
         my $org = $User->Organization;
         if((!defined ($org)) || ($org eq "")) {
           my $i = index($User->Name, "@");
           # Note that if index returned -1, we'll start at zero, just using the entire email addr as the org
           $org = substr $User->Name, $i+1;
         }
         push @{$org_hash{$org}}, $User->EmailAddress;
       }
     }
     
     
     </%INIT>
     
     <%ARGS>
     $QueueObj => undef
     $Name => undef
     $Default => 0
     $User => undef
     $TicketObj => undef
     $DefaultValue => 1
     $DefaultLabel => "-"
     $ValueAttribute => 'id'
     $cfqueues => undef
     </%ARGS>
     


Simplified SelectRequestor Edit

This simplified version only lists users by their full name using a single drop-down list. The only difference is the template file local/html/Elements/SelectRequestor:

  %# BEGIN BPS TAGGED BLOCK {{{
  %#
  %# COPYRIGHT:
  %#
  %# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
  %#                                          <jesse@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., 675 Mass Ave, Cambridge, MA 02139, USA.
  %#
  %#
  %# 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
  %# you are the copyright holder for those contributions and you grant
  %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
  %# 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 }}}
  
  <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
  function set_requestor()
  {
   document.TicketCreate.Requestors.value =
  
  document.TicketCreate.user_select.options[document.TicketCreate.user_select.selectedIndex].value;
  }
  </SCRIPT>
  
  <INPUT Name="Requestors" Value="<%$Default%>" SIZE=40>
  <SELECT NAME="user_select", onChange="set_requestor()">
  <OPTION SELECTED VALUE="0">Select a Requestor</OPTION>
  %foreach my $user (sort { lc($a) cmp lc($b) } keys %users) {
  <OPTION VALUE="<% $users{$user} %>"><% $user %></OPTION>
  %}
  </SELECT>
  
  
  <%INIT>
  my @objects;
  my %users;
  
  if ($TicketObj) {
   @objects = ($TicketObj);
  }
  elsif ($QueueObj) {
   @objects = ($QueueObj);
  }
  elsif ($cfqueues) {
   @objects = keys %{$cfqueues};
  }
  else {
   # Let's check rights on an empty queue object. that will do a search for any queue.
   my $queue = RT::Queue->new($session{'CurrentUser'});
   push( @objects, $queue );
  }
  
  foreach my $object (@objects) {
   my $Users = RT::Users->new($session{CurrentUser});
   $Users->WhoHaveRight(Right => 'CreateTicket', Object => $object, IncludeSystemRights => 1, IncludeSuperusers => 0);
   while (my $User = $Users->Next()) {
     next if ($User->id == $RT::Nobody->id); # skip nobody here, so we can make them first later
     $users{$User->RealName} = $User->EmailAddress;
   }
  }
  
  
  </%INIT>
  
  <%ARGS>
  $QueueObj => undef
  $Name => undef
  $Default => 0
  $User => undef
  $TicketObj => undef
  $DefaultValue => 1
  $DefaultLabel => "-"
  $ValueAttribute => 'id'
  $cfqueues => undef
  </%ARGS>
  
   

Around Wikia's network

Random Wiki