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
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
def create
@ -53,29 +44,14 @@ class WatchersController < ApplicationController
end
respond_to do |format|
format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
format.js do
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
format.js
end
end
def append
if params[:watcher].is_a?(Hash)
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
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
@users = User.active.find_all_by_id(user_ids)
end
end
@ -83,11 +59,7 @@ class WatchersController < ApplicationController
@watched.set_watcher(User.find(params[:user_id]), false) if request.post?
respond_to do |format|
format.html { redirect_to :back }
format.js do
render :update do |page|
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
end
end
format.js
end
end
@ -117,12 +89,7 @@ private
@watched.set_watcher(user, watching)
respond_to do |format|
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format.js do
render(:update) do |page|
c = watcher_css(@watched)
page << %|$$(".#{c}").each(function(el){el.innerHTML="#{escape_javascript watcher_link(@watched, user)}"});|
end
end
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} }
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
xhr :get, :new, :object_type => 'issue', :object_id => '2'
assert_response :success
assert_select_rjs :replace_html, 'ajax-modal'
assert_match /ajax-modal/, response.body
end
def test_new_for_new_record_with_id
@ -89,7 +89,7 @@ class WatchersControllerTest < ActionController::TestCase
xhr :get, :new, :project_id => 1
assert_response :success
assert_equal Project.find(1), assigns(:project)
assert_select_rjs :replace_html, 'ajax-modal'
assert_match /ajax-modal/, response.body
end
def test_new_for_new_record_with_identifier
@ -97,7 +97,7 @@ class WatchersControllerTest < ActionController::TestCase
xhr :get, :new, :project_id => 'ecookbook'
assert_response :success
assert_equal Project.find(1), assigns(:project)
assert_select_rjs :replace_html, 'ajax-modal'
assert_match /ajax-modal/, response.body
end
def test_create
@ -105,8 +105,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count') do
xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
assert_response :success
assert_select_rjs :replace_html, 'watchers'
assert_select_rjs :replace_html, 'ajax-modal'
assert_match /watchers/, response.body
assert_match /ajax-modal/, response.body
end
assert Issue.find(2).watched_by?(User.find(4))
end
@ -116,8 +116,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count', 2) do
xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
assert_response :success
assert_select_rjs :replace_html, 'watchers'
assert_select_rjs :replace_html, 'ajax-modal'
assert_match /watchers/, response.body
assert_match /ajax-modal/, response.body
end
assert Issue.find(2).watched_by?(User.find(4))
assert Issue.find(2).watched_by?(User.find(7))
@ -148,10 +148,8 @@ class WatchersControllerTest < ActionController::TestCase
assert_no_difference 'Watcher.count' do
xhr :post, :append, :watcher => {:user_ids => ['4', '7']}
assert_response :success
assert_select_rjs :insert_html, 'watchers_inputs' do
assert_select 'input[name=?][value=4]', 'issue[watcher_user_ids][]'
assert_select 'input[name=?][value=7]', 'issue[watcher_user_ids][]'
end
assert_include 'watchers_inputs', response.body
assert_include 'issue[watcher_user_ids][]', response.body
end
end
@ -160,7 +158,7 @@ class WatchersControllerTest < ActionController::TestCase
assert_difference('Watcher.count', -1) do
xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
assert_response :success
assert_select_rjs :replace_html, 'watchers'
assert_match /watchers/, response.body
end
assert !Issue.find(2).watched_by?(User.find(3))
end