Defect #4334 » watchers_list_refresh_patch.diff
| app/controllers/watchers_controller.rb | ||
|---|---|---|
|
class WatchersController < ApplicationController
|
||
|
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
|
||
|
before_filter :find_project, :only => [:new, :create, :append, :destroy, :autocomplete_for_user, :watch, :unwatch]
|
||
|
before_filter :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user]
|
||
|
def watch
|
||
|
set_watcher(@watchables, User.current, true)
|
||
| ... | ... | |
|
set_watcher(@watchables, User.current, false)
|
||
|
end
|
||
|
before_filter :find_project, :authorize, :only => [:new, :create, :append, :destroy, :autocomplete_for_user]
|
||
|
accept_api_auth :create, :destroy
|
||
|
def new
|
||
| ... | ... | |
|
else
|
||
|
user_ids << params[:user_id]
|
||
|
end
|
||
|
user_ids.flatten.compact.uniq.each do |user_id|
|
||
|
user_ids = user_ids.flatten.compact.uniq.map(&:to_i) & users_for_new_watcher.map(&:id)
|
||
|
user_ids.each do |user_id|
|
||
|
Watcher.create(:watchable => @watched, :user_id => user_id)
|
||
|
end
|
||
|
respond_to do |format|
|
||
| ... | ... | |
|
def users_for_new_watcher
|
||
|
users = []
|
||
|
if params[:q].blank? && @project.present?
|
||
|
users = @project.users.sorted
|
||
|
else
|
||
|
users = User.active.sorted.like(params[:q]).limit(100)
|
||
|
if @project.present?
|
||
|
if params[:q].blank?
|
||
|
users = @project.users.sorted
|
||
|
else
|
||
|
users = @project.users.sorted.like(params[:q]).limit(10)
|
||
|
end
|
||
|
end
|
||
|
if @watched
|
||
|
users -= @watched.watcher_users
|
||
| app/helpers/watchers_helper.rb | ||
|---|---|---|
|
def watchers_list(object)
|
||
|
remove_allowed = User.current.allowed_to?("delete_#{object.class.name.underscore}_watchers".to_sym, object.project)
|
||
|
content = ''.html_safe
|
||
|
object.reload
|
||
|
lis = object.watcher_users.collect do |user|
|
||
|
s = ''.html_safe
|
||
|
s << avatar(user, :size => "16").to_s
|
||
| app/views/watchers/_set_watcher.js.erb | ||
|---|---|---|
|
<% selector = ".#{watcher_css(watched)}" %>
|
||
|
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(watched, user) %>")});
|
||
|
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => watched.first})) %>');
|
||
| app/views/watchers/_watchers.html.erb | ||
|---|---|---|
|
<% watched.reload %>
|
||
|
<% if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||
|
<div class="contextual">
|
||
|
<%= link_to l(:button_add),
|
||
| app/views/watchers/destroy.js.erb | ||
|---|---|---|
|
$('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>');
|
||
|
<% selector = ".#{watcher_css(@watched)}" %>
|
||
|
$("<%= selector %>").each(function(){$(this).replaceWith("<%= escape_javascript watcher_link(@watched, User.current) %>")});
|
||