Patch #38792 » enable_removing_watchers_in_bulk_context_menu.patch
| app/controllers/context_menus_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/context_menus_controller.rb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
|
||
|
:copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
|
||
|
:add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
|
||
|
:delete_watchers => User.current.allowed_to?(:delete_issue_watchers, @projects),
|
||
|
:delete => @issues.all?(&:deletable?),
|
||
|
:add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project)
|
||
|
}
|
||
| app/controllers/watchers_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/watchers_controller.rb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class WatchersController < ApplicationController
|
||
|
before_action :require_login, :find_watchables, :only => [:watch, :unwatch]
|
||
|
before_action :require_login, :find_watchables, :only => [:watch, :unwatch, :bulk_delete]
|
||
|
def watch
|
||
|
set_watcher(@watchables, User.current, true)
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def bulk_delete
|
||
|
if request.method == "POST"
|
||
|
return unless params[:watcher].present?
|
||
|
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
|
||
|
@users = Principal.where(:id => user_ids).to_a
|
||
|
@users.each do |user|
|
||
|
@watchables.each do |watchable|
|
||
|
watchable.set_watcher(user, false)
|
||
|
end
|
||
|
end
|
||
|
respond_to do |format|
|
||
|
format.js
|
||
|
format.api {render_api_ok}
|
||
|
end
|
||
|
elsif request.method == "GET"
|
||
|
if params["object_id"].present?
|
||
|
@users = Watcher.where(watchable_id: params["object_id"]).all.map { |w| w.user }.uniq
|
||
|
else
|
||
|
@users = Principal.assignable_watchers
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def destroy
|
||
|
user = Principal.find(params[:user_id])
|
||
|
@watchables.each do |watchable|
|
||
| app/views/context_menus/issues.html.erb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/views/context_menus/issues.html.erb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
new_watchers_path(:object_type => 'issue', :object_id => @issue_ids),
|
||
|
:remote => true,
|
||
|
:class => 'icon icon-add' %></li>
|
||
|
<li><%= context_menu_link l(:button_delete),
|
||
|
bulk_delete_watchers_dialog_path(:object_type => 'issue', :object_id => @issue_ids),
|
||
|
:remote => true,
|
||
|
:class => 'icon icon-del' %></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<% end %>
|
||
| /dev/null (revision 41653+:c704208ed465+) → app/views/watchers/_bulk_delete.html.erb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
<%
|
||
|
title =
|
||
|
if watchables.present?
|
||
|
l(:"permission_delete_#{watchables.first.class.name.underscore}_watchers")
|
||
|
else
|
||
|
l(:permission_delete_issue_watchers)
|
||
|
end
|
||
|
-%>
|
||
|
<h3 class="title"><%= title %></h3>
|
||
|
<%= form_tag(bulk_delete_watchers_path,
|
||
|
:remote => true,
|
||
|
:method => :post,
|
||
|
:id => 'new-watcher-form') do %>
|
||
|
<% if watchables.present? %>
|
||
|
<%= hidden_field_tag 'object_type', watchables.first.class.name.underscore %>
|
||
|
<% watchables.each do |watchable| %>
|
||
|
<%= hidden_field_tag 'object_id[]', watchable.id %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<%= hidden_field_tag 'project_id', @project.id if @project %>
|
||
|
<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 => (watchables.present? ? watchables.first.class.name.underscore : nil),
|
||
|
:object_id => (watchables.present? ? watchables.map(&:id) : nil),
|
||
|
:project_id => @project
|
||
|
)
|
||
|
)}'
|
||
|
)"
|
||
|
) %>
|
||
|
<div id="users_for_watcher">
|
||
|
<%= principals_check_box_tags('watcher[user_ids][]', users) %>
|
||
|
</div>
|
||
|
<p class="buttons">
|
||
|
<%= submit_tag l(:button_delete), :name => nil, :onclick => "hideModal(this);" %>
|
||
|
<%= link_to_function l(:button_cancel), "hideModal(this);" %>
|
||
|
</p>
|
||
|
<% end %>
|
||
| /dev/null (revision 41653+:c704208ed465+) → app/views/watchers/bulk_delete.js.erb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
<% if request.method == "GET" %>
|
||
|
$('#ajax-modal').html(
|
||
|
'<%= escape_javascript(
|
||
|
render(:partial => 'watchers/bulk_delete',
|
||
|
:locals => { :watchables => @watchables, :users => @users })
|
||
|
) %>');
|
||
|
showModal('ajax-modal', '400px');
|
||
|
$('#ajax-modal').addClass('delete-watchers');
|
||
|
<% end %>
|
||
| config/routes.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → config/routes.rb (revision 41653+:c704208ed465+) | ||
|---|---|---|
|
post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
|
||
|
delete 'watchers/watch', :to => 'watchers#unwatch'
|
||
|
get 'watchers/new', :to => 'watchers#new', :as => 'new_watchers'
|
||
|
get 'watchers/delete', :to => 'watchers#bulk_delete', :as => 'bulk_delete_watchers_dialog'
|
||
|
post 'watchers/bulk_delete', :to => 'watchers#bulk_delete', :as => 'bulk_delete_watchers'
|
||
|
post 'watchers', :to => 'watchers#create'
|
||
|
post 'watchers/append', :to => 'watchers#append'
|
||
|
delete 'watchers', :to => 'watchers#destroy'
|
||