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:
parent
10c96dba8b
commit
1257f1960f
|
@ -109,8 +109,9 @@ class GroupsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete_for_user
|
def autocomplete_for_user
|
||||||
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
|
respond_to do |format|
|
||||||
render :layout => false
|
format.js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit_membership
|
def edit_membership
|
||||||
|
|
|
@ -112,8 +112,9 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def autocomplete
|
def autocomplete
|
||||||
@principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
|
respond_to do |format|
|
||||||
render :layout => false
|
format.js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -43,6 +43,7 @@ class ProjectsController < ApplicationController
|
||||||
helper :repositories
|
helper :repositories
|
||||||
include RepositoriesHelper
|
include RepositoriesHelper
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
|
helper :members
|
||||||
|
|
||||||
# Lists visible projects
|
# Lists visible projects
|
||||||
def index
|
def index
|
||||||
|
|
|
@ -24,4 +24,19 @@ module GroupsHelper
|
||||||
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
|
{:name => 'memberships', :partial => 'groups/memberships', :label => :label_project_plural}
|
||||||
]
|
]
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -18,4 +18,18 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
module MembersHelper
|
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
|
end
|
||||||
|
|
|
@ -22,22 +22,18 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="splitcontentright">
|
<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),
|
<%= form_for(@group, :remote => true, :url => group_users_path(@group),
|
||||||
:html => {:method => :post}) do |f| %>
|
:html => {:method => :post}) do |f| %>
|
||||||
<fieldset><legend><%=l(:label_user_new)%></legend>
|
<fieldset><legend><%=l(:label_user_new)%></legend>
|
||||||
|
|
||||||
<p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
|
<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">
|
<div id="users">
|
||||||
<%= principals_check_box_tags 'user_ids[]', users %>
|
<%= render_principals_for_new_group_users(@group) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%= submit_tag l(:button_add) %></p>
|
<p><%= submit_tag l(:button_add) %></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
<%= principals_check_box_tags 'user_ids[]', @users %>
|
|
|
@ -0,0 +1 @@
|
||||||
|
$('#users').html('<%= escape_javascript(render_principals_for_new_group_users(@group)) %>');
|
|
@ -1 +0,0 @@
|
||||||
<%= principals_check_box_tags 'membership[user_ids][]', @principals %>
|
|
|
@ -0,0 +1 @@
|
||||||
|
$('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_new_members(@project)) %>');
|
|
@ -51,18 +51,16 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% principals = Principal.active.not_member_of(@project).all(:limit => 100, :order => 'type, login, lastname ASC') %>
|
|
||||||
|
|
||||||
<div class="splitcontentright">
|
<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| %>
|
<%= form_for(@member, {:as => :membership, :url => project_memberships_path(@project), :remote => true, :method => :post}) do |f| %>
|
||||||
<fieldset><legend><%=l(:label_member_new)%></legend>
|
<fieldset><legend><%=l(:label_member_new)%></legend>
|
||||||
|
|
||||||
<p><%= label_tag "principal_search", l(:label_principal_search) %><%= text_field_tag 'principal_search', nil %></p>
|
<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">
|
<div id="principals_for_new_member">
|
||||||
<%= principals_check_box_tags 'membership[user_ids][]', principals %>
|
<%= render_principals_for_new_members(@project) %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><%= l(:label_role_plural) %>:
|
<p><%= l(:label_role_plural) %>:
|
||||||
|
|
|
@ -481,7 +481,7 @@ function observeSearchfield(fieldId, targetId, url) {
|
||||||
url: url,
|
url: url,
|
||||||
type: 'get',
|
type: 'get',
|
||||||
data: {q: $this.val()},
|
data: {q: $this.val()},
|
||||||
success: function(data){ $('#'+targetId).html(data); },
|
success: function(data){ if(targetId) $('#'+targetId).html(data); },
|
||||||
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
beforeSend: function(){ $this.addClass('ajax-loading'); },
|
||||||
complete: function(){ $this.removeClass('ajax-loading'); }
|
complete: function(){ $this.removeClass('ajax-loading'); }
|
||||||
});
|
});
|
||||||
|
|
|
@ -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, 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 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 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 {height: 200px; overflow:auto;}
|
||||||
#users_for_watcher label {display: block;}
|
#users_for_watcher label {display: block;}
|
||||||
|
|
|
@ -195,11 +195,8 @@ class GroupsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_autocomplete_for_user
|
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
|
assert_response :success
|
||||||
users = assigns(:users)
|
assert_include 'John Smith', response.body
|
||||||
assert_not_nil users
|
|
||||||
assert users.any?
|
|
||||||
assert !users.include?(Group.find(10).users.first)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -104,11 +104,8 @@ class MembersControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_autocomplete
|
def test_autocomplete
|
||||||
get :autocomplete, :project_id => 1, :q => 'mis'
|
get :autocomplete, :project_id => 1, :q => 'mis', :format => 'js'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'autocomplete'
|
assert_include 'User Misc', response.body
|
||||||
|
|
||||||
assert_tag :label, :content => /User Misc/,
|
|
||||||
:child => { :tag => 'input', :attributes => { :name => 'membership[user_ids][]', :value => '8' } }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,6 +47,10 @@ class RoutingGroupsTest < ActionController::IntegrationTest
|
||||||
{ :method => 'get', :path => "/groups/1/autocomplete_for_user" },
|
{ :method => 'get', :path => "/groups/1/autocomplete_for_user" },
|
||||||
{ :controller => 'groups', :action => 'autocomplete_for_user', :id => '1' }
|
{ :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(
|
assert_routing(
|
||||||
{ :method => 'get', :path => "/groups/1" },
|
{ :method => 'get', :path => "/groups/1" },
|
||||||
{ :controller => 'groups', :action => 'show', :id => '1' }
|
{ :controller => 'groups', :action => 'show', :id => '1' }
|
||||||
|
|
|
@ -55,5 +55,9 @@ class RoutingMembersTest < ActionController::IntegrationTest
|
||||||
{ :method => 'get', :path => "/projects/5234/memberships/autocomplete" },
|
{ :method => 'get', :path => "/projects/5234/memberships/autocomplete" },
|
||||||
{ :controller => 'members', :action => 'autocomplete', :project_id => '5234' }
|
{ :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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue