Commit 86a8b05b24ee7ce48cc62f53d18a089c29154efa

Authored by AntonioTerceiro
1 parent 7c51138c

ActionItem70: enhancing categories_helper



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@542 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/environment_admin/categories_controller.rb
1 class CategoriesController < EnvironmentAdminController 1 class CategoriesController < EnvironmentAdminController
  2 +
  3 + helper :categories
  4 +
2 def index 5 def index
3 @categories = environment.top_level_categories 6 @categories = environment.top_level_categories
4 end 7 end
app/helpers/categories_helper.rb
1 module CategoriesHelper 1 module CategoriesHelper
  2 +
  3 + include GetText
  4 +
  5 + COLORS = [
  6 + [ N_('Do not display at the menu'), nil ],
  7 + [ N_('Blue'), 1 ],
  8 + [ N_('Red'), 2 ],
  9 + [ N_('Green'), 3 ],
  10 + [ N_('Orange'), 4 ],
  11 + ]
  12 +
2 def select_color_for_category 13 def select_color_for_category
3 if @category.top_level? 14 if @category.top_level?
4 - options = [  
5 - [ _('Do not display at the menu'), nil ],  
6 - [ _('Blue'), 1 ],  
7 - [ _('Red'), 2 ],  
8 - [ _('Green'), 3 ],  
9 - [ _('Orange'), 4 ],  
10 - ]  
11 - labelled_form_field(_('Display at the menu?'), select('category', 'display_color', options)) 15 + labelled_form_field(_('Display at the menu?'), select('category', 'display_color', CategoriesHelper::COLORS.map {|item| [gettext(item[0]), item[1]] }))
12 else 16 else
13 "" 17 ""
14 end 18 end
15 end 19 end
16 20
  21 + def display_color_for_category(category)
  22 + color = category.display_color
  23 + if color.nil?
  24 + ""
  25 + else
  26 + "[" + gettext(CategoriesHelper::COLORS.find {|item| item[1] == color}.first) + "]"
  27 + end
  28 + end
  29 +
17 end 30 end
app/views/categories/_category.rhtml
1 <li> 1 <li>
2 <div class='treeitem'> 2 <div class='treeitem'>
  3 + <%= display_color_for_category(category) %>
3 <%= category.name %> 4 <%= category.name %>
4 5
5 <div> 6 <div>