diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-03-28 12:07:05 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-03-28 12:07:05 +0000 |
commit | 04e181b8b05d00a95d49aea0435f8542914b0fbc (patch) | |
tree | ebd9c00a13a4655b33df9a0d94bbae0272116954 | |
parent | b4be8849c0de81841c458c0f059787a9cc9bc022 (diff) | |
download | redmine-04e181b8b05d00a95d49aea0435f8542914b0fbc.tar.gz redmine-04e181b8b05d00a95d49aea0435f8542914b0fbc.zip |
Adds a user search field with autocompleter on project members screen.
User selection with checkboxes is disabled if there are more than 300 users available (#2993).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2638 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/members_controller.rb | 11 | ||||
-rw-r--r-- | app/models/member.rb | 10 | ||||
-rw-r--r-- | app/views/members/autocomplete_for_member_login.rhtml | 5 | ||||
-rw-r--r-- | app/views/projects/settings/_members.rhtml | 25 | ||||
-rw-r--r-- | lib/redmine.rb | 2 | ||||
-rw-r--r-- | public/stylesheets/application.css | 32 | ||||
-rw-r--r-- | test/functional/members_controller_test.rb | 16 |
7 files changed, 88 insertions, 13 deletions
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index fcc65ba0f..e2bc9257f 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -16,8 +16,8 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class MembersController < ApplicationController - before_filter :find_member, :except => :new - before_filter :find_project, :only => :new + before_filter :find_member, :except => [:new, :autocomplete_for_member_login] + before_filter :find_project, :only => [:new, :autocomplete_for_member_login] before_filter :authorize def new @@ -60,6 +60,13 @@ class MembersController < ApplicationController format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} } end end + + def autocomplete_for_member_login + @users = User.active.find(:all, :conditions => ["LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ?", "#{params[:user]}%", "#{params[:user]}%", "#{params[:user]}%"], + :limit => 10, + :order => 'login ASC') - @project.users + render :layout => false + end private def find_project diff --git a/app/models/member.rb b/app/models/member.rb index 0f644dbe7..5228d1ffc 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -31,6 +31,16 @@ class Member < ActiveRecord::Base self.user.name end + # Sets user by login + def user_login=(login) + login = login.to_s + unless login.blank? + if (u = User.find_by_login(login)) + self.user = u + end + end + end + def <=>(member) role == member.role ? (user <=> member.user) : (role <=> member.role) end diff --git a/app/views/members/autocomplete_for_member_login.rhtml b/app/views/members/autocomplete_for_member_login.rhtml new file mode 100644 index 000000000..09a08bf95 --- /dev/null +++ b/app/views/members/autocomplete_for_member_login.rhtml @@ -0,0 +1,5 @@ +<ul> +<% @users.each do |user| -%> + <li><%= h user.login %><span class="informal"> (<%= h(user.name(:lastname_coma_firstname)) %>)</span></li> +<% end -%> +</ul> diff --git a/app/views/projects/settings/_members.rhtml b/app/views/projects/settings/_members.rhtml index f70cef5a8..312403993 100644 --- a/app/views/projects/settings/_members.rhtml +++ b/app/views/projects/settings/_members.rhtml @@ -1,7 +1,5 @@ <%= error_messages_for 'member' %> -<% roles = Role.find_all_givable %> -<% users = User.active.find(:all).sort - @project.users %> -<% # members sorted by role position +<% roles = Role.find_all_givable members = @project.members.find(:all, :include => [:role, :user]).sort %> <div class="splitcontentleft"> @@ -42,15 +40,24 @@ <% end %> </div> + +<% users_count = User.active.count - @project.users.count + users = (users_count < 300) ? User.active.find(:all, :limit => 200).sort - @project.users : [] %> + <div class="splitcontentright"> -<% if !users.empty? %> +<% if roles.any? && users_count > 0 %> <% remote_form_for(:member, @member, :url => {:controller => 'members', :action => 'new', :id => @project}, :method => :post) do |f| %> <fieldset><legend><%=l(:label_member_new)%></legend> - <div> - <% users.each do |user| -%> - <label><%= check_box_tag 'member[user_ids][]', user.id, false %> <%= user %></label> - <% end -%> - </div> + <p><%= text_field_tag 'member[user_login]', nil, :size => "40" %></p> + <div id="member_user_login_choices" class="autocomplete">sqd</div> + <%= javascript_tag "new Ajax.Autocompleter('member_user_login', 'member_user_login_choices', '#{ url_for(:controller => 'members', :action => 'autocomplete_for_member_login', :id => @project) }', { minChars: 1, frequency: 0.5, paramName: 'user' });" %> + <% unless users.empty? %> + <div> + <% users.each do |user| -%> + <label><%= check_box_tag 'member[user_ids][]', user.id, false %> <%= user %></label> + <% end -%> + </div> + <% end %> <p><%= l(:label_role) %>: <%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, :selected => nil %> <%= submit_tag l(:button_add) %></p> </fieldset> diff --git a/lib/redmine.rb b/lib/redmine.rb index c8d64b8c3..5ac32b2fe 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -22,7 +22,7 @@ Redmine::AccessControl.map do |map| map.permission :search_project, {:search => :index}, :public => true map.permission :edit_project, {:projects => [:settings, :edit]}, :require => :member map.permission :select_project_modules, {:projects => :modules}, :require => :member - map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy]}, :require => :member + map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member_login]}, :require => :member map.permission :manage_versions, {:projects => [:settings, :add_version], :versions => [:edit, :destroy]}, :require => :member map.project_module :issue_tracking do |map| diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index f156b5fc4..a8d8736fd 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -327,7 +327,7 @@ a.atom { background: url(../images/feed.png) no-repeat 1px 50%; padding: 2px 0px /* Project members tab */ div#tab-content-members .splitcontentleft { width: 64% } div#tab-content-members .splitcontentright { width: 34% } -div#tab-content-members fieldset { margin-top: -8px; padding-top:0.6em; margin-bottom: 1em; } +div#tab-content-members fieldset { padding:1em; margin-bottom: 1em; } div#tab-content-members fieldset legend { font-weight: bold; } div#tab-content-members fieldset label { display: block; } div#tab-content-members fieldset div { max-height: 400px; overflow:auto; } @@ -486,6 +486,36 @@ border-bottom: 1px solid #fff; background-color: #fff; } +/***** Auto-complete *****/ +div.autocomplete { + position:absolute; + width:250px; + background-color:white; + margin:0; + padding:0; +} +div.autocomplete ul { + list-style-type:none; + margin:0; + padding:0; +} +div.autocomplete ul li.selected { background-color: #ffb;} +div.autocomplete ul li { + list-style-type:none; + display:block; + margin:0; + padding:2px; + cursor:pointer; + font-size: 90%; + border-bottom: 1px solid #ccc; + border-left: 1px solid #ccc; + border-right: 1px solid #ccc; +} +div.autocomplete ul li span.informal { + font-size: 80%; + color: #aaa; +} + /***** Diff *****/ .diff_out { background: #fcc; } .diff_in { background: #cfc; } diff --git a/test/functional/members_controller_test.rb b/test/functional/members_controller_test.rb index be3e6d1cf..efd28a414 100644 --- a/test/functional/members_controller_test.rb +++ b/test/functional/members_controller_test.rb @@ -48,6 +48,14 @@ class MembersControllerTest < Test::Unit::TestCase assert User.find(7).member_of?(Project.find(1)) end + def test_create_by_user_login + assert_difference 'Member.count' do + post :new, :id => 1, :member => {:role_id => 1, :user_login => 'someone'} + end + assert_redirected_to '/projects/ecookbook/settings/members' + assert User.find(7).member_of?(Project.find(1)) + end + def test_create_multiple assert_difference 'Member.count', 3 do post :new, :id => 1, :member => {:role_id => 1, :user_ids => [7, 8, 9]} @@ -70,4 +78,12 @@ class MembersControllerTest < Test::Unit::TestCase assert_redirected_to '/projects/ecookbook/settings/members' assert !User.find(3).member_of?(Project.find(1)) end + + def test_autocomplete_for_member_login + get :autocomplete_for_member_login, :id => 1, :user => 'mis' + assert_response :success + assert_template 'autocomplete_for_member_login' + + assert_tag :ul, :child => {:tag => 'li', :content => /miscuser8/} + end end |