diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index b6fe5e594..a0be20faf 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -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 diff --git a/app/views/watchers/_set_watcher.js.erb b/app/views/watchers/_set_watcher.js.erb new file mode 100644 index 000000000..4f2a4318b --- /dev/null +++ b/app/views/watchers/_set_watcher.js.erb @@ -0,0 +1,2 @@ +<% selector = ".#{watcher_css(watched)}" %> +$$("<%= selector %>").each(function(el){el.update("<%= escape_javascript watcher_link(watched, user) %>")}); diff --git a/app/views/watchers/append.js.erb b/app/views/watchers/append.js.erb new file mode 100644 index 000000000..b5bde1e6d --- /dev/null +++ b/app/views/watchers/append.js.erb @@ -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)) %>'); diff --git a/app/views/watchers/create.js.erb b/app/views/watchers/create.js.erb new file mode 100644 index 000000000..d18152b76 --- /dev/null +++ b/app/views/watchers/create.js.erb @@ -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})) %>'); diff --git a/app/views/watchers/destroy.js.erb b/app/views/watchers/destroy.js.erb new file mode 100644 index 000000000..4c3bb1930 --- /dev/null +++ b/app/views/watchers/destroy.js.erb @@ -0,0 +1 @@ +Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); diff --git a/app/views/watchers/new.js.erb b/app/views/watchers/new.js.erb new file mode 100644 index 000000000..c89dd1c95 --- /dev/null +++ b/app/views/watchers/new.js.erb @@ -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'); diff --git a/test/functional/watchers_controller_test.rb b/test/functional/watchers_controller_test.rb index bef8aae9b..91324edf0 100644 --- a/test/functional/watchers_controller_test.rb +++ b/test/functional/watchers_controller_test.rb @@ -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