[Rt-commit] rt branch, autocomplete-links, created. rt-3.9.7-1164-g57a6f9c

Shawn Moore sartak at bestpractical.com
Mon Jan 3 21:12:28 EST 2011


The branch, autocomplete-links has been created
        at  57a6f9ca1c7754e47fbe366ee9e72f82221b7c7d (commit)

- Log -----------------------------------------------------------------
commit 6e42aac669020037340cda9936e416d0076a10bc
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:38:02 2011 -0500

    Allow = and != relations for User autocomplete

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 74bf759..013b33e 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1689,8 +1689,8 @@ Set($OnlySearchActiveTicketsInSimpleSearch, 1);
 =item C<$UserAutocompleteFields>
 
 Specifies which fields of L<RT::User> to match against and how to match each
-field when autocompleting users.  Valid match methods are LIKE, STARTSWITH, and
-ENDSWITH.
+field when autocompleting users.  Valid match methods are LIKE, STARTSWITH,
+ENDSWITH, C<=>, and C<!=>.
 
 Not all User fields are publically accessible and hence won't work for
 autocomplete unless you override their accessibility using a local overlay or a
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index e270c75..621373d 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -94,7 +94,7 @@ $users->LimitToPrivileged() if $privileged;
 
 while (my ($name, $op) = each %fields) {
     $op = 'STARTSWITH'
-        unless $op =~ /^(?:LIKE|(?:START|END)SWITH)$/i;
+        unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
 
     $users->Limit(
         FIELD           => $name,

commit 5fdd9c4d6d564f19d21e97800ddf5cb5b1f34554
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:39:09 2011 -0500

    Add ticket autocompleting for links

diff --git a/share/html/Elements/EditLinks b/share/html/Elements/EditLinks
index 71cdfda..77641f0 100755
--- a/share/html/Elements/EditLinks
+++ b/share/html/Elements/EditLinks
@@ -131,32 +131,32 @@
 % if ($Merge) {
   <tr>
     <td class="label"><&|/l&>Merge into</&>:</td>
-    <td class="entry"><input name="<%$id%>-MergeInto" /> <i><&|/l&>(only one ticket)</&></i></td>
+    <td class="entry"><input name="<%$id%>-MergeInto" class="link_entry" /> <i><&|/l&>(only one ticket)</&></i></td>
   </tr>
 % }
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Depends on'), Relation => 'DependsOn' &>:</td>
-    <td class="entry"><input name="<%$id%>-DependsOn" /></td>
+    <td class="entry"><input name="<%$id%>-DependsOn" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Depended on by'), Relation => 'DependedOnBy' &>:</td>
-    <td class="entry"><input name="DependsOn-<%$id%>" /></td>
+    <td class="entry"><input name="DependsOn-<%$id%>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Parents'), Relation => 'Parents' &>:</td>
-    <td class="entry"><input name="<%$id%>-MemberOf" /></td>
+    <td class="entry"><input name="<%$id%>-MemberOf" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Children'), Relation => 'Children' &>:</td>
-    <td class="entry"> <input name="MemberOf-<%$id%>" /></td>
+    <td class="entry"> <input name="MemberOf-<%$id%>" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Refers to'), Relation => 'RefersTo' &>:</td>
-    <td class="entry"><input name="<%$id%>-RefersTo" /></td>
+    <td class="entry"><input name="<%$id%>-RefersTo" class="link_entry" /></td>
   </tr>
   <tr>
     <td class="label"><& ShowRelationLabel, id => $id, Label => loc('Referred to by'), Relation => 'ReferredToBy' &>:</td>
-    <td class="entry"> <input name="RefersTo-<%$id%>" /></td>
+    <td class="entry"> <input name="RefersTo-<%$id%>" class="link_entry" /></td>
   </tr>
 % $m->callback( CallbackName => 'NewLink' );
 </table>
@@ -164,6 +164,11 @@
 </tr>
 </table>
 
+<script type="text/javascript">
+    jQuery(".link_entry").autocomplete({
+        source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Tickets"
+    });
+</script>
 <%INIT>
 my $id;
 if ($Object && $Object->Id) {
diff --git a/share/html/Helpers/Autocomplete/Tickets b/share/html/Helpers/Autocomplete/Tickets
new file mode 100644
index 0000000..49c8bb6
--- /dev/null
+++ b/share/html/Helpers/Autocomplete/Tickets
@@ -0,0 +1,116 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2010 Best Practical Solutions, LLC
+%#                                          <jesse at 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
+%# 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 }}}
+<% JSON::to_json( \@suggestions ) |n %>
+% $m->abort;
+<%ARGS>
+$return => ''
+$term => undef
+$delim => undef
+$max => 10
+$exclude => ''
+</%ARGS>
+<%INIT>
+require JSON;
+
+# Only allow certain return fields
+$return = 'id'
+    unless $return =~ /^(?:id|Subject)$/;
+
+$m->abort unless defined $return
+             and defined $term
+             and length $term;
+
+# Use our delimeter if we have one
+if ( defined $delim and length $delim ) {
+    if ( $delim eq ',' ) {
+        $delim = qr/,\s*/;
+    } else {
+        $delim = qr/\Q$delim\E/;
+    }
+
+    # If the field handles multiple values, pop the last one off
+    $term = (split $delim, $term)[-1] if $term =~ $delim;
+}
+
+my $CurrentUser = $session{'CurrentUser'};
+
+# Require privileged users
+$m->abort unless $CurrentUser->Privileged;
+
+my %fields = %{ RT->Config->Get('TicketAutocompleteFields')
+                || { id => '=' } };
+
+my $tickets = RT::Tickets->new( $CurrentUser );
+$tickets->RowsPerPage( $max );
+
+while (my ($name, $op) = each %fields) {
+    $op = 'STARTSWITH'
+        unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
+
+    $tickets->Limit(
+        FIELD           => $name,
+        OPERATOR        => $op,
+        VALUE           => $term,
+        ENTRYAGGREGATOR => 'OR',
+        SUBCLAUSE       => 'autocomplete',
+    );
+}
+
+# Exclude tickets we don't want
+foreach (split /\s*,\s*/, $exclude) {
+    $tickets->Limit(FIELD => 'id', VALUE => $_, OPERATOR => '!=');
+}
+
+my @suggestions;
+
+while ( my $ticket = $tickets->Next ) {
+    my $formatted = loc("#[_1]: [_2]", $ticket->Id, $ticket->Subject);
+    push @suggestions, { label => $formatted, value => $ticket->$return };
+}
+
+</%INIT>

commit 57a6f9ca1c7754e47fbe366ee9e72f82221b7c7d
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Mon Jan 3 20:41:34 2011 -0500

    Document $TicketAutocompleteFields

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 013b33e..2700b26 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1719,6 +1719,24 @@ Default: C<< Set( $AllowUserAutocompleteForUnprivileged, 0 ) >>
 
 Set( $AllowUserAutocompleteForUnprivileged, 0 );
 
+=item C<$TicketAutocompleteFields>
+
+Specifies which fields of L<RT::Ticket> to match against and how to match each
+field when autocompleting users.  Valid match methods are LIKE, STARTSWITH,
+ENDSWITH, C<=>, and C<!=>.
+
+Not all Ticket fields are publically accessible and hence won't work for
+autocomplete unless you override their accessibility using a local overlay or a
+plugin.  Out of the box the following fields are public: id, Subject.
+
+Default: C<< Set( $TicketAutocompleteFields, { id => '=' })] ) >>
+
+=cut
+
+Set( $TicketAutocompleteFields, {
+    id => '=',
+});
+
 =item C<$DisplayTicketAfterQuickCreate>
 
 Enable this to redirect to the created ticket display page automatically

-----------------------------------------------------------------------


More information about the Rt-commit mailing list