Removes RJS from WatchersController.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10047 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-07-19 17:17:10 +00:00
parent c178aded61
commit 38060a2cf0
7 changed files with 26 additions and 49 deletions

View File

@ -33,15 +33,6 @@ class WatchersController < ApplicationController
end end
def new def new
respond_to do |format|
format.js do
render :update do |page|
page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
page << "showModal('ajax-modal', '400px');"
page << "$('ajax-modal').addClassName('new-watcher');"
end
end
end
end end
def create def create
@ -53,29 +44,14 @@ class WatchersController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
format.js do format.js
render :update do |page|
page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
end
end
end end
end end
def append def append
if params[:watcher].is_a?(Hash) if params[:watcher].is_a?(Hash)
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
users = User.active.find_all_by_id(user_ids) @users = User.active.find_all_by_id(user_ids)
respond_to do |format|
format.js do
render :update do |page|
users.each do |user|
page << %|$$("#issue_watcher_user_ids_#{user.id}").each(function(el){el.remove();});|
end
page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true)
end
end
end
end end
end end
@ -83,11 +59,7 @@ class WatchersController < ApplicationController
@watched.set_watcher(User.find(params[:user_id]), false) if request.post? @watched.set_watcher(User.find(params[:user_id]), false) if request.post?
respond_to do |format| respond_to do |format|
format.html { redirect_to :back } format.html { redirect_to :back }
format.js do format.js
render :update do |page|
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
end
end
end end
end end
@ -117,12 +89,7 @@ private
@watched.set_watcher(user, watching) @watched.set_watcher(user, watching)
respond_to do |format| respond_to do |format|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js do format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} }
render(:update) do |page|
c = watcher_css(@watched)
page << %|$$(".#{c}").each(function(el){el.innerHTML="#{escape_javascript watcher_link(@watched, user)}"});|
end
end
end end
end end
end end

View File

@ -0,0 +1,2 @@
<% selector = ".#{watcher_css(watched)}" %>
$$("<%= selector %>").each(function(el){el.update("<%= escape_javascript watcher_link(watched, user) %>")});

View File

@ -0,0 +1,4 @@
<% @users.each do |user| %>
$$("#issue_watcher_user_ids_<%= user.id %>").each(function(el){el.remove();});
<% end %>
Element.insert('watchers_inputs', '<%= escape_javascript(watchers_checkboxes(nil, @users, true)) %>');

View File

@ -0,0 +1,2 @@
Element.update('ajax-modal', '<%= escape_javascript(render(:partial => 'watchers/new', :locals => {:watched => @watched})) %>');
Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>');

View File

@ -0,0 +1 @@
Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>');

View File

@ -0,0 +1,3 @@
Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'watchers/new', :locals => {:watched => @watched}) %>');
showModal('ajax-modal', '400px');
$('ajax-modal').addClassName('new-watcher');

View File

@ -81,7 +81,7 @@ class WatchersControllerTest < ActionController::TestCase
@request.session[:user_id] = 2 @request.session[:user_id] = 2
xhr :get, :new, :object_type => 'issue', :object_id => '2' xhr :get, :new, :object_type => 'issue', :object_id => '2'
assert_response :success assert_response :success
assert_select_rjs :replace_html, 'ajax-modal' assert_match /ajax-modal/, response.body
end end
def test_new_for_new_record_with_id def test_new_for_new_record_with_id
@ -89,7 +89,7 @@ class WatchersControllerTest < ActionController::TestCase
xhr :get, :new, :project_id => 1 xhr :get, :new, :project_id => 1
assert_response :success assert_response :success
assert_equal Project.find(1), assigns(:project) assert_equal Project.find(1), assigns(:project)
assert_select_rjs :replace_html, 'ajax-modal' assert_match /ajax-modal/, response.body
end end
def test_new_for_new_record_with_identifier def test_new_for_new_record_with_identifier
@ -97,7 +97,7 @@ class WatchersControllerTest < ActionController::TestCase
xhr :get, :new, :project_id => 'ecookbook' xhr :get, :new, :project_id => 'ecookbook'
assert_response :success assert_response :success
assert_equal Project.find(1), assigns(:project) assert_equal Project.find(1), assigns(:project)
assert_select_rjs :replace_html, 'ajax-modal' assert_match /ajax-modal/, response.body
end end
def test_create def test_create
@ -105,8 +105,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count') do assert_difference('Watcher.count') do
xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
assert_response :success assert_response :success
assert_select_rjs :replace_html, 'watchers' assert_match /watchers/, response.body
assert_select_rjs :replace_html, 'ajax-modal' assert_match /ajax-modal/, response.body
end end
assert Issue.find(2).watched_by?(User.find(4)) assert Issue.find(2).watched_by?(User.find(4))
end end
@ -116,8 +116,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count', 2) do assert_difference('Watcher.count', 2) do
xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
assert_response :success assert_response :success
assert_select_rjs :replace_html, 'watchers' assert_match /watchers/, response.body
assert_select_rjs :replace_html, 'ajax-modal' assert_match /ajax-modal/, response.body
end end
assert Issue.find(2).watched_by?(User.find(4)) assert Issue.find(2).watched_by?(User.find(4))
assert Issue.find(2).watched_by?(User.find(7)) assert Issue.find(2).watched_by?(User.find(7))
@ -148,10 +148,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_no_difference 'Watcher.count' do assert_no_difference 'Watcher.count' do
xhr :post, :append, :watcher => {:user_ids => ['4', '7']} xhr :post, :append, :watcher => {:user_ids => ['4', '7']}
assert_response :success assert_response :success
assert_select_rjs :insert_html, 'watchers_inputs' do assert_include 'watchers_inputs', response.body
assert_select 'input[name=?][value=4]', 'issue[watcher_user_ids][]' assert_include 'issue[watcher_user_ids][]', response.body
assert_select 'input[name=?][value=7]', 'issue[watcher_user_ids][]'
end
end end
end end
@ -160,7 +158,7 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count', -1) do assert_difference('Watcher.count', -1) do
xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
assert_response :success assert_response :success
assert_select_rjs :replace_html, 'watchers' assert_match /watchers/, response.body
end end
assert !Issue.find(2).watched_by?(User.find(3)) assert !Issue.find(2).watched_by?(User.find(3))
end end