parent
5deae7ebe3
commit
8160cd02bd
|
@ -34,9 +34,12 @@ class WatchersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@watcher = Watcher.new(params[:watcher])
|
params[:user_ids].each do |user_id|
|
||||||
|
@watcher = Watcher.new((params[:watcher] || {}).merge({:user_id => user_id}))
|
||||||
@watcher.watchable = @watched
|
@watcher.watchable = @watched
|
||||||
@watcher.save if request.post?
|
@watcher.save if request.post?
|
||||||
|
end if params[:user_ids].present?
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js do
|
format.js do
|
||||||
|
|
|
@ -285,7 +285,7 @@ module ApplicationHelper
|
||||||
def principals_check_box_tags(name, principals)
|
def principals_check_box_tags(name, principals)
|
||||||
s = ''
|
s = ''
|
||||||
principals.sort.each do |principal|
|
principals.sort.each do |principal|
|
||||||
s << "<label>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
|
s << "<label style='display:block;'>#{ check_box_tag name, principal.id, false } #{h principal}</label>\n"
|
||||||
end
|
end
|
||||||
s
|
s
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,24 +1,31 @@
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to_remote l(:button_add),
|
<%= link_to_function(l(:button_add), "$('new-watcher-form').toggle();") if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||||||
:url => {:controller => 'watchers',
|
|
||||||
:action => 'new',
|
|
||||||
:object_type => watched.class.name.underscore,
|
|
||||||
:object_id => watched} if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3><%= l(:label_issue_watchers) %> (<%= watched.watcher_users.size %>)</h3>
|
<h3><%= l(:label_issue_watchers) %> (<%= watched.watcher_users.size %>)</h3>
|
||||||
|
|
||||||
<% unless @watcher.nil? %>
|
<% if User.current.allowed_to?(:add_issue_watchers, @project) %>
|
||||||
<% remote_form_for(:watcher, @watcher,
|
<% remote_form_for(:watcher, @watcher,
|
||||||
:url => {:controller => 'watchers',
|
:url => {:controller => 'watchers',
|
||||||
:action => 'new',
|
:action => 'new',
|
||||||
:object_type => watched.class.name.underscore,
|
:object_type => watched.class.name.underscore,
|
||||||
:object_id => watched},
|
:object_id => watched},
|
||||||
:method => :post,
|
:method => :post,
|
||||||
:html => {:id => 'new-watcher-form'}) do |f| %>
|
:html => {:id => 'new-watcher-form', :style => 'display:none;'}) do |f| %>
|
||||||
<p><%= f.select :user_id, (watched.addable_watcher_users.collect {|m| [m.name, m.id]}), :prompt => "--- #{l(:actionview_instancetag_blank_option)} ---" %>
|
<% users = User.active.find(:all, :limit => 10) %>
|
||||||
|
<p><%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil, :style => "width:98%;" %></p>
|
||||||
|
<%= observe_field(:user_search,
|
||||||
|
:frequency => 0.5,
|
||||||
|
:update => :users,
|
||||||
|
:url => auto_complete_users_path,
|
||||||
|
:with => 'q')
|
||||||
|
%>
|
||||||
|
|
||||||
<%= submit_tag l(:button_add) %>
|
<div id="users">
|
||||||
|
<%= principals_check_box_tags 'user_ids[]', users %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p><%= submit_tag l(:button_add) %>
|
||||||
<%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
|
<%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -114,13 +114,24 @@ class WatchersControllerTest < ActionController::TestCase
|
||||||
def test_new_watcher
|
def test_new_watcher
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference('Watcher.count') do
|
assert_difference('Watcher.count') do
|
||||||
xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
|
xhr :post, :new, :object_type => 'issue', :object_id => '2', :user_ids => ['4']
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select_rjs :replace_html, 'watchers'
|
assert_select_rjs :replace_html, 'watchers'
|
||||||
end
|
end
|
||||||
assert Issue.find(2).watched_by?(User.find(4))
|
assert Issue.find(2).watched_by?(User.find(4))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_new_multiple_users
|
||||||
|
@request.session[:user_id] = 2
|
||||||
|
assert_difference('Watcher.count', 2) do
|
||||||
|
xhr :post, :new, :object_type => 'issue', :object_id => '2', :user_ids => ['4','7']
|
||||||
|
assert_response :success
|
||||||
|
assert_select_rjs :replace_html, 'watchers'
|
||||||
|
end
|
||||||
|
assert Issue.find(2).watched_by?(User.find(4))
|
||||||
|
assert Issue.find(2).watched_by?(User.find(7))
|
||||||
|
end
|
||||||
|
|
||||||
def test_remove_watcher
|
def test_remove_watcher
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference('Watcher.count', -1) do
|
assert_difference('Watcher.count', -1) do
|
||||||
|
|
Loading…
Reference in New Issue