From 1b1c510ff99cfca216082926e5ce9e2e981b2506 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 9 Jan 2012 18:37:16 +0000 Subject: [PATCH] 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 --- app/controllers/watchers_controller.rb | 26 ++++++++++++++-- app/views/layouts/base.html.erb | 1 + app/views/watchers/_new.html.erb | 30 +++++++++++++++++++ app/views/watchers/_watchers.html.erb | 20 +++---------- .../watchers/autocomplete_for_user.html.erb | 1 + config/routes.rb | 6 +++- public/stylesheets/application.css | 3 ++ test/functional/watchers_controller_test.rb | 24 +++++++++++++-- test/integration/routing/watchers_test.rb | 18 +++++++---- 9 files changed, 101 insertions(+), 28 deletions(-) create mode 100644 app/views/watchers/_new.html.erb create mode 100644 app/views/watchers/autocomplete_for_user.html.erb diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 8c951ad9d..1a1935d0d 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -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) diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb index 6673b4944..ccf5dbaee 100644 --- a/app/views/layouts/base.html.erb +++ b/app/views/layouts/base.html.erb @@ -73,6 +73,7 @@ +