From 3eed7e622c3856f3b2395f883b5c3bdc20a7a95d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 5 May 2007 15:21:18 +0000 Subject: [PATCH] Members management in project settings is now AJAXified git-svn-id: http://redmine.rubyforge.org/svn/trunk@508 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/members_controller.rb | 12 ++++--- app/controllers/projects_controller.rb | 16 ++++----- app/views/projects/_members.rhtml | 43 ++++++++++++++++++++++++ app/views/projects/settings.rhtml | 45 +++----------------------- public/stylesheets/application.css | 2 +- 5 files changed, 63 insertions(+), 55 deletions(-) create mode 100644 app/views/projects/_members.rhtml diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index ad9e44ff9..dfaad7fa3 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d3a71478b..a870cca2a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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,14 +170,14 @@ 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 - else - settings - render :action => 'settings' + 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 diff --git a/app/views/projects/_members.rhtml b/app/views/projects/_members.rhtml new file mode 100644 index 000000000..4283b2ef8 --- /dev/null +++ b/app/views/projects/_members.rhtml @@ -0,0 +1,43 @@ +<%= error_messages_for 'member' %> +<% roles = Role.find(:all, :order => 'position') %> +<% users = User.find_active(:all) - @project.users %> + + + + + + + + + <% @project.members.find(:all, :include => [:role, :user]).sort{|x,y| x.role.position <=> y.role.position}.each do |member| %> + <% next if member.new_record? %> + + + + + + +<% end; reset_cycle %> +
<%= l(:label_user) %><%= l(:label_role) %>
<%= member.user.display_name %> + <% 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 %> + + <%= link_to_remote l(:button_delete), { :url => {:controller => 'members', :action => 'destroy', :id => member}, + :method => :post + }, :title => l(:button_delete), + :class => 'icon icon-del' %> +
+  + +<% if authorize_for('projects', 'add_member') && !users.empty? %> +

+ <% 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 %> diff --git a/app/views/projects/settings.rhtml b/app/views/projects/settings.rhtml index aaa4e6522..69d26d299 100644 --- a/app/views/projects/settings.rhtml +++ b/app/views/projects/settings.rhtml @@ -19,44 +19,7 @@