Bladeren bron

Adds a optgroup for groups in users/groups select tags.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6307 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/1.3.0
Jean-Philippe Lang 13 jaren geleden
bovenliggende
commit
ed01ae121d

+ 14
- 0
app/helpers/application_helper.rb Bestand weergeven

@@ -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)

+ 1
- 1
app/views/issue_categories/_form.rhtml Bestand weergeven

@@ -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>

+ 1
- 1
app/views/issue_moves/new.rhtml Bestand weergeven

@@ -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>


+ 1
- 1
app/views/issues/_attributes.rhtml Bestand weergeven

@@ -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;'),

+ 1
- 1
app/views/issues/_form_update.rhtml Bestand weergeven

@@ -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? %>

+ 1
- 1
app/views/issues/bulk_edit.rhtml Bestand weergeven

@@ -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>

+ 23
- 0
test/unit/helpers/application_helper_test.rb Bestand weergeven

@@ -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

Laden…
Annuleren
Opslaan