Removes RJS from GroupsController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10044 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-19 16:57:59 +00:00
parent 035805fbd0
commit 21ee2e2cf2
6 changed files with 46 additions and 30 deletions

View File

@ -90,16 +90,11 @@ class GroupsController < ApplicationController
end end
def add_users def add_users
users = User.find_all_by_id(params[:user_id] || params[:user_ids]) @users = User.find_all_by_id(params[:user_id] || params[:user_ids])
@group.users << users if request.post? @group.users << @users if request.post?
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
format.js { format.js
render(:update) {|page|
page.replace_html "tab-content-users", :partial => 'groups/users'
users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") }
}
}
format.api { render_api_ok } format.api { render_api_ok }
end end
end end
@ -108,7 +103,7 @@ class GroupsController < ApplicationController
@group.users.delete(User.find(params[:user_id])) if request.delete? @group.users.delete(User.find(params[:user_id])) if request.delete?
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' }
format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } format.js
format.api { render_api_ok } format.api { render_api_ok }
end end
end end
@ -122,21 +117,8 @@ class GroupsController < ApplicationController
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group) @membership = Member.edit_membership(params[:membership_id], params[:membership], @group)
@membership.save if request.post? @membership.save if request.post?
respond_to do |format| respond_to do |format|
if @membership.valid?
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
format.js { format.js
render(:update) {|page|
page.replace_html "tab-content-memberships", :partial => 'groups/memberships'
page.visual_effect(:highlight, "member-#{@membership.id}")
}
}
else
format.js {
render(:update) {|page|
page.alert(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', ')))
}
}
end
end end
end end
@ -144,7 +126,7 @@ class GroupsController < ApplicationController
Member.find(params[:membership_id]).destroy if request.post? Member.find(params[:membership_id]).destroy if request.post?
respond_to do |format| respond_to do |format|
format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' } format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'memberships' }
format.js { render(:update) {|page| page.replace_html "tab-content-memberships", :partial => 'groups/memberships'} } format.js
end end
end end

View File

@ -0,0 +1,4 @@
Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>');
<% @users.each do |user| %>
new Effect.Highlight('user-<%= user.id %>');
<% end %>

View File

@ -0,0 +1 @@
Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>');

View File

@ -0,0 +1,6 @@
<% if @membership.valid? %>
Element.update('tab-content-memberships', '<%= escape_javascript(render :partial => 'groups/memberships') %>');
new Effect.Highlight('member-<%= @membership.id %>');
<% else %>
alert('<%= escape_javascript(l(:notice_failed_to_save_members, :errors => @membership.errors.full_messages.join(', '))) %>');
<% end %>

View File

@ -0,0 +1 @@
Element.update('tab-content-users', '<%= escape_javascript(render :partial => 'groups/users') %>');

View File

@ -113,8 +113,11 @@ class GroupsControllerTest < ActionController::TestCase
def test_xhr_add_users def test_xhr_add_users
assert_difference 'Group.find(10).users.count', 2 do assert_difference 'Group.find(10).users.count', 2 do
xhr :post, :add_users, :id => 10, :user_ids => ['2', '3'] xhr :post, :add_users, :id => 10, :user_ids => ['2', '3']
assert_response :success
assert_template 'add_users'
assert_equal 'text/javascript', response.content_type
end end
assert_select_rjs :replace_html, 'tab-content-users' assert_match /John Smith/, response.body
end end
def test_remove_user def test_remove_user
@ -126,8 +129,10 @@ class GroupsControllerTest < ActionController::TestCase
def test_xhr_remove_user def test_xhr_remove_user
assert_difference 'Group.find(10).users.count', -1 do assert_difference 'Group.find(10).users.count', -1 do
xhr :delete, :remove_user, :id => 10, :user_id => '8' xhr :delete, :remove_user, :id => 10, :user_id => '8'
assert_response :success
assert_template 'remove_user'
assert_equal 'text/javascript', response.content_type
end end
assert_select_rjs :replace_html, 'tab-content-users'
end end
def test_new_membership def test_new_membership
@ -139,15 +144,21 @@ class GroupsControllerTest < ActionController::TestCase
def test_xhr_new_membership def test_xhr_new_membership
assert_difference 'Group.find(10).members.count' do assert_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']} xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 2, :role_ids => ['1', '2']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end end
assert_select_rjs :replace_html, 'tab-content-memberships' assert_match /OnlineStore/, response.body
end end
def test_xhr_new_membership_with_failure def test_xhr_new_membership_with_failure
assert_no_difference 'Group.find(10).members.count' do assert_no_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']} xhr :post, :edit_membership, :id => 10, :membership => { :project_id => 999, :role_ids => ['1', '2']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end end
assert @response.body.match(/alert/i), "Alert message not sent" assert_match /alert/, response.body, "Alert message not sent"
end end
def test_edit_membership def test_edit_membership
@ -156,6 +167,15 @@ class GroupsControllerTest < ActionController::TestCase
end end
end end
def test_xhr_edit_membership
assert_no_difference 'Group.find(10).members.count' do
xhr :post, :edit_membership, :id => 10, :membership_id => 6, :membership => { :role_ids => ['1', '3']}
assert_response :success
assert_template 'edit_membership'
assert_equal 'text/javascript', response.content_type
end
end
def test_destroy_membership def test_destroy_membership
assert_difference 'Group.find(10).members.count', -1 do assert_difference 'Group.find(10).members.count', -1 do
post :destroy_membership, :id => 10, :membership_id => 6 post :destroy_membership, :id => 10, :membership_id => 6
@ -165,8 +185,10 @@ class GroupsControllerTest < ActionController::TestCase
def test_xhr_destroy_membership def test_xhr_destroy_membership
assert_difference 'Group.find(10).members.count', -1 do assert_difference 'Group.find(10).members.count', -1 do
xhr :post, :destroy_membership, :id => 10, :membership_id => 6 xhr :post, :destroy_membership, :id => 10, :membership_id => 6
assert_response :success
assert_template 'destroy_membership'
assert_equal 'text/javascript', response.content_type
end end
assert_select_rjs :replace_html, 'tab-content-memberships'
end end
def test_autocomplete_for_user def test_autocomplete_for_user