From 86a8b05b24ee7ce48cc62f53d18a089c29154efa Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Tue, 25 Sep 2007 18:51:03 +0000 Subject: [PATCH] ActionItem70: enhancing categories_helper --- app/controllers/environment_admin/categories_controller.rb | 3 +++ app/helpers/categories_helper.rb | 29 +++++++++++++++++++++-------- app/views/categories/_category.rhtml | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/controllers/environment_admin/categories_controller.rb b/app/controllers/environment_admin/categories_controller.rb index 10aa268..3881e1d 100644 --- a/app/controllers/environment_admin/categories_controller.rb +++ b/app/controllers/environment_admin/categories_controller.rb @@ -1,4 +1,7 @@ class CategoriesController < EnvironmentAdminController + + helper :categories + def index @categories = environment.top_level_categories end diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 5a84fb1..9dea17d 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -1,17 +1,30 @@ module CategoriesHelper + + include GetText + + COLORS = [ + [ N_('Do not display at the menu'), nil ], + [ N_('Blue'), 1 ], + [ N_('Red'), 2 ], + [ N_('Green'), 3 ], + [ N_('Orange'), 4 ], + ] + def select_color_for_category if @category.top_level? - options = [ - [ _('Do not display at the menu'), nil ], - [ _('Blue'), 1 ], - [ _('Red'), 2 ], - [ _('Green'), 3 ], - [ _('Orange'), 4 ], - ] - labelled_form_field(_('Display at the menu?'), select('category', 'display_color', options)) + labelled_form_field(_('Display at the menu?'), select('category', 'display_color', CategoriesHelper::COLORS.map {|item| [gettext(item[0]), item[1]] })) else "" end end + def display_color_for_category(category) + color = category.display_color + if color.nil? + "" + else + "[" + gettext(CategoriesHelper::COLORS.find {|item| item[1] == color}.first) + "]" + end + end + end diff --git a/app/views/categories/_category.rhtml b/app/views/categories/_category.rhtml index dd7b29c..33f8541 100644 --- a/app/views/categories/_category.rhtml +++ b/app/views/categories/_category.rhtml @@ -1,5 +1,6 @@
  • + <%= display_color_for_category(category) %> <%= category.name %>
    -- libgit2 0.21.2