From a525bc8e98f6e7c88a820ca42df54e58d92a5d1c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 19 Jan 2014 10:01:14 +0000 Subject: [PATCH] Don't display default watchers checkboxes on the new issue form when there are more than 20 members (#8562). git-svn-id: http://svn.redmine.org/redmine/trunk@12673 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/issues_controller.rb | 5 ++++- app/controllers/watchers_controller.rb | 21 ++++++++++++++++----- app/views/watchers/_new.html.erb | 6 +----- app/views/watchers/create.js.erb | 2 +- app/views/watchers/new.js.erb | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f89298c4c..7f40be7d7 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -428,7 +428,10 @@ class IssuesController < ApplicationController @priorities = IssuePriority.active @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?) - @available_watchers = (@issue.project.users.sort + @issue.watcher_users).uniq + @available_watchers = @issue.watcher_users + if @issue.project.users.count <= 20 + @available_watchers = (@available_watchers + @issue.project.users.sort).uniq + end end def check_for_default_issue_status diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 325e9e9f2..13f1f35c6 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -30,6 +30,7 @@ class WatchersController < ApplicationController accept_api_auth :create, :destroy def new + @users = users_for_new_watcher end def create @@ -44,7 +45,7 @@ class WatchersController < ApplicationController end respond_to do |format| format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} - format.js + format.js { @users = users_for_new_watcher } format.api { render_api_ok } end end @@ -66,10 +67,7 @@ class WatchersController < ApplicationController end def autocomplete_for_user - @users = User.active.sorted.like(params[:q]).limit(100).all - if @watched - @users -= @watched.watcher_users - end + @users = users_for_new_watcher render :layout => false end @@ -106,4 +104,17 @@ class WatchersController < ApplicationController format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} } end end + + def users_for_new_watcher + users = [] + if params[:q].blank? && @project.present? + users = @project.users.sorted + else + users = User.active.sorted.like(params[:q]).limit(100) + end + if @watched + users -= @watched.watcher_users + end + users + end end diff --git a/app/views/watchers/_new.html.erb b/app/views/watchers/_new.html.erb index e3443a1cd..6282d59aa 100644 --- a/app/views/watchers/_new.html.erb +++ b/app/views/watchers/_new.html.erb @@ -17,11 +17,7 @@ :project_id => @project) }')" %>
- <%= principals_check_box_tags( - 'watcher[user_ids][]', - (watched ? - watched.addable_watcher_users : User.active.limit(100).all) - ) %> + <%= principals_check_box_tags('watcher[user_ids][]', users) %>

diff --git a/app/views/watchers/create.js.erb b/app/views/watchers/create.js.erb index 0f7e15a00..ba8e580af 100644 --- a/app/views/watchers/create.js.erb +++ b/app/views/watchers/create.js.erb @@ -1,2 +1,2 @@ -$('#ajax-modal').html('<%= escape_javascript(render(:partial => 'watchers/new', :locals => {:watched => @watched})) %>'); +$('#ajax-modal').html('<%= escape_javascript(render(:partial => 'watchers/new', :locals => {:watched => @watched, :users => @users})) %>'); $('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>'); diff --git a/app/views/watchers/new.js.erb b/app/views/watchers/new.js.erb index 6b99f657e..8ff5dacc9 100644 --- a/app/views/watchers/new.js.erb +++ b/app/views/watchers/new.js.erb @@ -1,3 +1,3 @@ -$('#ajax-modal').html('<%= escape_javascript(render :partial => 'watchers/new', :locals => {:watched => @watched}) %>'); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'watchers/new', :locals => {:watched => @watched, :users => @users}) %>'); showModal('ajax-modal', '400px'); $('#ajax-modal').addClass('new-watcher');