# 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
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
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
--- /dev/null
+<ul>
+<% @users.each do |user| -%>
+ <li><%= h user.login %><span class="informal"> (<%= h(user.name(:lastname_coma_firstname)) %>)</span></li>
+<% end -%>
+</ul>
<%= 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">
<% 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>
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|
/* 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; }
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; }
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]}
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