@@ -0,0 +1,2 | |||||
|
1 | <% selector = ".#{watcher_css(watched)}" %> | |||
|
2 | $$("<%= selector %>").each(function(el){el.update("<%= escape_javascript watcher_link(watched, user) %>")}); |
@@ -0,0 +1,4 | |||||
|
1 | <% @users.each do |user| %> | |||
|
2 | $$("#issue_watcher_user_ids_<%= user.id %>").each(function(el){el.remove();}); | |||
|
3 | <% end %> | |||
|
4 | Element.insert('watchers_inputs', '<%= escape_javascript(watchers_checkboxes(nil, @users, true)) %>'); |
@@ -0,0 +1,2 | |||||
|
1 | Element.update('ajax-modal', '<%= escape_javascript(render(:partial => 'watchers/new', :locals => {:watched => @watched})) %>'); | |||
|
2 | Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); |
@@ -0,0 +1,1 | |||||
|
1 | Element.update('watchers', '<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); |
@@ -0,0 +1,3 | |||||
|
1 | Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'watchers/new', :locals => {:watched => @watched}) %>'); | |||
|
2 | showModal('ajax-modal', '400px'); | |||
|
3 | $('ajax-modal').addClassName('new-watcher'); |
@@ -33,15 +33,6 class WatchersController < ApplicationController | |||||
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def new |
|
35 | def new | |
36 | respond_to do |format| |
|
|||
37 | format.js do |
|
|||
38 | render :update do |page| |
|
|||
39 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
|||
40 | page << "showModal('ajax-modal', '400px');" |
|
|||
41 | page << "$('ajax-modal').addClassName('new-watcher');" |
|
|||
42 | end |
|
|||
43 | end |
|
|||
44 | end |
|
|||
45 | end |
|
36 | end | |
46 |
|
37 | |||
47 | def create |
|
38 | def create | |
@@ -53,29 +44,14 class WatchersController < ApplicationController | |||||
53 | end |
|
44 | end | |
54 | respond_to do |format| |
|
45 | respond_to do |format| | |
55 | format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} |
|
46 | format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} | |
56 |
format.js |
|
47 | format.js | |
57 | render :update do |page| |
|
|||
58 | page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched} |
|
|||
59 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
|||
60 | end |
|
|||
61 | end |
|
|||
62 | end |
|
48 | end | |
63 | end |
|
49 | end | |
64 |
|
50 | |||
65 | def append |
|
51 | def append | |
66 | if params[:watcher].is_a?(Hash) |
|
52 | if params[:watcher].is_a?(Hash) | |
67 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] |
|
53 | user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]] | |
68 | users = User.active.find_all_by_id(user_ids) |
|
54 | @users = User.active.find_all_by_id(user_ids) | |
69 | respond_to do |format| |
|
|||
70 | format.js do |
|
|||
71 | render :update do |page| |
|
|||
72 | users.each do |user| |
|
|||
73 | page << %|$$("#issue_watcher_user_ids_#{user.id}").each(function(el){el.remove();});| |
|
|||
74 | end |
|
|||
75 | page.insert_html :bottom, 'watchers_inputs', :text => watchers_checkboxes(nil, users, true) |
|
|||
76 | end |
|
|||
77 | end |
|
|||
78 | end |
|
|||
79 | end |
|
55 | end | |
80 | end |
|
56 | end | |
81 |
|
57 | |||
@@ -83,11 +59,7 class WatchersController < ApplicationController | |||||
83 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? |
|
59 | @watched.set_watcher(User.find(params[:user_id]), false) if request.post? | |
84 | respond_to do |format| |
|
60 | respond_to do |format| | |
85 | format.html { redirect_to :back } |
|
61 | format.html { redirect_to :back } | |
86 |
format.js |
|
62 | format.js | |
87 | render :update do |page| |
|
|||
88 | page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched} |
|
|||
89 | end |
|
|||
90 | end |
|
|||
91 | end |
|
63 | end | |
92 | end |
|
64 | end | |
93 |
|
65 | |||
@@ -117,12 +89,7 private | |||||
117 | @watched.set_watcher(user, watching) |
|
89 | @watched.set_watcher(user, watching) | |
118 | respond_to do |format| |
|
90 | respond_to do |format| | |
119 | format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} |
|
91 | format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}} | |
120 | format.js do |
|
92 | format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} } | |
121 | render(:update) do |page| |
|
|||
122 | c = watcher_css(@watched) |
|
|||
123 | page << %|$$(".#{c}").each(function(el){el.innerHTML="#{escape_javascript watcher_link(@watched, user)}"});| |
|
|||
124 | end |
|
|||
125 | end |
|
|||
126 | end |
|
93 | end | |
127 | end |
|
94 | end | |
128 | end |
|
95 | end |
@@ -81,7 +81,7 class WatchersControllerTest < ActionController::TestCase | |||||
81 | @request.session[:user_id] = 2 |
|
81 | @request.session[:user_id] = 2 | |
82 | xhr :get, :new, :object_type => 'issue', :object_id => '2' |
|
82 | xhr :get, :new, :object_type => 'issue', :object_id => '2' | |
83 | assert_response :success |
|
83 | assert_response :success | |
84 | assert_select_rjs :replace_html, 'ajax-modal' |
|
84 | assert_match /ajax-modal/, response.body | |
85 | end |
|
85 | end | |
86 |
|
86 | |||
87 | def test_new_for_new_record_with_id |
|
87 | def test_new_for_new_record_with_id | |
@@ -89,7 +89,7 class WatchersControllerTest < ActionController::TestCase | |||||
89 | xhr :get, :new, :project_id => 1 |
|
89 | xhr :get, :new, :project_id => 1 | |
90 | assert_response :success |
|
90 | assert_response :success | |
91 | assert_equal Project.find(1), assigns(:project) |
|
91 | assert_equal Project.find(1), assigns(:project) | |
92 | assert_select_rjs :replace_html, 'ajax-modal' |
|
92 | assert_match /ajax-modal/, response.body | |
93 | end |
|
93 | end | |
94 |
|
94 | |||
95 | def test_new_for_new_record_with_identifier |
|
95 | def test_new_for_new_record_with_identifier | |
@@ -97,7 +97,7 class WatchersControllerTest < ActionController::TestCase | |||||
97 | xhr :get, :new, :project_id => 'ecookbook' |
|
97 | xhr :get, :new, :project_id => 'ecookbook' | |
98 | assert_response :success |
|
98 | assert_response :success | |
99 | assert_equal Project.find(1), assigns(:project) |
|
99 | assert_equal Project.find(1), assigns(:project) | |
100 | assert_select_rjs :replace_html, 'ajax-modal' |
|
100 | assert_match /ajax-modal/, response.body | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_create |
|
103 | def test_create | |
@@ -105,8 +105,8 class WatchersControllerTest < ActionController::TestCase | |||||
105 | assert_difference('Watcher.count') do |
|
105 | assert_difference('Watcher.count') do | |
106 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} |
|
106 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} | |
107 | assert_response :success |
|
107 | assert_response :success | |
108 | assert_select_rjs :replace_html, 'watchers' |
|
108 | assert_match /watchers/, response.body | |
109 | assert_select_rjs :replace_html, 'ajax-modal' |
|
109 | assert_match /ajax-modal/, response.body | |
110 | end |
|
110 | end | |
111 | assert Issue.find(2).watched_by?(User.find(4)) |
|
111 | assert Issue.find(2).watched_by?(User.find(4)) | |
112 | end |
|
112 | end | |
@@ -116,8 +116,8 class WatchersControllerTest < ActionController::TestCase | |||||
116 | assert_difference('Watcher.count', 2) do |
|
116 | assert_difference('Watcher.count', 2) do | |
117 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} |
|
117 | xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']} | |
118 | assert_response :success |
|
118 | assert_response :success | |
119 | assert_select_rjs :replace_html, 'watchers' |
|
119 | assert_match /watchers/, response.body | |
120 | assert_select_rjs :replace_html, 'ajax-modal' |
|
120 | assert_match /ajax-modal/, response.body | |
121 | end |
|
121 | end | |
122 | assert Issue.find(2).watched_by?(User.find(4)) |
|
122 | assert Issue.find(2).watched_by?(User.find(4)) | |
123 | assert Issue.find(2).watched_by?(User.find(7)) |
|
123 | assert Issue.find(2).watched_by?(User.find(7)) | |
@@ -148,10 +148,8 class WatchersControllerTest < ActionController::TestCase | |||||
148 | assert_no_difference 'Watcher.count' do |
|
148 | assert_no_difference 'Watcher.count' do | |
149 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']} |
|
149 | xhr :post, :append, :watcher => {:user_ids => ['4', '7']} | |
150 | assert_response :success |
|
150 | assert_response :success | |
151 |
assert_ |
|
151 | assert_include 'watchers_inputs', response.body | |
152 |
|
|
152 | assert_include 'issue[watcher_user_ids][]', response.body | |
153 | assert_select 'input[name=?][value=7]', 'issue[watcher_user_ids][]' |
|
|||
154 | end |
|
|||
155 | end |
|
153 | end | |
156 | end |
|
154 | end | |
157 |
|
155 | |||
@@ -160,7 +158,7 class WatchersControllerTest < ActionController::TestCase | |||||
160 | assert_difference('Watcher.count', -1) do |
|
158 | assert_difference('Watcher.count', -1) do | |
161 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
|
159 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' | |
162 | assert_response :success |
|
160 | assert_response :success | |
163 | assert_select_rjs :replace_html, 'watchers' |
|
161 | assert_match /watchers/, response.body | |
164 | end |
|
162 | end | |
165 | assert !Issue.find(2).watched_by?(User.find(3)) |
|
163 | assert !Issue.find(2).watched_by?(User.find(3)) | |
166 | end |
|
164 | end |
General Comments 0
You need to be logged in to leave comments.
Login now