diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index e9479f43..5d5d2d50 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 83007e15..f4396b56 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -285,7 +285,7 @@ module ApplicationHelper def principals_check_box_tags(name, principals) s = '' principals.sort.each do |principal| - s << "\n" + s << "\n" end s end diff --git a/app/views/watchers/_watchers.rhtml b/app/views/watchers/_watchers.rhtml index 4da8c0dd..f05e551d 100644 --- a/app/views/watchers/_watchers.rhtml +++ b/app/views/watchers/_watchers.rhtml @@ -1,24 +1,31 @@
<%= 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) %> +
<%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil, :style => "width:98%;" %>
+ <%= observe_field(:user_search, + :frequency => 0.5, + :update => :users, + :url => auto_complete_users_path, + :with => 'q') + %> + +<%= submit_tag l(:button_add) %> <%= toggle_link l(:button_cancel), 'new-watcher-form'%>
<% end %> <% end %> diff --git a/test/functional/watchers_controller_test.rb b/test/functional/watchers_controller_test.rb index 7023908f..858e807e 100644 --- a/test/functional/watchers_controller_test.rb +++ b/test/functional/watchers_controller_test.rb @@ -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