Defect #4334 » watchers_list_refresh_patch.diff
app/controllers/watchers_controller.rb | ||
---|---|---|
17 | 17 | |
18 | 18 |
class WatchersController < ApplicationController |
19 | 19 |
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch] |
20 |
before_filter :find_project, :only => [:new, :create, :append, :destroy, :autocomplete_for_user, :watch, :unwatch] |
|
21 |
before_filter :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user] |
|
20 | 22 | |
21 | 23 |
def watch |
22 | 24 |
set_watcher(@watchables, User.current, true) |
... | ... | |
26 | 28 |
set_watcher(@watchables, User.current, false) |
27 | 29 |
end |
28 | 30 | |
29 |
before_filter :find_project, :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user] |
|
30 | 31 |
accept_api_auth :create, :destroy |
31 | 32 | |
32 | 33 |
def new |
... | ... | |
40 | 41 |
else |
41 | 42 |
user_ids << params[:user_id] |
42 | 43 |
end |
43 |
user_ids.flatten.compact.uniq.each do |user_id| |
|
44 |
user_ids = user_ids.flatten.compact.uniq.map(&:to_i) & users_for_new_watcher.map(&:id) |
|
45 |
user_ids.each do |user_id| |
|
44 | 46 |
Watcher.create(:watchable => @watched, :user_id => user_id) |
45 | 47 |
end |
46 | 48 |
respond_to do |format| |
... | ... | |
116 | 118 | |
117 | 119 |
def users_for_new_watcher |
118 | 120 |
users = [] |
119 |
if params[:q].blank? && @project.present? |
|
120 |
users = @project.users.sorted |
|
121 |
else |
|
122 |
users = User.active.sorted.like(params[:q]).limit(100) |
|
121 |
if @project.present? |
|
122 |
if params[:q].blank? |
|
123 |
users = @project.users.sorted |
|
124 |
else |
|
125 |
users = @project.users.sorted.like(params[:q]).limit(10) |
|
126 |
end |
|
123 | 127 |
end |
124 | 128 |
if @watched |
125 | 129 |
users -= @watched.watcher_users |
app/helpers/watchers_helper.rb | ||
---|---|---|
52 | 52 |
def watchers_list(object) |
53 | 53 |
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project) |
54 | 54 |
content = ''.html_safe |
55 |
object.reload |
|
55 | 56 |
lis = object.watcher_users.collect do |user| |
56 | 57 |
s = ''.html_safe |
57 | 58 |
s << avatar(user, :size => "16").to_s |
app/views/watchers/_set_watcher.js.erb | ||
---|---|---|
1 | 1 |
<% selector = ".#{watcher_css(watched)}" %> |
2 | 2 |
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")}); |
3 |
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>'); |
app/views/watchers/_watchers.html.erb | ||
---|---|---|
1 |
<% watched.reload %> |
|
1 | 2 |
<% if User.current.allowed_to?(:add_issue_watchers, @project) %> |
2 | 3 |
<div class="contextual"> |
3 | 4 |
<%= link_to l(:button_add), |
app/views/watchers/destroy.js.erb | ||
---|---|---|
1 | 1 |
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); |
2 |
<% selector = ".#{watcher_css(@watched)}" %> |
|
3 |
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(@watched, User.current) %>")}); |