Members management in project settings is now AJAXified

git-svn-id: http://redmine.rubyforge.org/svn/trunk@508 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-05-05 15:21:18 +00:00
parent a6a181c70c
commit 3eed7e622c
5 changed files with 63 additions and 55 deletions

View File

@ -21,15 +21,19 @@ class MembersController < ApplicationController
def edit
if request.post? and @member.update_attributes(params[:member])
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project
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/members'} }
end
end
end
def destroy
@member.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'members', :id => @project
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/members'} }
end
end
private

View File

@ -96,8 +96,6 @@ class ProjectsController < ApplicationController
@custom_fields = IssueCustomField.find(:all)
@issue_category ||= IssueCategory.new
@member ||= @project.members.new
@roles = Role.find(:all, :order => 'position')
@users = User.find_active(:all) - @project.users
@custom_values ||= ProjectCustomField.find(:all).collect { |x| @project.custom_values.find_by_custom_field_id(x.id) || CustomValue.new(:custom_field => x) }
end
@ -172,16 +170,16 @@ class ProjectsController < ApplicationController
# Add a new member to @project
def add_member
@member = @project.members.build(params[:member])
if request.post?
if @member.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'settings', :tab => 'members', :id => @project
if request.post? && @member.save
respond_to do |format|
format.html { redirect_to :action => 'settings', :tab => 'members', :id => @project }
format.js { render(:update) {|page| page.replace_html "tab-content-members", :partial => 'members'} }
end
else
settings
render :action => 'settings'
end
end
end
# Show members list of @project
def list_members

View File

@ -0,0 +1,43 @@
<%= error_messages_for 'member' %>
<% roles = Role.find(:all, :order => 'position') %>
<% users = User.find_active(:all) - @project.users %>
<table class="list">
<thead>
<th><%= l(:label_user) %></th>
<th><%= l(:label_role) %></th>
<th></th>
</thead>
<tbody>
<% @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position}.each do |member| %>
<% next if member.new_record? %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%= member.user.display_name %></td>
<td align="center">
<% if authorize_for('members', 'edit') %>
<% remote_form_for(:member, member, :url => {:controller => 'members', :action => 'edit', :id => member}, :method => :post) do |f| %>
<%= f.select :role_id, roles.collect{|role| [role.name, role.id]}, {}, :class => "small" %>
<%= submit_tag l(:button_change), :class => "small" %>
<% end %>
<% end %>
</td>
<td align="center">
<small><%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member},
:method => :post
}, :title => l(:button_delete),
:class => 'icon icon-del' %></small>
</td>
</tr>
</tbody>
<% end; reset_cycle %>
</table>
&nbsp;
<% if authorize_for('projects', 'add_member') && !users.empty? %>
<p><label for="member_user_id"><%=l(:label_member_new)%></label></p>
<% remote_form_for(:member, @member, :url => {:controller => 'projects', :action => 'add_member', :tab => 'members', :id => @project}, :method => :post) do |f| %>
<%= 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 %>
<%= submit_tag l(:button_add) %>
<% end %>
<% end %>

View File

@ -19,44 +19,7 @@
</div>
<div id="tab-content-members" class="tab-content" style="display:none;">
<%= error_messages_for 'member' %>
<table class="list">
<thead><th><%= l(:label_user) %></th><th><%= l(:label_role) %></th><th></th></thead>
<tbody>
<% @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position}.each do |member| %>
<% unless member.new_record? %>
<tr class="<%= cycle 'odd', 'even' %>">
<td><%= member.user.display_name %></td>
<td align="center">
<% if authorize_for('members', 'edit') %>
<% form_tag({:controller => 'members', :action => 'edit', :id => member}) do %>
<select name="member[role_id]">
<%= options_from_collection_for_select @roles, "id", "name", member.role_id %>
</select>
<%= submit_tag l(:button_change), :class => "button-small" %>
<% end %>
<% end %>
</td>
<td align="center">
<%= link_to_if_authorized l(:button_delete), {:controller => 'members', :action => 'destroy', :id => member}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
</td>
</tr>
<% end %>
</tbody>
<% end; reset_cycle %>
</table>
<% if authorize_for('projects', 'add_member') %>
<label><%=l(:label_member_new)%></label><br/>
<% form_tag({:controller => 'projects', :action => 'add_member', :tab => 'members', :id => @project}) do %>
<select name="member[user_id]">
<%= options_from_collection_for_select @users, "id", "display_name", @member.user_id %>
</select>
<select name="member[role_id]">
<%= options_from_collection_for_select @roles, "id", "name", @member.role_id %>
</select>
<%= submit_tag l(:button_add) %>
<% end %>
<% end %>
<%= render :partial => 'members' %>
</div>
<div id="tab-content-versions" class="tab-content" style="display:none;">
@ -68,8 +31,8 @@
<td><%=h version.name %></td>
<td align="center"><%= format_date(version.effective_date) %></td>
<td><%=h version.description %></td>
<td align="center"><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></td>
<td align="center"><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></td>
<td align="center"><small><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></small></td>
<td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td>
</td>
</tr>
<% end; reset_cycle %>
@ -94,7 +57,7 @@
<% end %>
</td>
<td align="center">
<%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => @category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
<small><%= link_to_if_authorized l(:button_delete), {:controller => 'issue_categories', :action => 'destroy', :id => @category}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small>
</td>
</tr>
<% end %>

View File

@ -242,7 +242,7 @@ text-decoration:none;
form {display: inline;}
blockquote {padding-left: 6px; border-left: 2px solid #ccc;}
input, select {vertical-align: middle; margin-bottom: 4px;}
input, select {vertical-align: middle; margin-top: 1px; margin-bottom: 1px;}
input.button-small {font-size: 0.8em;}
textarea.wiki-edit { width: 99.5%; }