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