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
This commit is contained in:
parent
b4be8849c0
commit
04e181b8b0
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue