@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -76,21 +76,13 private | |||
|
76 | 76 | |
|
77 | 77 | def set_watcher(user, watching) |
|
78 | 78 | @watched.set_watcher(user, watching) |
|
79 | if params[:replace].present? | |
|
80 | if params[:replace].is_a? Array | |
|
81 | replace_ids = params[:replace] | |
|
82 | else | |
|
83 | replace_ids = [params[:replace]] | |
|
84 | end | |
|
85 | else | |
|
86 | replace_ids = ['watcher'] | |
|
87 | end | |
|
88 | 79 | respond_to do |format| |
|
89 | 80 | format.html { redirect_to :back } |
|
90 | 81 | format.js do |
|
91 | 82 | render(:update) do |page| |
|
92 | replace_ids.each do |replace_id| | |
|
93 | page.replace_html replace_id, watcher_link(@watched, user, :replace => replace_ids) | |
|
83 | c = watcher_css(@watched) | |
|
84 | page.select(".#{c}").each do |item| | |
|
85 | page.replace_html item, watcher_link(@watched, user) | |
|
94 | 86 | end |
|
95 | 87 | end |
|
96 | 88 | end |
@@ -1,5 +1,5 | |||
|
1 |
# |
|
|
2 |
# Copyright (C) 2006-20 |
|
|
1 | # Redmine - project management software | |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -16,28 +16,18 | |||
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module WatchersHelper |
|
19 | ||
|
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) | |
|
19 | ||
|
20 | def watcher_tag(object, user, options={}) | |
|
21 | content_tag("span", watcher_link(object, user), :class => watcher_css(object)) | |
|
28 | 22 | end |
|
29 | 23 | |
|
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 | def watcher_link(object, user) | |
|
34 | 25 | return '' unless user && user.logged? && object.respond_to?('watched_by?') |
|
35 | 26 | watched = object.watched_by?(user) |
|
36 | 27 | url = {:controller => 'watchers', |
|
37 | 28 | :action => (watched ? 'unwatch' : 'watch'), |
|
38 | 29 | :object_type => object.class.to_s.underscore, |
|
39 |
:object_id => object.id |
|
|
40 | :replace => options[:replace]} | |
|
30 | :object_id => object.id} | |
|
41 | 31 | link_to_remote((watched ? l(:button_unwatch) : l(:button_watch)), |
|
42 | 32 | {:url => url}, |
|
43 | 33 | :href => url_for(url), |
@@ -45,6 +35,11 module WatchersHelper | |||
|
45 | 35 | |
|
46 | 36 | end |
|
47 | 37 | |
|
38 | # Returns the css class used to identify watch links for a given +object+ | |
|
39 | def watcher_css(object) | |
|
40 | "#{object.class.to_s.underscore}-#{object.id}-watcher" | |
|
41 | end | |
|
42 | ||
|
48 | 43 | # Returns a comma separated list of users watching the given object |
|
49 | 44 | def watchers_list(object) |
|
50 | 45 | remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) |
@@ -1,8 +1,7 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 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 | 3 | <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'new', :issue_id => @issue}, :class => 'icon icon-time-add' %> |
|
4 | <% replace_watcher ||= 'watcher' %> | |
|
5 | <%= watcher_tag(@issue, User.current, {:id => replace_watcher, :replace => ['watcher','watcher2']}) %> | |
|
4 | <%= watcher_tag(@issue, User.current) %> | |
|
6 | 5 | <%= link_to_if_authorized l(:button_duplicate), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-duplicate' %> |
|
7 | 6 | <%= link_to_if_authorized l(:button_copy), {:controller => 'issue_moves', :action => 'new', :id => @issue, :copy_options => {:copy => 't'}}, :class => 'icon icon-copy' %> |
|
8 | 7 | <%= link_to_if_authorized l(:button_move), {:controller => 'issue_moves', :action => 'new', :id => @issue}, :class => 'icon icon-move' %> |
@@ -98,7 +98,7 | |||
|
98 | 98 | |
|
99 | 99 | |
|
100 | 100 | <div style="clear: both;"></div> |
|
101 |
<%= render :partial => 'action_menu' |
|
|
101 | <%= render :partial => 'action_menu' %> | |
|
102 | 102 | |
|
103 | 103 | <div style="clear: both;"></div> |
|
104 | 104 | <% if authorize_for('issues', 'edit') %> |
@@ -1,5 +1,5 | |||
|
1 | 1 | # Redmine - project management software |
|
2 |
# Copyright (C) 2006-20 |
|
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
@@ -43,7 +43,7 class WatchersControllerTest < ActionController::TestCase | |||
|
43 | 43 | assert_difference('Watcher.count') do |
|
44 | 44 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
|
45 | 45 | assert_response :success |
|
46 | assert_select_rjs :replace_html, 'watcher' | |
|
46 | assert @response.body.include?('$$(".issue-1-watcher")') | |
|
47 | 47 | end |
|
48 | 48 | assert Issue.find(1).watched_by?(User.find(3)) |
|
49 | 49 | end |
@@ -56,34 +56,13 class WatchersControllerTest < ActionController::TestCase | |||
|
56 | 56 | assert_response 403 |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | ||
|
60 | def test_watch_with_multiple_replacements | |
|
61 | @request.session[:user_id] = 3 | |
|
62 | assert_difference('Watcher.count') do | |
|
63 | xhr :post, :watch, :object_type => 'issue', :object_id => '1', :replace => ['watch_item_1','watch_item_2'] | |
|
64 | assert_response :success | |
|
65 | assert_select_rjs :replace_html, 'watch_item_1' | |
|
66 | assert_select_rjs :replace_html, 'watch_item_2' | |
|
67 | end | |
|
68 | end | |
|
69 | 59 | |
|
70 | 60 | def test_unwatch |
|
71 | 61 | @request.session[:user_id] = 3 |
|
72 | 62 | assert_difference('Watcher.count', -1) do |
|
73 | 63 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2' |
|
74 | 64 | assert_response :success |
|
75 | assert_select_rjs :replace_html, 'watcher' | |
|
76 | end | |
|
77 | assert !Issue.find(1).watched_by?(User.find(3)) | |
|
78 | end | |
|
79 | ||
|
80 | def test_unwatch_with_multiple_replacements | |
|
81 | @request.session[:user_id] = 3 | |
|
82 | assert_difference('Watcher.count', -1) do | |
|
83 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2', :replace => ['watch_item_1', 'watch_item_2'] | |
|
84 | assert_response :success | |
|
85 | assert_select_rjs :replace_html, 'watch_item_1' | |
|
86 | assert_select_rjs :replace_html, 'watch_item_2' | |
|
65 | assert @response.body.include?('$$(".issue-2-watcher")') | |
|
87 | 66 | end |
|
88 | 67 | assert !Issue.find(1).watched_by?(User.find(3)) |
|
89 | 68 | end |
General Comments 0
You need to be logged in to leave comments.
Login now