summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb14
-rw-r--r--app/views/issue_categories/_form.rhtml2
-rw-r--r--app/views/issue_moves/new.rhtml2
-rw-r--r--app/views/issues/_attributes.rhtml2
-rw-r--r--app/views/issues/_form_update.rhtml2
-rw-r--r--app/views/issues/bulk_edit.rhtml2
-rw-r--r--test/unit/helpers/application_helper_test.rb23
7 files changed, 42 insertions, 5 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a1832882e..6d5a058dc 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -291,6 +291,20 @@ module ApplicationHelper
end
s
end
+
+ # Returns a string for users/groups option tags
+ def principals_options_for_select(collection, selected=nil)
+ s = ''
+ groups = ''
+ collection.sort.each do |element|
+ selected_attribute = ' selected="selected"' if option_value_selected?(element, selected)
+ (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>)
+ end
+ unless groups.empty?
+ s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>)
+ end
+ s
+ end
# Truncates and returns the string as a single line
def truncate_single_line(string, *args)
diff --git a/app/views/issue_categories/_form.rhtml b/app/views/issue_categories/_form.rhtml
index fc5f158d3..fae0a75e5 100644
--- a/app/views/issue_categories/_form.rhtml
+++ b/app/views/issue_categories/_form.rhtml
@@ -2,5 +2,5 @@
<div class="box">
<p><%= f.text_field :name, :size => 30, :required => true %></p>
-<p><%= f.select :assigned_to_id, @project.assignable_users.sort.collect{|u| [u.name, u.id]}, :include_blank => true %></p>
+<p><%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %></p>
</div>
diff --git a/app/views/issue_moves/new.rhtml b/app/views/issue_moves/new.rhtml
index a8a053c4c..48d62da48 100644
--- a/app/views/issue_moves/new.rhtml
+++ b/app/views/issue_moves/new.rhtml
@@ -39,7 +39,7 @@
<label><%= l(:field_assigned_to) %></label>
<%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') +
content_tag('option', l(:label_nobody), :value => 'none') +
- options_from_collection_for_select(@target_project.assignable_users, :id, :name)) %>
+ principals_options_for_select(@target_project.assignable_users)) %>
</p>
</div>
diff --git a/app/views/issues/_attributes.rhtml b/app/views/issues/_attributes.rhtml
index 555a65653..e2d04ee51 100644
--- a/app/views/issues/_attributes.rhtml
+++ b/app/views/issues/_attributes.rhtml
@@ -8,7 +8,7 @@
<% end %>
<p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %></p>
-<p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
+<p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true %></p>
<% unless @project.issue_categories.empty? %>
<p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %>
<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
diff --git a/app/views/issues/_form_update.rhtml b/app/views/issues/_form_update.rhtml
index e29c41a7c..7c96317f7 100644
--- a/app/views/issues/_form_update.rhtml
+++ b/app/views/issues/_form_update.rhtml
@@ -1,7 +1,7 @@
<div class="attributes">
<div class="splitcontentleft">
<p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p>
-<p><%= f.select :assigned_to_id, (@issue.assignable_users.collect {|m| [m.name, m.id]}), :include_blank => true %></p>
+<p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true %></p>
</div>
<div class="splitcontentright">
<% if Issue.use_field_for_done_ratio? %>
diff --git a/app/views/issues/bulk_edit.rhtml b/app/views/issues/bulk_edit.rhtml
index eebce21b4..37b50ee86 100644
--- a/app/views/issues/bulk_edit.rhtml
+++ b/app/views/issues/bulk_edit.rhtml
@@ -27,7 +27,7 @@
<label><%= l(:field_assigned_to) %></label>
<%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') +
content_tag('option', l(:label_nobody), :value => 'none') +
- options_from_collection_for_select(@assignables, :id, :name)) %>
+ principals_options_for_select(@assignables)) %>
</p>
<% if @project %>
<p>
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 1d82dcb0e..d2e7cee62 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -675,4 +675,27 @@ RAW
assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>),
link_to_project(project, {:action => 'settings'}, :class => "project")
end
+
+ def test_principals_options_for_select_with_users
+ users = [User.find(2), User.find(4)]
+ assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>),
+ principals_options_for_select(users)
+ end
+
+ def test_principals_options_for_select_with_selected
+ users = [User.find(2), User.find(4)]
+ assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>),
+ principals_options_for_select(users, User.find(4))
+ end
+
+ def test_principals_options_for_select_with_users_and_groups
+ 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>) +
+ %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>),
+ principals_options_for_select(users)
+ end
+
+ def test_principals_options_for_select_with_empty_collection
+ assert_equal '', principals_options_for_select([])
+ end
end