before_filter :authorize
def new
- @project.members << Member.new(params[:member]) if request.post?
+ members = []
+ if params[:member] && request.post?
+ attrs = params[:member].dup
+ if (user_ids = attrs.delete(:user_ids))
+ user_ids.each do |user_id|
+ members << Member.new(attrs.merge(:user_id => user_id))
+ end
+ else
+ members << Member.new(attrs)
+ end
+ @project.members << members
+ end
respond_to do |format|
format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project }
- format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'projects/settings/members'} }
+ format.js {
+ render(:update) {|page|
+ page.replace_html "tab-content-members", :partial => 'projects/settings/members'
+ members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") }
+ }
+ }
end
end
<% users = User.active.find(:all).sort - @project.users %>
<% # members sorted by role position
members = @project.members.find(:all, :include => [:role, :user]).sort %>
-
+
+<div class="splitcontentleft">
<% if members.any? %>
<table class="list">
<thead>
<tbody>
<% members.each do |member| %>
<% next if member.new_record? %>
- <tr class="<%= cycle 'odd', 'even' %>">
+ <tr id="member-<%= member.id %>" class="<%= cycle 'odd', 'even' %>">
<td><%= member.name %></td>
<td align="center">
<% if authorize_for('members', 'edit') %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
+</div>
-<% if authorize_for('members', 'new') && !users.empty? %>
+<div class="splitcontentright">
+<% if !users.empty? %>
<% remote_form_for(:member, @member, :url => {:controller => 'members', :action => 'new', :id => @project}, :method => :post) do |f| %>
- <p><label for="member_user_id"><%=l(:label_member_new)%></label><br />
- <%= f.select :user_id, users.collect{|user| [user.name, user.id]} %>
- <%= l(:label_role) %>: <%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, :selected => nil %>
+ <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><%= l(:label_role) %>: <%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, :selected => nil %>
<%= submit_tag l(:button_add) %></p>
+ </fieldset>
<% end %>
<% end %>
+</div>
a.atom { background: url(../images/feed.png) no-repeat 1px 50%; padding: 2px 0px 3px 16px; }
+/* 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 legend { font-weight: bold; }
+div#tab-content-members fieldset label { display: block; }
+div#tab-content-members fieldset div { max-height: 400px; overflow:auto; }
+
+* html div#tab-content-members fieldset div { height: 450px; }
+
/***** Flash & error messages ****/
#errorExplanation, div.flash, .nodata, .warning {
padding: 4px 4px 4px 30px;
mail_notification: false\r
login: someone\r
type: User\r
+users_008: \r
+ id: 8\r
+ created_on: 2006-07-19 19:33:19 +02:00\r
+ status: 1\r
+ last_login_on: \r
+ language: 'it'\r
+ hashed_password: 1\r
+ updated_on: 2006-07-19 19:33:19 +02:00\r
+ admin: false\r
+ mail: miscuser8@foo.bar\r
+ lastname: Misc\r
+ firstname: User\r
+ auth_source_id: \r
+ mail_notification: false\r
+ login: miscuser8\r
+ type: User\r
+users_009: \r
+ id: 9\r
+ created_on: 2006-07-19 19:33:19 +02:00\r
+ status: 1\r
+ last_login_on: \r
+ language: 'it'\r
+ hashed_password: 1\r
+ updated_on: 2006-07-19 19:33:19 +02:00\r
+ admin: false\r
+ mail: miscuser9@foo.bar\r
+ lastname: Misc\r
+ firstname: User\r
+ auth_source_id: \r
+ mail_notification: false\r
+ login: miscuser9\r
+ type: User\r
\r
\ No newline at end of file
)
end
- def test_new
+ def test_create
assert_difference 'Member.count' do
post :new, :id => 1, :member => {:role_id => 1, :user_id => 7}
end
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]}
+ end
+ assert_redirected_to '/projects/ecookbook/settings/members'
+ assert User.find(7).member_of?(Project.find(1))
+ end
+
def test_edit
assert_no_difference 'Member.count' do
post :edit, :id => 2, :member => {:role_id => 1, :user_id => 3}