Removes RJS from MembersController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10058 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-21 06:35:11 +00:00
parent 9c3045eeda
commit d3bfbb800c
5 changed files with 46 additions and 44 deletions

View File

@ -63,31 +63,16 @@ class MembersController < ApplicationController
end
respond_to do |format|
if members.present? && members.all? {|m| m.valid? }
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'
page << 'hideOnLoad()'
members.each {|member| page.visual_effect(:highlight, "member-#{member.id}") }
}
}
format.js { @members = members }
format.api {
@member = members.first
if @member.valid?
render :action => 'show', :status => :created, :location => membership_url(@member)
}
else
format.js {
render(:update) {|page|
errors = members.collect {|m|
m.errors.full_messages
}.flatten.uniq
page.alert(l(:notice_failed_to_save_members, :errors => errors.join(', ')))
}
}
format.api { render_validation_errors(members.first) }
render_validation_errors(@member)
end
}
end
end
@ -98,13 +83,7 @@ class MembersController < ApplicationController
saved = @member.save
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'
page << 'hideOnLoad()'
page.visual_effect(:highlight, "member-#{@member.id}")
}
}
format.js
format.api {
if saved
render_api_ok
@ -121,11 +100,7 @@ class MembersController < ApplicationController
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'
page << 'hideOnLoad()'
}
}
format.js
format.api {
if @member.destroyed?
render_api_ok
@ -140,5 +115,4 @@ class MembersController < ApplicationController
@principals = Principal.active.not_member_of(@project).like(params[:q]).all(:limit => 100)
render :layout => false
end
end

View File

@ -0,0 +1,11 @@
Element.update('tab-content-members', '<%= escape_javascript(render :partial => 'projects/settings/members') %>');
hideOnLoad();
<% if @members.present? && @members.all? {|m| m.valid? } %>
<% @members.each do |member| %>
new Effect.Highlight("member-<%= member.id %>");
<% end %>
<% else %>
<% errors = @members.collect {|m| m.errors.full_messages}.flatten.uniq.join(', ') %>
alert('<%= escape_javascript l(:notice_failed_to_save_members, :errors => errors) %>');
<% end %>

View File

@ -0,0 +1,2 @@
Element.update('tab-content-members', '<%= escape_javascript(render :partial => 'projects/settings/members') %>');
hideOnLoad();

View File

@ -0,0 +1,3 @@
Element.update('tab-content-members', '<%= escape_javascript(render :partial => 'projects/settings/members') %>');
hideOnLoad();
new Effect.Highlight("member-<%= @member.id %>");

View File

@ -51,20 +51,25 @@ class MembersControllerTest < ActionController::TestCase
def test_xhr_create
assert_difference 'Member.count', 3 do
post :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}, :format => "js"
xhr :post, :create, :project_id => 1, :membership => {:role_ids => [1], :user_ids => [7, 8, 9]}
assert_response :success
assert_template 'create'
assert_equal 'text/javascript', response.content_type
end
assert_select_rjs :replace_html, 'tab-content-members'
assert User.find(7).member_of?(Project.find(1))
assert User.find(8).member_of?(Project.find(1))
assert User.find(9).member_of?(Project.find(1))
assert_include 'tab-content-members', response.body
end
def test_xhr_create_with_failure
assert_no_difference 'Member.count' do
post :create, :project_id => 1, :membership => {:role_ids => [], :user_ids => [7, 8, 9]}, :format => "js"
xhr :post, :create, :project_id => 1, :membership => {:role_ids => [], :user_ids => [7, 8, 9]}
assert_response :success
assert_template 'create'
assert_equal 'text/javascript', response.content_type
end
assert_select '#tab-content-members', 0
assert @response.body.match(/alert/i), "Alert message not sent"
assert_match /alert/, response.body, "Alert message not sent"
end
def test_edit
@ -77,11 +82,14 @@ class MembersControllerTest < ActionController::TestCase
def test_xhr_edit
assert_no_difference 'Member.count' do
xhr :put, :update, :id => 2, :membership => {:role_ids => [1], :user_id => 3}
assert_response :success
assert_template 'update'
assert_equal 'text/javascript', response.content_type
end
assert_select_rjs :replace_html, 'tab-content-members'
member = Member.find(2)
assert_equal [1], member.role_ids
assert_equal 3, member.user_id
assert_include 'tab-content-members', response.body
end
def test_destroy
@ -95,8 +103,12 @@ class MembersControllerTest < ActionController::TestCase
def test_xhr_destroy
assert_difference 'Member.count', -1 do
xhr :delete, :destroy, :id => 2
assert_response :success
assert_template 'destroy'
assert_equal 'text/javascript', response.content_type
end
assert_select_rjs :replace_html, 'tab-content-members'
assert_nil Member.find_by_id(2)
assert_include 'tab-content-members', response.body
end
def test_autocomplete