summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/groups_controller.rb5
-rw-r--r--app/controllers/members_controller.rb5
-rw-r--r--app/controllers/projects_controller.rb1
-rw-r--r--app/helpers/groups_helper.rb15
-rw-r--r--app/helpers/members_helper.rb14
-rw-r--r--app/views/groups/_users.html.erb8
-rw-r--r--app/views/groups/autocomplete_for_user.html.erb1
-rw-r--r--app/views/groups/autocomplete_for_user.js.erb1
-rw-r--r--app/views/members/autocomplete.html.erb1
-rw-r--r--app/views/members/autocomplete.js.erb1
-rw-r--r--app/views/projects/settings/_members.html.erb10
-rw-r--r--public/javascripts/application.js2
-rw-r--r--public/stylesheets/application.css2
-rw-r--r--test/functional/groups_controller_test.rb7
-rw-r--r--test/functional/members_controller_test.rb7
-rw-r--r--test/integration/routing/groups_test.rb4
-rw-r--r--test/integration/routing/members_test.rb4
17 files changed, 58 insertions, 30 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index d0a9dad09..b2f9d6af5 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -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
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb
index 54b3a5cbe..c46b62879 100644
--- a/app/controllers/members_controller.rb
+++ b/app/controllers/members_controller.rb
@@ -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
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 054b8bb47..a3527a550 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -43,6 +43,7 @@ class ProjectsController < ApplicationController
helper :repositories
include RepositoriesHelper
include ProjectsHelper
+ helper :members
# Lists visible projects
def index
diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb
index 91cbb803f..5e6b1f7aa 100644
--- a/app/helpers/groups_helper.rb
+++ b/app/helpers/groups_helper.rb
@@ -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
diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb
index d56fc6179..eb06a3977 100644
--- a/app/helpers/members_helper.rb
+++ b/app/helpers/members_helper.rb
@@ -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
diff --git a/app/views/groups/_users.html.erb b/app/views/groups/_users.html.erb
index 8bd76e90e..a0f89d76f 100644
--- a/app/views/groups/_users.html.erb
+++ b/app/views/groups/_users.html.erb
@@ -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>
diff --git a/app/views/groups/autocomplete_for_user.html.erb b/app/views/groups/autocomplete_for_user.html.erb
deleted file mode 100644
index de1b0073a..000000000
--- a/app/views/groups/autocomplete_for_user.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= principals_check_box_tags 'user_ids[]', @users %>
diff --git a/app/views/groups/autocomplete_for_user.js.erb b/app/views/groups/autocomplete_for_user.js.erb
new file mode 100644
index 000000000..9bb569ea1
--- /dev/null
+++ b/app/views/groups/autocomplete_for_user.js.erb
@@ -0,0 +1 @@
+$('#users').html('<%= escape_javascript(render_principals_for_new_group_users(@group)) %>');
diff --git a/app/views/members/autocomplete.html.erb b/app/views/members/autocomplete.html.erb
deleted file mode 100644
index a3ae74a0b..000000000
--- a/app/views/members/autocomplete.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= principals_check_box_tags 'membership[user_ids][]', @principals %>
diff --git a/app/views/members/autocomplete.js.erb b/app/views/members/autocomplete.js.erb
new file mode 100644
index 000000000..ba98983d3
--- /dev/null
+++ b/app/views/members/autocomplete.js.erb
@@ -0,0 +1 @@
+$('#principals_for_new_member').html('<%= escape_javascript(render_principals_for_new_members(@project)) %>');
diff --git a/app/views/projects/settings/_members.html.erb b/app/views/projects/settings/_members.html.erb
index 7b2eaac87..87c8f8be3 100644
--- a/app/views/projects/settings/_members.html.erb
+++ b/app/views/projects/settings/_members.html.erb
@@ -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) %>:
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 5a0627644..90d651acb 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -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'); }
});
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 6cb5c0d6b..5e3f0ea7c 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -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;}
diff --git a/test/functional/groups_controller_test.rb b/test/functional/groups_controller_test.rb
index 03a5c4229..67edb9261 100644
--- a/test/functional/groups_controller_test.rb
+++ b/test/functional/groups_controller_test.rb
@@ -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
diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb
index 2953b630d..365a4b4bd 100644
--- a/test/functional/members_controller_test.rb
+++ b/test/functional/members_controller_test.rb
@@ -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
diff --git a/test/integration/routing/groups_test.rb b/test/integration/routing/groups_test.rb
index fe0e1ac80..96d187144 100644
--- a/test/integration/routing/groups_test.rb
+++ b/test/integration/routing/groups_test.rb
@@ -48,6 +48,10 @@ class RoutingGroupsTest < ActionController::IntegrationTest
{ :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' }
)
diff --git a/test/integration/routing/members_test.rb b/test/integration/routing/members_test.rb
index 26ba3e1db..c796eab46 100644
--- a/test/integration/routing/members_test.rb
+++ b/test/integration/routing/members_test.rb
@@ -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