@@ -292,6 +292,20 module ApplicationHelper | |||||
292 | s |
|
292 | s | |
293 | end |
|
293 | end | |
294 |
|
294 | |||
|
295 | # Returns a string for users/groups option tags | |||
|
296 | def principals_options_for_select(collection, selected=nil) | |||
|
297 | s = '' | |||
|
298 | groups = '' | |||
|
299 | collection.sort.each do |element| | |||
|
300 | selected_attribute = ' selected="selected"' if option_value_selected?(element, selected) | |||
|
301 | (element.is_a?(Group) ? groups : s) << %(<option value="#{element.id}"#{selected_attribute}>#{h element.name}</option>) | |||
|
302 | end | |||
|
303 | unless groups.empty? | |||
|
304 | s << %(<optgroup label="#{h(l(:label_group_plural))}">#{groups}</optgroup>) | |||
|
305 | end | |||
|
306 | s | |||
|
307 | end | |||
|
308 | ||||
295 | # Truncates and returns the string as a single line |
|
309 | # Truncates and returns the string as a single line | |
296 | def truncate_single_line(string, *args) |
|
310 | def truncate_single_line(string, *args) | |
297 | truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') |
|
311 | truncate(string.to_s, *args).gsub(%r{[\r\n]+}m, ' ') |
@@ -2,5 +2,5 | |||||
2 |
|
2 | |||
3 | <div class="box"> |
|
3 | <div class="box"> | |
4 | <p><%= f.text_field :name, :size => 30, :required => true %></p> |
|
4 | <p><%= f.text_field :name, :size => 30, :required => true %></p> | |
5 |
<p><%= f.select :assigned_to_id, @project.assignable_users |
|
5 | <p><%= f.select :assigned_to_id, principals_options_for_select(@project.assignable_users, @category.assigned_to), :include_blank => true %></p> | |
6 | </div> |
|
6 | </div> |
@@ -39,7 +39,7 | |||||
39 | <label><%= l(:field_assigned_to) %></label> |
|
39 | <label><%= l(:field_assigned_to) %></label> | |
40 | <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') + |
|
40 | <%= select_tag('assigned_to_id', content_tag('option', l(:label_no_change_option), :value => '') + | |
41 | content_tag('option', l(:label_nobody), :value => 'none') + |
|
41 | content_tag('option', l(:label_nobody), :value => 'none') + | |
42 |
|
|
42 | principals_options_for_select(@target_project.assignable_users)) %> | |
43 | </p> |
|
43 | </p> | |
44 | </div> |
|
44 | </div> | |
45 |
|
45 |
@@ -8,7 +8,7 | |||||
8 | <% end %> |
|
8 | <% end %> | |
9 |
|
9 | |||
10 | <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %></p> |
|
10 | <p><%= f.select :priority_id, (@priorities.collect {|p| [p.name, p.id]}), {:required => true}, :disabled => !@issue.leaf? %></p> | |
11 |
<p><%= f.select :assigned_to_id, (@issue.assignable_users |
|
11 | <p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true %></p> | |
12 | <% unless @project.issue_categories.empty? %> |
|
12 | <% unless @project.issue_categories.empty? %> | |
13 | <p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> |
|
13 | <p><%= f.select :category_id, (@project.issue_categories.collect {|c| [c.name, c.id]}), :include_blank => true %> | |
14 | <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), |
|
14 | <%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'), |
@@ -1,7 +1,7 | |||||
1 | <div class="attributes"> |
|
1 | <div class="attributes"> | |
2 | <div class="splitcontentleft"> |
|
2 | <div class="splitcontentleft"> | |
3 | <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p> |
|
3 | <p><%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), :required => true %></p> | |
4 |
<p><%= f.select :assigned_to_id, (@issue.assignable_users |
|
4 | <p><%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to), :include_blank => true %></p> | |
5 | </div> |
|
5 | </div> | |
6 | <div class="splitcontentright"> |
|
6 | <div class="splitcontentright"> | |
7 | <% if Issue.use_field_for_done_ratio? %> |
|
7 | <% if Issue.use_field_for_done_ratio? %> |
@@ -27,7 +27,7 | |||||
27 | <label><%= l(:field_assigned_to) %></label> |
|
27 | <label><%= l(:field_assigned_to) %></label> | |
28 | <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') + |
|
28 | <%= select_tag('issue[assigned_to_id]', content_tag('option', l(:label_no_change_option), :value => '') + | |
29 | content_tag('option', l(:label_nobody), :value => 'none') + |
|
29 | content_tag('option', l(:label_nobody), :value => 'none') + | |
30 |
|
|
30 | principals_options_for_select(@assignables)) %> | |
31 | </p> |
|
31 | </p> | |
32 | <% if @project %> |
|
32 | <% if @project %> | |
33 | <p> |
|
33 | <p> |
@@ -675,4 +675,27 RAW | |||||
675 | assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>), |
|
675 | assert_equal %(<a href="/projects/ecookbook/settings" class="project">eCookbook</a>), | |
676 | link_to_project(project, {:action => 'settings'}, :class => "project") |
|
676 | link_to_project(project, {:action => 'settings'}, :class => "project") | |
677 | end |
|
677 | end | |
|
678 | ||||
|
679 | def test_principals_options_for_select_with_users | |||
|
680 | users = [User.find(2), User.find(4)] | |||
|
681 | assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>), | |||
|
682 | principals_options_for_select(users) | |||
|
683 | end | |||
|
684 | ||||
|
685 | def test_principals_options_for_select_with_selected | |||
|
686 | users = [User.find(2), User.find(4)] | |||
|
687 | assert_equal %(<option value="2">John Smith</option><option value="4" selected="selected">Robert Hill</option>), | |||
|
688 | principals_options_for_select(users, User.find(4)) | |||
|
689 | end | |||
|
690 | ||||
|
691 | def test_principals_options_for_select_with_users_and_groups | |||
|
692 | users = [User.find(2), Group.find(11), User.find(4), Group.find(10)] | |||
|
693 | assert_equal %(<option value="2">John Smith</option><option value="4">Robert Hill</option>) + | |||
|
694 | %(<optgroup label="Groups"><option value="10">A Team</option><option value="11">B Team</option></optgroup>), | |||
|
695 | principals_options_for_select(users) | |||
|
696 | end | |||
|
697 | ||||
|
698 | def test_principals_options_for_select_with_empty_collection | |||
|
699 | assert_equal '', principals_options_for_select([]) | |||
|
700 | end | |||
678 | end |
|
701 | end |
General Comments 0
You need to be logged in to leave comments.
Login now