Adds a <<me>> option at the top of the assignee drop-down (#1102).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8688 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-01-21 11:06:59 +00:00
parent 1d07bb91a7
commit 45e3dafa8f
2 changed files with 12 additions and 0 deletions

View File

@ -305,6 +305,9 @@ module ApplicationHelper
# Returns a string for users/groups option tags # Returns a string for users/groups option tags
def principals_options_for_select(collection, selected=nil) def principals_options_for_select(collection, selected=nil)
s = '' s = ''
if collection.include?(User.current)
s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
end
groups = '' groups = ''
collection.sort.each do |element| collection.sort.each do |element|
selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)

View File

@ -854,18 +854,21 @@ RAW
end end
def test_principals_options_for_select_with_users def test_principals_options_for_select_with_users
User.current = nil
users = [User.find(2), User.find(4)] users = [User.find(2), User.find(4)]
assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
principals_options_for_select(users) principals_options_for_select(users)
end end
def test_principals_options_for_select_with_selected def test_principals_options_for_select_with_selected
User.current = nil
users = [User.find(2), User.find(4)] users = [User.find(2), User.find(4)]
assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>), assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
principals_options_for_select(users, User.find(4)) principals_options_for_select(users, User.find(4))
end end
def test_principals_options_for_select_with_users_and_groups def test_principals_options_for_select_with_users_and_groups
User.current = nil
users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] users = [User.find(2), Group.find(11), User.find(4), Group.find(10)]
assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) + assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) +
%(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
@ -875,4 +878,10 @@ RAW
def test_principals_options_for_select_with_empty_collection def test_principals_options_for_select_with_empty_collection
assert_equal '', principals_options_for_select([]) assert_equal '', principals_options_for_select([])
end end
def test_principals_options_for_select_should_include_me_option_when_current_user_is_in_collection
users = [User.find(2), User.find(4)]
User.current = User.find(4)
assert_include '<option value="4"><< me >></option>', principals_options_for_select(users)
end
end end