diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 64b42698c1..efbef67f80 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -222,27 +222,29 @@ module ApplicationHelper end end - def project_tree_options_for_select(projects, options = {}, &_block) - Project.project_level_list(projects).map { |element| + def project_tree_options_for_select(projects, selected: nil, disabled: {}, &_block) + options = ''.html_safe + Project.project_level_list(projects).each do |element| + identifier = element[:project].id tag_options = { - value: h(element[:project].id), + value: h(identifier), title: h(element[:project].name), } - if options[:selected] == element[:project] || - (options[:selected].respond_to?(:include?) && - options[:selected].include?(element[:project])) - - tag_options[:selected] = 'selected' + if !selected.nil? && selected.id == identifier + tag_options[:selected] = true end - level_prefix = '' - level_prefix = (' ' * 3 * element[:level] + '» ').html_safe if element[:level] > 0 + tag_options[:disabled] = true if disabled.include? identifier + + content = ''.html_safe + content << (' ' * 3 * element[:level] + '» ').html_safe if element[:level] > 0 + content << element[:project].name - tag_options.merge!(yield(element[:project])) if block_given? + options << content_tag('option', content, tag_options) + end - content_tag('option', level_prefix + h(element[:project].name), tag_options) - }.join('').html_safe + options end # Yields the given block for each project with its level in the tree diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 0257b956be..b901cc969e 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -126,12 +126,11 @@ module UsersHelper end # Options for the new membership projects combo-box + # + # Disables projects the user is already member in def options_for_membership_project_select(user, projects) - options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---") - options << project_tree_options_for_select(projects) { |p| - { disabled: (user.projects.include?(p)) } - } - options + options = project_tree_options_for_select(projects, disabled: user.projects.ids.to_set) + content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---") + options end def user_mail_notification_options(user)