Ability to add non-member users as watchers (#5159).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8592 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -37,13 +37,28 @@ class WatchersController < ApplicationController
|
||||
end
|
||||
|
||||
def new
|
||||
@watcher = Watcher.new(params[:watcher])
|
||||
@watcher.watchable = @watched
|
||||
@watcher.save if request.post?
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
|
||||
page << "showModal('ajax-modal', '400px');"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:watcher].is_a?(Hash) && request.post?
|
||||
user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
|
||||
user_ids.each do |user_id|
|
||||
Watcher.create(:watchable => @watched, :user_id => user_id)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
format.js do
|
||||
render :update do |page|
|
||||
page.replace_html 'ajax-modal', :partial => 'watchers/new', :locals => {:watched => @watched}
|
||||
page.replace_html 'watchers', :partial => 'watchers/watchers', :locals => {:watched => @watched}
|
||||
end
|
||||
end
|
||||
@@ -64,6 +79,11 @@ class WatchersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def autocomplete_for_user
|
||||
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @watched.watcher_users
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
def find_project
|
||||
klass = Object.const_get(params[:object_type].camelcase)
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
</div>
|
||||
|
||||
<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
|
||||
<div id="ajax-modal" style="display:none;"></div>
|
||||
|
||||
<div id="footer">
|
||||
<div class="bgl"><div class="bgr">
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<h3 class="title"><%= l(:permission_add_issue_watchers) %></h3>
|
||||
|
||||
<% form_remote_tag :url => {:controller => 'watchers',
|
||||
:action => 'create',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched},
|
||||
:method => :post,
|
||||
:html => {:id => 'new-watcher-form'} do %>
|
||||
|
||||
<p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
|
||||
<%= observe_field(:user_search,
|
||||
:frequency => 0.5,
|
||||
:update => :users_for_watcher,
|
||||
:method => :get,
|
||||
:url => {
|
||||
:controller => 'watchers',
|
||||
:action => 'autocomplete_for_user',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched},
|
||||
:with => 'q') %>
|
||||
|
||||
<div id="users_for_watcher">
|
||||
<%= principals_check_box_tags 'watcher[user_ids][]', watched.addable_watcher_users %>
|
||||
</div>
|
||||
|
||||
<p class="buttons">
|
||||
<%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %>
|
||||
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
|
||||
</p>
|
||||
<% end %>
|
||||
@@ -1,26 +1,14 @@
|
||||
<% if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||||
<div class="contextual">
|
||||
<%= link_to_remote l(:button_add),
|
||||
:url => {:controller => 'watchers',
|
||||
:action => 'new',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched} if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||||
:object_id => watched},
|
||||
:method => 'get' %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<h3><%= l(:label_issue_watchers) %> (<%= watched.watcher_users.size %>)</h3>
|
||||
|
||||
<% unless @watcher.nil? %>
|
||||
<% remote_form_for(:watcher, @watcher,
|
||||
:url => {:controller => 'watchers',
|
||||
:action => 'new',
|
||||
:object_type => watched.class.name.underscore,
|
||||
:object_id => watched},
|
||||
:method => :post,
|
||||
:html => {:id => 'new-watcher-form'}) do |f| %>
|
||||
<p><%= f.select :user_id, (watched.addable_watcher_users.collect {|m| [m.name, m.id]}), :prompt => "--- #{l(:actionview_instancetag_blank_option)} ---" %>
|
||||
|
||||
<%= submit_tag l(:button_add) %>
|
||||
<%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= watchers_list(watched) %>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%= principals_check_box_tags 'watcher[user_ids][]', @users %>
|
||||
Reference in New Issue
Block a user