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
This commit is contained in:
Jean-Philippe Lang
2014-01-19 10:01:14 +00:00
parent b933cd7a65
commit a525bc8e98
5 changed files with 23 additions and 13 deletions

View File

@@ -428,7 +428,10 @@ class IssuesController < ApplicationController
@priorities = IssuePriority.active @priorities = IssuePriority.active
@allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?) @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 end
def check_for_default_issue_status def check_for_default_issue_status

View File

@@ -30,6 +30,7 @@ class WatchersController < ApplicationController
accept_api_auth :create, :destroy accept_api_auth :create, :destroy
def new def new
@users = users_for_new_watcher
end end
def create def create
@@ -44,7 +45,7 @@ class WatchersController < ApplicationController
end end
respond_to do |format| respond_to do |format|
format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}} 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 } format.api { render_api_ok }
end end
end end
@@ -66,10 +67,7 @@ class WatchersController < ApplicationController
end end
def autocomplete_for_user def autocomplete_for_user
@users = User.active.sorted.like(params[:q]).limit(100).all @users = users_for_new_watcher
if @watched
@users -= @watched.watcher_users
end
render :layout => false render :layout => false
end end
@@ -106,4 +104,17 @@ class WatchersController < ApplicationController
format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} } format.js { render :partial => 'set_watcher', :locals => {:user => user, :watched => watchables} }
end end
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 end

View File

@@ -17,11 +17,7 @@
:project_id => @project) }')" %> :project_id => @project) }')" %>
<div id="users_for_watcher"> <div id="users_for_watcher">
<%= principals_check_box_tags( <%= principals_check_box_tags('watcher[user_ids][]', users) %>
'watcher[user_ids][]',
(watched ?
watched.addable_watcher_users : User.active.limit(100).all)
) %>
</div> </div>
<p class="buttons"> <p class="buttons">

View File

@@ -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})) %>'); $('#watchers').html('<%= escape_javascript(render(:partial => 'watchers/watchers', :locals => {:watched => @watched})) %>');

View File

@@ -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'); showModal('ajax-modal', '400px');
$('#ajax-modal').addClass('new-watcher'); $('#ajax-modal').addClass('new-watcher');