Bulk watch/unwatch issues from the context menu (#7159).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11339 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -16,23 +16,19 @@
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
class WatchersController < ApplicationController
|
||||
before_filter :find_project
|
||||
before_filter :require_login, :check_project_privacy, :only => [:watch, :unwatch]
|
||||
before_filter :authorize, :only => [:new, :destroy]
|
||||
accept_api_auth :create, :destroy
|
||||
before_filter :require_login, :find_watchables, :only => [:watch, :unwatch]
|
||||
|
||||
def watch
|
||||
if @watched.respond_to?(:visible?) && !@watched.visible?(User.current)
|
||||
render_403
|
||||
else
|
||||
set_watcher(User.current, true)
|
||||
end
|
||||
set_watcher(@watchables, User.current, true)
|
||||
end
|
||||
|
||||
def unwatch
|
||||
set_watcher(User.current, false)
|
||||
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
|
||||
end
|
||||
|
||||
@@ -77,7 +73,8 @@ class WatchersController < ApplicationController
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def find_project
|
||||
if params[:object_type] && params[:object_id]
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
@@ -91,11 +88,22 @@ private
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_watcher(user, watching)
|
||||
@watched.set_watcher(user, watching)
|
||||
def find_watchables
|
||||
klass = Object.const_get(params[:object_type].camelcase) rescue nil
|
||||
if klass && klass.respond_to?('watched_by')
|
||||
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
|
||||
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
|
||||
end
|
||||
render_404 unless @watchables.present?
|
||||
end
|
||||
|
||||
def set_watcher(watchables, user, watching)
|
||||
watchables.each do |watchable|
|
||||
watchable.set_watcher(user, watching)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
|
||||
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => @watched} }
|
||||
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,21 +24,28 @@ module WatchersHelper
|
||||
watcher_link(object, user)
|
||||
end
|
||||
|
||||
def watcher_link(object, user)
|
||||
return '' unless user && user.logged? && object.respond_to?('watched_by?')
|
||||
watched = object.watched_by?(user)
|
||||
css = [watcher_css(object), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
|
||||
url = {:controller => 'watchers',
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:object_type => object.class.to_s.underscore,
|
||||
:object_id => object.id}
|
||||
link_to((watched ? l(:button_unwatch) : l(:button_watch)), url,
|
||||
:remote => true, :method => 'post', :class => css)
|
||||
def watcher_link(objects, user)
|
||||
return '' unless user && user.logged?
|
||||
objects = Array.wrap(objects)
|
||||
|
||||
watched = objects.any? {|object| object.watched_by?(user)}
|
||||
css = [watcher_css(objects), watched ? 'icon icon-fav' : 'icon icon-fav-off'].join(' ')
|
||||
text = watched ? l(:button_unwatch) : l(:button_watch)
|
||||
url = {
|
||||
:controller => 'watchers',
|
||||
:action => (watched ? 'unwatch' : 'watch'),
|
||||
:object_type => objects.first.class.to_s.underscore,
|
||||
:object_id => (objects.size == 1 ? objects.first.id : objects.map(&:id).sort)
|
||||
}
|
||||
|
||||
link_to text, url, :remote => true, :method => 'post', :class => css
|
||||
end
|
||||
|
||||
# Returns the css class used to identify watch links for a given +object+
|
||||
def watcher_css(object)
|
||||
"#{object.class.to_s.underscore}-#{object.id}-watcher"
|
||||
def watcher_css(objects)
|
||||
objects = Array.wrap(objects)
|
||||
id = (objects.size == 1 ? objects.first.id : 'bulk')
|
||||
"#{objects.first.class.to_s.underscore}-#{id}-watcher"
|
||||
end
|
||||
|
||||
# Returns a comma separated list of users watching the given object
|
||||
|
||||
@@ -117,10 +117,11 @@
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if User.current.logged? %>
|
||||
<li><%= watcher_link(@issues, User.current) %></li>
|
||||
<% end %>
|
||||
|
||||
<% if @issue.present? %>
|
||||
<% if User.current.logged? %>
|
||||
<li><%= watcher_link(@issue, User.current) %></li>
|
||||
<% end %>
|
||||
<% if @can[:log_time] -%>
|
||||
<li><%= context_menu_link l(:button_log_time), new_issue_time_entry_path(@issue),
|
||||
:class => 'icon-time-add' %></li>
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
<%= form_tag({:controller => 'watchers',
|
||||
:action => (watched ? 'create' : 'append'),
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched},
|
||||
:object_type => (watched && watched.class.name.underscore),
|
||||
:object_id => watched,
|
||||
:project_id => @project},
|
||||
:remote => true,
|
||||
:method => :post,
|
||||
:id => 'new-watcher-form') do %>
|
||||
@@ -11,8 +12,9 @@
|
||||
<p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
|
||||
<%= javascript_tag "observeSearchfield('user_search', 'users_for_watcher', '#{ escape_javascript url_for(:controller => 'watchers',
|
||||
:action => 'autocomplete_for_user',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched) }')" %>
|
||||
:object_type => (watched && watched.class.name.underscore),
|
||||
:object_id => watched,
|
||||
:project_id => @project) }')" %>
|
||||
|
||||
<div id="users_for_watcher">
|
||||
<%= principals_check_box_tags 'watcher[user_ids][]', (watched ? watched.addable_watcher_users : User.active.all(:limit => 100)) %>
|
||||
|
||||
Reference in New Issue
Block a user