@@ -0,0 +1,9 | |||||
|
1 | <div class="contextual"> | |||
|
2 | <%= link_to_if_authorized(l(:button_update), {:controller => 'issues', :action => 'edit', :id => @issue }, :onclick => 'showAndScrollTo("update", "notes"); return false;', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %> | |||
|
3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time-add' %> | |||
|
4 | <% replace_watcher ||= 'watcher' %> | |||
|
5 | <%= watcher_tag(@issue, User.current, {:id => replace_watcher, :replace => ['watcher','watcher2']}) %> | |||
|
6 | <%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %> | |||
|
7 | <%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %> | |||
|
8 | <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> | |||
|
9 | </div> |
@@ -72,9 +72,24 private | |||||
72 |
|
72 | |||
73 | def set_watcher(user, watching) |
|
73 | def set_watcher(user, watching) | |
74 | @watched.set_watcher(user, watching) |
|
74 | @watched.set_watcher(user, watching) | |
|
75 | if params[:replace].present? | |||
|
76 | if params[:replace].is_a? Array | |||
|
77 | replace_ids = params[:replace] | |||
|
78 | else | |||
|
79 | replace_ids = [params[:replace]] | |||
|
80 | end | |||
|
81 | else | |||
|
82 | replace_ids = 'watcher' | |||
|
83 | end | |||
75 | respond_to do |format| |
|
84 | respond_to do |format| | |
76 | format.html { redirect_to :back } |
|
85 | format.html { redirect_to :back } | |
77 | format.js { render(:update) {|page| page.replace_html 'watcher', watcher_link(@watched, user)} } |
|
86 | format.js do | |
|
87 | render(:update) do |page| | |||
|
88 | replace_ids.each do |replace_id| | |||
|
89 | page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) | |||
|
90 | end | |||
|
91 | end | |||
|
92 | end | |||
78 | end |
|
93 | end | |
79 | rescue ::ActionController::RedirectBackError |
|
94 | rescue ::ActionController::RedirectBackError | |
80 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
|
95 | render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true |
@@ -16,17 +16,28 | |||||
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module WatchersHelper |
|
18 | module WatchersHelper | |
19 | def watcher_tag(object, user) |
|
19 | ||
20 | content_tag("span", watcher_link(object, user), :id => 'watcher') |
|
20 | # Valid options | |
|
21 | # * :id - the element id | |||
|
22 | # * :replace - a string or array of element ids that will be | |||
|
23 | # replaced | |||
|
24 | def watcher_tag(object, user, options={:replace => 'watcher'}) | |||
|
25 | id = options[:id] | |||
|
26 | id ||= options[:replace] if options[:replace].is_a? String | |||
|
27 | content_tag("span", watcher_link(object, user, options), :id => id) | |||
21 | end |
|
28 | end | |
22 |
|
29 | |||
23 | def watcher_link(object, user) |
|
30 | # Valid options | |
|
31 | # * :replace - a string or array of element ids that will be | |||
|
32 | # replaced | |||
|
33 | def watcher_link(object, user, options={:replace => 'watcher'}) | |||
24 | return '' unless user && user.logged? && object.respond_to?('watched_by?') |
|
34 | return '' unless user && user.logged? && object.respond_to?('watched_by?') | |
25 | watched = object.watched_by?(user) |
|
35 | watched = object.watched_by?(user) | |
26 | url = {:controller => 'watchers', |
|
36 | url = {:controller => 'watchers', | |
27 | :action => (watched ? 'unwatch' : 'watch'), |
|
37 | :action => (watched ? 'unwatch' : 'watch'), | |
28 | :object_type => object.class.to_s.underscore, |
|
38 | :object_type => object.class.to_s.underscore, | |
29 |
:object_id => object.id |
|
39 | :object_id => object.id, | |
|
40 | :replace => options[:replace]} | |||
30 | link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), |
|
41 | link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), | |
31 | {:url => url}, |
|
42 | {:url => url}, | |
32 | :href => url_for(url), |
|
43 | :href => url_for(url), |
@@ -1,11 +1,4 | |||||
1 | <div class="contextual"> |
|
1 | <%= render :partial => 'action_menu' %> | |
2 | <%= link_to_if_authorized(l(:button_update), {:controller => 'issues', :action => 'edit', :id => @issue }, :onclick => 'showAndScrollTo("update", "notes"); return false;', :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %> |
|
|||
3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'edit', :issue_id => @issue}, :class => 'icon icon-time-add' %> |
|
|||
4 | <%= watcher_tag(@issue, User.current) %> |
|
|||
5 | <%= link_to_if_authorized l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-copy' %> |
|
|||
6 | <%= link_to_if_authorized l(:button_move), {:controller => 'issues', :action => 'move', :id => @issue }, :class => 'icon icon-move' %> |
|
|||
7 | <%= link_to_if_authorized l(:button_delete), {:controller => 'issues', :action => 'destroy', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> |
|
|||
8 | </div> |
|
|||
9 |
|
2 | |||
10 | <h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> |
|
3 | <h2><%= @issue.tracker.name %> #<%= @issue.id %></h2> | |
11 |
|
4 | |||
@@ -93,6 +86,9 | |||||
93 | <%= render :partial => 'history', :locals => { :journals => @journals } %> |
|
86 | <%= render :partial => 'history', :locals => { :journals => @journals } %> | |
94 | </div> |
|
87 | </div> | |
95 | <% end %> |
|
88 | <% end %> | |
|
89 | ||||
|
90 | <%= render :partial => 'action_menu', :locals => {:replace_watcher => 'watcher2' } %> | |||
|
91 | ||||
96 | <div style="clear: both;"></div> |
|
92 | <div style="clear: both;"></div> | |
97 |
|
93 | |||
98 | <% if authorize_for('issues', 'edit') %> |
|
94 | <% if authorize_for('issues', 'edit') %> |
@@ -47,6 +47,16 class WatchersControllerTest < ActionController::TestCase | |||||
47 | end |
|
47 | end | |
48 | assert Issue.find(1).watched_by?(User.find(3)) |
|
48 | assert Issue.find(1).watched_by?(User.find(3)) | |
49 | end |
|
49 | end | |
|
50 | ||||
|
51 | def test_watch_with_multiple_replacements | |||
|
52 | @request.session[:user_id] = 3 | |||
|
53 | assert_difference('Watcher.count') do | |||
|
54 | xhr :post, :watch, :object_type => 'issue', :object_id => '1', :replace => ['watch_item_1','watch_item_2'] | |||
|
55 | assert_response :success | |||
|
56 | assert_select_rjs :replace_html, 'watch_item_1' | |||
|
57 | assert_select_rjs :replace_html, 'watch_item_2' | |||
|
58 | end | |||
|
59 | end | |||
50 |
|
60 | |||
51 | def test_unwatch |
|
61 | def test_unwatch | |
52 | @request.session[:user_id] = 3 |
|
62 | @request.session[:user_id] = 3 | |
@@ -57,7 +67,18 class WatchersControllerTest < ActionController::TestCase | |||||
57 | end |
|
67 | end | |
58 | assert !Issue.find(1).watched_by?(User.find(3)) |
|
68 | assert !Issue.find(1).watched_by?(User.find(3)) | |
59 | end |
|
69 | end | |
60 |
|
70 | |||
|
71 | def test_unwatch_with_multiple_replacements | |||
|
72 | @request.session[:user_id] = 3 | |||
|
73 | assert_difference('Watcher.count', -1) do | |||
|
74 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2', :replace => ['watch_item_1', 'watch_item_2'] | |||
|
75 | assert_response :success | |||
|
76 | assert_select_rjs :replace_html, 'watch_item_1' | |||
|
77 | assert_select_rjs :replace_html, 'watch_item_2' | |||
|
78 | end | |||
|
79 | assert !Issue.find(1).watched_by?(User.find(3)) | |||
|
80 | end | |||
|
81 | ||||
61 | def test_new_watcher |
|
82 | def test_new_watcher | |
62 | @request.session[:user_id] = 2 |
|
83 | @request.session[:user_id] = 2 | |
63 | assert_difference('Watcher.count') do |
|
84 | assert_difference('Watcher.count') do |
General Comments 0
You need to be logged in to leave comments.
Login now