[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-305-g62d117f

Thomas Sibley trs at bestpractical.com
Thu Aug 12 23:27:02 EDT 2010


The branch, 3.9-trunk has been updated
       via  62d117fdb4112d1d0105894a986a2b3eea5af9e7 (commit)
       via  2500d0299a4b3058c3750d478e52c6e632b3f0c0 (commit)
       via  8137c8f8512e4d193b2545f97b2530a9cbba5132 (commit)
       via  008a976c1de1fc6946b341a913214ead169bd72b (commit)
       via  fdfa0775ce8be52e319034d2ef4783e14a99db9d (commit)
       via  700558d3c4f2448e63a7fefe742b3f7145212c84 (commit)
       via  4f2cc61d5f6bf61baf0f3caf32ea0bc8fe46ef5f (commit)
      from  cbc7b824af337d8f1b036a46beea095333ab88d2 (commit)

Summary of changes:
 etc/RT_Config.pm.in                                |   38 ++++++++++++++++-
 share/html/Helpers/Autocomplete/Users              |   27 ++++++++----
 share/html/NoAuth/js/userautocomplete.js           |   43 ++++++++++++++++++++
 .../Ticket/Elements/EditTransactionCustomFields    |    2 +-
 4 files changed, 98 insertions(+), 12 deletions(-)
 create mode 100644 share/html/NoAuth/js/userautocomplete.js

- Log -----------------------------------------------------------------
commit 4f2cc61d5f6bf61baf0f3caf32ea0bc8fe46ef5f
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 13:40:42 2010 -0400

    We don't need to filter twice, just use the new match name

diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index 9efd70e..33d931d 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -50,8 +50,7 @@
 % $m->abort;
 <%ARGS>
 $return => ''
-$term => ''
-$query => undef
+$term => undef
 </%ARGS>
 <%INIT>
 require JSON;
@@ -61,8 +60,8 @@ $return = 'EmailAddress'
     unless $return =~ /^(?:EmailAddress|Name|RealName)$/;
 
 $m->abort unless defined $return
-             and defined $query
-             and length $query;
+             and defined $term
+             and length $term;
 
 my $CurrentUser = $session{'CurrentUser'};
 
@@ -79,7 +78,7 @@ for (@fields) {
     $users->Limit(
         FIELD           => $_,
         OPERATOR        => 'LIKE',
-        VALUE           => $query,
+        VALUE           => $term,
         ENTRYAGGREGATOR => 'OR',
         SUBCLAUSE       => 'autocomplete',
     );
@@ -91,9 +90,6 @@ while ( my $user = $users->Next ) {
     next if $user->id == $RT::SystemUser->id
          or $user->id == $RT::Nobody->id;
 
-    # we need to filter by ourselves to use jqueryui's autocomplete
-    next unless $user->$return =~ /$term/i;
-
     my $formatted = $m->scomp('/Elements/ShowUser', User => $user);
     $formatted =~ s/\n//g;
     push @suggestions, { label => $formatted, value => $user->$return };

commit 700558d3c4f2448e63a7fefe742b3f7145212c84
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 13:52:36 2010 -0400

    Doc the config options for user autocomplete and set defaults

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 11699e1..812363f 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1569,6 +1569,29 @@ Use this to set the default units for time entry to hours instead of minutes.
 
 Set($DefaultTimeUnitsToHours, 0);
 
+=item C<$UserAutocompleteFields>
+
+Specifies which fields of L<RT::User> to match against when autocompleting
+users.
+
+Default: C<< Set( $UserAutocompleteFields, [qw(EmailAddress Name RealName)] ) >>
+
+=cut
+
+Set( $UserAutocompleteFields, [qw(EmailAddress Name RealName)] );
+
+=item C<$AllowUserAutocompleteForUnprivileged>
+
+Should unprivileged users be allowed to autocomplete users.  Setting this
+option to a true value means unprivileged users will be able to search all your
+users.
+
+Default: C<< Set( $AllowUserAutocompleteForUnprivileged, 0 ) >>
+
+=cut
+
+Set( $AllowUserAutocompleteForUnprivileged, 0 );
+
 =back
 
 =head1 L<Net::Server> (rt-server) Configuration
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index 33d931d..c531a1c 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -67,7 +67,7 @@ my $CurrentUser = $session{'CurrentUser'};
 
 # Require privileged users or overriding config
 $m->abort unless $CurrentUser->Privileged
-              or RT->Config->Get('AllowUnprivilegedUserAutocomplete');
+              or RT->Config->Get('AllowUserAutocompleteForUnprivileged');
 
 my @fields = @{ RT->Config->Get('UserAutocompleteFields')
                 || [qw(EmailAddress Name RealName)] };

commit fdfa0775ce8be52e319034d2ef4783e14a99db9d
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 14:37:47 2010 -0400

    Support delimiters for user autocomplete
    
    It's sad that the jQuery UI autocompleter doesn't have delimiter
    support.

diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index c531a1c..bc11c5d 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -51,6 +51,7 @@
 <%ARGS>
 $return => ''
 $term => undef
+$delim => undef
 </%ARGS>
 <%INIT>
 require JSON;
@@ -63,6 +64,18 @@ $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 or overriding config

commit 008a976c1de1fc6946b341a913214ead169bd72b
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 14:46:19 2010 -0400

    Automatically attach autocomplete to all user fields

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 812363f..feda98e 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1851,11 +1851,19 @@ a list of js files to be included in head
 
 Example:
 
-Set(@JSFilesInHead, qw/jquery-1.4.2.min.js jquery_noconflict.js jquery-ui-1.8.4.custom.min.js ui.timepickr.js titlebox-state.js util.js/);
+Set(@JSFilesInHead, qw/jquery-1.4.2.min.js jquery_noconflict.js jquery-ui-1.8.4.custom.min.js ui.timepickr.js titlebox-state.js util.js userautocomplete.js/);
 
 =cut
 
-Set(@JSFilesInHead, qw/jquery-1.4.2.min.js jquery_noconflict.js jquery-ui-1.8.4.custom.min.js ui.timepickr.js titlebox-state.js util.js/);
+Set(@JSFilesInHead, qw/
+    jquery-1.4.2.min.js
+    jquery_noconflict.js
+    jquery-ui-1.8.4.custom.min.js
+    ui.timepickr.js
+    titlebox-state.js
+    util.js
+    userautocomplete.js
+/);
 
 =item C<$JSMinPath>
 
diff --git a/share/html/NoAuth/js/userautocomplete.js b/share/html/NoAuth/js/userautocomplete.js
new file mode 100644
index 0000000..6d57fac
--- /dev/null
+++ b/share/html/NoAuth/js/userautocomplete.js
@@ -0,0 +1,44 @@
+jQuery(function() {
+    // inputs that accept multiple email addresses
+    var multipleCompletion = new Array("Requestors", "To", "Bcc", "Cc", "AdminCc", "WatcherAddressEmail[123]", "UpdateCc", "UpdateBcc");
+
+    // inputs with only a single email address allowed
+    var singleCompletion   = new Array("(Add|Delete)Requestor", "(Add|Delete)Cc", "(Add|Delete)AdminCc");
+
+    // build up the regexps we'll use to match
+    var applyto  = new RegExp('^(' + multipleCompletion.concat(singleCompletion).join('|') + ')$');
+    var acceptsMultiple = new RegExp('^(' + multipleCompletion.join('|') + ')$');
+
+    var inputs = document.getElementsByTagName("input");
+
+    for (var i = 0; i < inputs.length; i++) {
+        var input = inputs[i];
+        var inputName = input.getAttribute("name");
+
+        if (!inputName || !inputName.match(applyto))
+            continue;
+
+        var options = {
+            source: "<% RT->Config->Get('WebPath')%>/Helpers/Autocomplete/Users"
+        };
+
+        if (inputName.match(acceptsMultiple)) {
+            options.source = options.source . "?delim=,";
+
+            options.focus = function () {
+                // prevent value inserted on focus
+                return false;
+            }
+
+            options.select = function(event, ui) {
+                var terms = this.value.split(/,\s*/);
+                terms.pop();                    // remove current input
+                terms.push( ui.item.value );    // add selected item
+                this.value = terms.join(", ");
+                return false;
+            }
+        }
+
+        jQuery(input).autocomplete(options);
+    }
+});

commit 8137c8f8512e4d193b2545f97b2530a9cbba5132
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 14:49:02 2010 -0400

    Fix an extra closing </td>

diff --git a/share/html/Ticket/Elements/EditTransactionCustomFields b/share/html/Ticket/Elements/EditTransactionCustomFields
index 97f7aef..44e4b05 100644
--- a/share/html/Ticket/Elements/EditTransactionCustomFields
+++ b/share/html/Ticket/Elements/EditTransactionCustomFields
@@ -60,7 +60,7 @@
     NamePrefix => $NamePrefix
 &>
 </td>
-</td></tr>
+</tr>
 % }
 % }
 % $m->callback( CallbackName => 'AfterTransactionCustomFields', TicketObj => $TicketObj, QueueObj => $QueueObj, NamePrefix => $NamePrefix );

commit 2500d0299a4b3058c3750d478e52c6e632b3f0c0
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 14:56:16 2010 -0400

    Javascript is not Perl (fix a syntax error)

diff --git a/share/html/NoAuth/js/userautocomplete.js b/share/html/NoAuth/js/userautocomplete.js
index 6d57fac..b296d0c 100644
--- a/share/html/NoAuth/js/userautocomplete.js
+++ b/share/html/NoAuth/js/userautocomplete.js
@@ -23,7 +23,7 @@ jQuery(function() {
         };
 
         if (inputName.match(acceptsMultiple)) {
-            options.source = options.source . "?delim=,";
+            options.source = options.source + "?delim=,";
 
             options.focus = function () {
                 // prevent value inserted on focus
@@ -38,7 +38,6 @@ jQuery(function() {
                 return false;
             }
         }
-
         jQuery(input).autocomplete(options);
     }
 });

commit 62d117fdb4112d1d0105894a986a2b3eea5af9e7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Thu Aug 12 15:56:58 2010 -0400

    Make a note about publically accessible User fields

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index feda98e..d67fd4c 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -1572,7 +1572,10 @@ Set($DefaultTimeUnitsToHours, 0);
 =item C<$UserAutocompleteFields>
 
 Specifies which fields of L<RT::User> to match against when autocompleting
-users.
+users.  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
+plugin.  Out of the box the following fields are public: Name, EmailAddress,
+RealName, NickName, and Organization.
 
 Default: C<< Set( $UserAutocompleteFields, [qw(EmailAddress Name RealName)] ) >>
 

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


More information about the Rt-commit mailing list