Adds pagination to users list when adding project or group members (#9549).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11200 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-01-18 17:57:16 +00:00
parent 10c96dba8b
commit 1257f1960f
17 changed files with 58 additions and 30 deletions

View File

@ -109,8 +109,9 @@ class GroupsController < ApplicationController
end
def autocomplete_for_user
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
render :layout => false
respond_to do |format|
format.js
end
end
def edit_membership

View File

@ -112,8 +112,9 @@ class MembersController < ApplicationController
end
def autocomplete
@principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
render :layout => false
respond_to do |format|
format.js
end
end
private

View File

@ -43,6 +43,7 @@ class ProjectsController < ApplicationController
helper :repositories
include RepositoriesHelper
include ProjectsHelper
helper :members
# Lists visible projects
def index

View File

@ -24,4 +24,19 @@ module GroupsHelper
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
]
end
def render_principals_for_new_group_users(group)
scope = User.active.not_in_group(group).like(params[:q])
principal_count = scope.count
principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
s = content_tag('div', principals_check_box_tags('user_ids[]', principals), :id => 'principals')
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
link_to text, autocomplete_for_user_group_path(group, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
}
s + content_tag('p', links, :class => 'pagination')
end
end

View File

@ -18,4 +18,18 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module MembersHelper
def render_principals_for_new_members(project)
scope = Principal.active.not_member_of(project).like(params[:q]).order('type, login, lastname ASC')
principal_count = scope.count
principal_pages = Redmine::Pagination::Paginator.new principal_count, 100, params['page']
principals = scope.offset(principal_pages.offset).limit(principal_pages.per_page).all
s = content_tag('div', principals_check_box_tags('membership[user_ids][]', principals), :id => 'principals')
links = pagination_links_full(principal_pages, principal_count, :per_page_links => false) {|text, parameters, options|
link_to text, autocomplete_project_memberships_path(project, parameters.merge(:q => params[:q], :format => 'js')), :remote => true
}
s + content_tag('p', links, :class => 'pagination')
end
end

View File

@ -22,22 +22,18 @@
</div>
<div class="splitcontentright">
<% users = User.active.not_in_group(@group).all(:limit => 100) %>
<% if users.any? %>
<%= form_for(@group, :remote => true, :url => group_users_path(@group),
:html => {:method => :post}) do |f| %>
<fieldset><legend><%=l(:label_user_new)%></legend>
<p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
<%= javascript_tag "observeSearchfield('user_search', 'users', '#{ escape_javascript autocomplete_for_user_group_path(@group) }')" %>
<%= javascript_tag "observeSearchfield('user_search', null, '#{ escape_javascript autocomplete_for_user_group_path(@group) }')" %>
<div id="users">
<%= principals_check_box_tags 'user_ids[]', users %>
<%= render_principals_for_new_group_users(@group) %>
</div>
<p><%= submit_tag l(:button_add) %></p>
</fieldset>
<% end %>
<% end %>
</div>

View File

@ -1 +0,0 @@
<%= principals_check_box_tags 'user_ids[]', @users %>

View File

@ -0,0 +1 @@
$('#users').html('<%= escape_javascript(render_principals_for_new_group_users(@group)) %>');

View File

@ -1 +0,0 @@
<%= principals_check_box_tags 'membership[user_ids][]', @principals %>

View File

@ -0,0 +1 @@
$('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_new_members(@project)) %>');

View File

@ -51,18 +51,16 @@
<% end %>
</div>
<% principals = Principal.active.not_member_of(@project).all(:limit => 100, :order => 'type, login, lastname ASC') %>
<div class="splitcontentright">
<% if roles.any? && principals.any? %>
<% if roles.any? %>
<%= form_for(@member, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %>
<fieldset><legend><%=l(:label_member_new)%></legend>
<p><%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %></p>
<%= javascript_tag "observeSearchfield('principal_search', 'principals', '#{ escape_javascript autocomplete_project_memberships_path(@project) }')" %>
<%= javascript_tag "observeSearchfield('principal_search', null, '#{ escape_javascript autocomplete_project_memberships_path(@project, :format => 'js') }')" %>
<div id="principals">
<%= principals_check_box_tags 'membership[user_ids][]', principals %>
<div id="principals_for_new_member">
<%= render_principals_for_new_members(@project) %>
</div>
<p><%= l(:label_role_plural) %>:

View File

@ -481,7 +481,7 @@ function observeSearchfield(fieldId, targetId, url) {
url: url,
type: 'get',
data: {q: $this.val()},
success: function(data){ $('#'+targetId).html(data); },
success: function(data){ if(targetId) $('#'+targetId).html(data); },
beforeSend: function(){ $this.addClass('ajax-loading'); },
complete: function(){ $this.removeClass('ajax-loading'); }
});

View File

@ -562,7 +562,7 @@ div#tab-content-members .splitcontentright, div#tab-content-memberships .splitco
div#tab-content-members fieldset, div#tab-content-memberships fieldset, div#tab-content-users fieldset { padding:1em; margin-bottom: 1em; }
div#tab-content-members fieldset legend, div#tab-content-memberships fieldset legend, div#tab-content-users fieldset legend { font-weight: bold; }
div#tab-content-members fieldset label, div#tab-content-memberships fieldset label, div#tab-content-users fieldset label { display: block; }
div#tab-content-members fieldset div, div#tab-content-users fieldset div { max-height: 400px; overflow:auto; }
div#tab-content-members #principals, div#tab-content-users #principals { max-height: 400px; overflow:auto; }
#users_for_watcher {height: 200px; overflow:auto;}
#users_for_watcher label {display: block;}

View File

@ -195,11 +195,8 @@ class GroupsControllerTest < ActionController::TestCase
end
def test_autocomplete_for_user
get :autocomplete_for_user, :id => 10, :q => 'mis'
get :autocomplete_for_user, :id => 10, :q => 'smi', :format => 'js'
assert_response :success
users = assigns(:users)
assert_not_nil users
assert users.any?
assert !users.include?(Group.find(10).users.first)
assert_include 'John Smith', response.body
end
end

View File

@ -104,11 +104,8 @@ class MembersControllerTest < ActionController::TestCase
end
def test_autocomplete
get :autocomplete, :project_id => 1, :q => 'mis'
get :autocomplete, :project_id => 1, :q => 'mis', :format => 'js'
assert_response :success
assert_template 'autocomplete'
assert_tag :label, :content => /User Misc/,
:child => { :tag => 'input', :attributes => { :name => 'membership[user_ids][]', :value => '8' } }
assert_include 'User Misc', response.body
end
end

View File

@ -47,6 +47,10 @@ class RoutingGroupsTest < ActionController::IntegrationTest
{ :method => 'get', :path => "/groups/1/autocomplete_for_user" },
{ :controller => 'groups', :action => 'autocomplete_for_user', :id => '1' }
)
assert_routing(
{ :method => 'get', :path => "/groups/1/autocomplete_for_user.js" },
{ :controller => 'groups', :action => 'autocomplete_for_user', :id => '1', :format => 'js' }
)
assert_routing(
{ :method => 'get', :path => "/groups/1" },
{ :controller => 'groups', :action => 'show', :id => '1' }

View File

@ -55,5 +55,9 @@ class RoutingMembersTest < ActionController::IntegrationTest
{ :method => 'get', :path => "/projects/5234/memberships/autocomplete" },
{ :controller => 'members', :action => 'autocomplete', :project_id => '5234' }
)
assert_routing(
{ :method => 'get', :path => "/projects/5234/memberships/autocomplete.js" },
{ :controller => 'members', :action => 'autocomplete', :project_id => '5234', :format => 'js' }
)
end
end