[Rt-commit] rt branch, 4.2/autocomplete-back-button, created. rt-4.1.8-516-gd508642
Alex Vandiver
alexmv at bestpractical.com
Thu May 30 15:55:45 EDT 2013
The branch, 4.2/autocomplete-back-button has been created
at d5086428fa252f77687993dc442bac74674dacbe (commit)
- Log -----------------------------------------------------------------
commit b68290a80b53d2136cde4ed05c5c2daef4a5a686
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu May 30 15:22:09 2013 -0400
Always return user/group id in related autocompleters
diff --git a/share/html/Helpers/Autocomplete/Groups b/share/html/Helpers/Autocomplete/Groups
index 0446c50..462010c 100644
--- a/share/html/Helpers/Autocomplete/Groups
+++ b/share/html/Helpers/Autocomplete/Groups
@@ -83,6 +83,8 @@ foreach (split /\s*,\s*/, $exclude) {
my @suggestions;
while ( my $group = $groups->Next ) {
- push @suggestions, $group->Name;
+ my $suggestion = { id => $group->Id, label => $group->Name, value => $group->Name };
+ $m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, group => $group );
+ push @suggestions, $suggestion;
}
</%INIT>
diff --git a/share/html/Helpers/Autocomplete/Users b/share/html/Helpers/Autocomplete/Users
index aa97d45..8c30db9 100644
--- a/share/html/Helpers/Autocomplete/Users
+++ b/share/html/Helpers/Autocomplete/Users
@@ -101,7 +101,7 @@ $users->SimpleSearch( Privileged => $privileged,
my @suggestions;
while ( my $user = $users->Next ) {
- my $suggestion = { label => $user->Format, value => $user->$return };
+ my $suggestion = { id => $user->id, label => $user->Format, value => $user->$return };
$m->callback( CallbackName => "ModifySuggestion", suggestion => $suggestion, user => $user );
push @suggestions, $suggestion;
}
diff --git a/t/web/case-sensitivity.t b/t/web/case-sensitivity.t
index c8dc77c..5220bbd 100644
--- a/t/web/case-sensitivity.t
+++ b/t/web/case-sensitivity.t
@@ -22,7 +22,7 @@ $m->login;
require JSON;
is_deeply(
JSON::from_json( $m->content ),
- [{"value" => "root\@localhost","label" => "root (Enoch Root)"}]
+ [{id => 12, "value" => "root\@localhost","label" => "root (Enoch Root)"}]
);
}
commit d8c2504947c5631c5763953d35d1f3dde778fb58
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Wed May 29 18:02:25 2013 -0400
Don't store information in hidden elements where it can become stale
Storing the username in a hidden form element to submit, and then doing
the redirect server-side, opens the possibility that the hidden element
can become stale -- namely, when the browser's back button is involved.
If a user was selected from the autocomplete, then the browser backed up
to that page, the browser would helpfully remember the value in the
hidden form element. This would result in any search (but not
autocomplete) bringing the user to the previously autocompleted user.
Instead, perform the redirect client-side, which saves processing a
custom hidden form. The UserSearch element cannot be simply filled with
the chosen autocomplete value's username because this might result in a
search with more than one result -- leading to a list of matches, and
not the selected user. Jumping directly to the target page avoids this
problem.
diff --git a/share/html/Admin/Groups/index.html b/share/html/Admin/Groups/index.html
index 9e18bfb..bb5a23d 100644
--- a/share/html/Admin/Groups/index.html
+++ b/share/html/Admin/Groups/index.html
@@ -58,12 +58,10 @@
jQuery(function(){
jQuery("#autocomplete-GroupString").autocomplete({
source: RT.Config.WebPath + "/Helpers/Autocomplete/Groups",
- // Auto-submit once a group is chosen
+ // Jump directly to the page if a group is chosen
select: function( event, ui ) {
- jQuery(event.target).val(ui.item.value);
- var form = jQuery(event.target).closest('form');
- form.find('input[name=GroupOp]').val('=');
- form.submit();
+ document.location = RT.Config.WebPath + "/Admin/Groups/Modify.html?id="
+ + ui.item.id;
}
});
});
diff --git a/share/html/Admin/Users/index.html b/share/html/Admin/Users/index.html
index f43f7e8..3bd3758 100644
--- a/share/html/Admin/Users/index.html
+++ b/share/html/Admin/Users/index.html
@@ -63,12 +63,10 @@
jQuery(function(){
jQuery("#autocomplete-UserString").autocomplete({
source: RT.Config.WebPath + "/Helpers/Autocomplete/Users?return=Name",
- // Auto-submit once a user is chosen
+ // Jump directly to the page if a user is chosen
select: function( event, ui ) {
- jQuery(event.target).val(ui.item.value);
- var form = jQuery(event.target).closest('form');
- form.find('input[name=UserOp]').val('=');
- form.submit();
+ document.location = RT.Config.WebPath + "/Admin/Users/Modify.html?id="
+ + ui.item.id;
}
}).addClass("autocompletes-user");
});
diff --git a/share/html/Elements/GotoUser b/share/html/Elements/GotoUser
index 94cf526..ae31ad4 100644
--- a/share/html/Elements/GotoUser
+++ b/share/html/Elements/GotoUser
@@ -47,16 +47,14 @@
%# END BPS TAGGED BLOCK }}}
<form name="UserSearch" method="post" action="<% RT->Config->Get('WebPath') %>/User/Search.html">
<input type="text" name="UserString" value="<% $Default %>" id="autocomplete-UserString" />
-<input type="hidden" name="UserName" value="">
<script type="text/javascript">
jQuery(function(){
jQuery("#autocomplete-UserString").autocomplete({
source: RT.Config.WebPath + "/Helpers/Autocomplete/Users?return=Name",
- // Auto-submit once a user is chosen
+ // Jump directly to the page if a user is chosen
select: function( event, ui ) {
- var form = jQuery(event.target).closest('form');
- form.find('input[name=UserName]').val(ui.item.value);
- form.submit();
+ document.location = RT.Config.WebPath + "/User/Summary.html?id="
+ + ui.item.id;
}
});
});
diff --git a/share/html/User/Search.html b/share/html/User/Search.html
index 75b3aed..02befc5 100644
--- a/share/html/User/Search.html
+++ b/share/html/User/Search.html
@@ -75,16 +75,6 @@
<%INIT>
-if ($UserName) {
- my $user = RT::User->new( $session{'CurrentUser'} );
- my ($status, $msg) = $user->Load($UserName);
- if ($status) {
- RT::Interface::Web::Redirect(RT->Config->Get('WebURL')."User/Summary.html?id=".$user->Id);
- } else {
- RT->Logger->error("Unable to load $UserName: $msg");
- }
-}
-
my $exclude = [RT->Nobody->Id, RT->System->Id];
my $users = RT::Users->new($session{'CurrentUser'});
$users->SimpleSearch( Return => 'Name',
@@ -105,5 +95,4 @@ my $search_fields = join ", ", map loc($_), keys %{RT->Config->Get('UserSearchFi
</%INIT>
<%ARGS>
$UserString => undef
-$UserName => undef
</%ARGS>
commit d5086428fa252f77687993dc442bac74674dacbe
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Thu May 30 15:27:10 2013 -0400
Add autocompletes-user class to this element, as it didn't exist in 315f007
diff --git a/share/html/Elements/GotoUser b/share/html/Elements/GotoUser
index ae31ad4..df28120 100644
--- a/share/html/Elements/GotoUser
+++ b/share/html/Elements/GotoUser
@@ -56,7 +56,7 @@ jQuery(function(){
document.location = RT.Config.WebPath + "/User/Summary.html?id="
+ ui.item.id;
}
- });
+ }).addClass("autocompletes-user");
});
</script>
<input type="submit" name="UserSearch" value="<&|/l&>Search</&>" class="button" />
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list