From 7d32fc7088707175e64666ee672414d8020d086a Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 19 Jan 2009 11:47:02 -0800 Subject: [PATCH] Added a new helper to UsersHelper. * project_options_for_select doesn't allow setting the selected project so it is replaced with project_options_for_select_with_selected in the views #1914 --- app/views/rates/_form.html.erb | 2 +- lib/rate_users_helper_patch.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/views/rates/_form.html.erb b/app/views/rates/_form.html.erb index 5bf5dfe..77df412 100644 --- a/app/views/rates/_form.html.erb +++ b/app/views/rates/_form.html.erb @@ -15,7 +15,7 @@ <%= # TODO: move to controller once a hook is in place for the Admin panel projects = Project.find(:all, :conditions => { :status => Project::STATUS_ACTIVE}, :include => :parent) - select_tag("rate[project_id]", projects_options_for_select(projects)) + select_tag("rate[project_id]", project_options_for_select_with_selected(projects, @rate.project)) %> diff --git a/lib/rate_users_helper_patch.rb b/lib/rate_users_helper_patch.rb index a0c48e9..8001bad 100644 --- a/lib/rate_users_helper_patch.rb +++ b/lib/rate_users_helper_patch.rb @@ -17,6 +17,20 @@ module RateUsersHelperPatch return tabs end + # Similar to +project_options_for_select+ but allows selecting the active value + def project_options_for_select_with_selected(projects, selected = nil) + options = content_tag('option', "--- #{l(:actionview_instancetag_blank_option)} ---") + projects_by_root = projects.group_by(&:root) + projects_by_root.keys.sort.each do |root| + options << content_tag('option', h(root.name), :value => root.id, :disabled => (!projects.include?(root)), :selected => root == selected) + projects_by_root[root].sort.each do |project| + next if project == root + options << content_tag('option', '» ' + h(project.name), :value => project.id, :selected => project == selected) + end + end + options + end + end end