[#800 #801] Add Javascript search to bulk add watchers to issues.

This commit is contained in:
Eric Davis 2010-12-03 14:43:03 -08:00
parent 5deae7ebe3
commit 8160cd02bd
4 changed files with 36 additions and 15 deletions

View File

@ -34,9 +34,12 @@ class WatchersController < ApplicationController
end
def new
@watcher = Watcher.new(params[:watcher])
@watcher.watchable = @watched
@watcher.save if request.post?
params[:user_ids].each do |user_id|
@watcher = Watcher.new((params[:watcher] || {}).merge({:user_id => user_id}))
@watcher.watchable = @watched
@watcher.save if request.post?
end if params[:user_ids].present?
respond_to do |format|
format.html { redirect_to :back }
format.js do

View File

@ -285,7 +285,7 @@ module ApplicationHelper
def principals_check_box_tags(name, principals)
s = ''
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
s
end

View File

@ -1,24 +1,31 @@
<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) %>
<%= link_to_function(l(:button_add), "$('new-watcher-form').toggle();") if User.current.allowed_to?(:add_issue_watchers, @project) %>
</div>
<h3><%= l(:label_issue_watchers) %> (<%= watched.watcher_users.size %>)</h3>
<% unless @watcher.nil? %>
<% remote_form_for(:watcher, @watcher,
<% if User.current.allowed_to?(:add_issue_watchers, @project) %>
<% 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)} ---" %>
:html => {:id => 'new-watcher-form', :style => 'display:none;'}) do |f| %>
<% 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')
%>
<div id="users">
<%= principals_check_box_tags 'user_ids[]', users %>
</div>
<%= submit_tag l(:button_add) %>
<p><%= submit_tag l(:button_add) %>
<%= toggle_link l(:button_cancel), 'new-watcher-form'%></p>
<% end %>
<% end %>

View File

@ -114,13 +114,24 @@ class WatchersControllerTest < ActionController::TestCase
def test_new_watcher
@request.session[:user_id] = 2
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_select_rjs :replace_html, 'watchers'
end
assert Issue.find(2).watched_by?(User.find(4))
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
@request.session[:user_id] = 2
assert_difference('Watcher.count', -1) do