Commit da92889479ab6b46c513662c1eb5a01d270f3ea4
1 parent
4004a064
Exists in
master
and in
29 other branches
ActionItem70: implemented categories
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@527 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
66 additions
and
10 deletions
Show diff stats
app/controllers/environment_admin/categories_controller.rb
... | ... | @@ -2,4 +2,41 @@ class CategoriesController < EnvironmentAdminController |
2 | 2 | def index |
3 | 3 | @categories = environment.top_level_categories |
4 | 4 | end |
5 | + | |
6 | + # posts back | |
7 | + def new | |
8 | + @category = Category.new(params[:category]) | |
9 | + @category.environment = environment | |
10 | + if params[:parent_id] | |
11 | + @category.parent = environment.categories.find(params[:parent_id]) | |
12 | + end | |
13 | + if request.post? | |
14 | + begin | |
15 | + @category.save! | |
16 | + redirect_to :action => 'index' | |
17 | + rescue Exception => e | |
18 | + render :action => 'new' | |
19 | + end | |
20 | + end | |
21 | + end | |
22 | + | |
23 | + # posts back | |
24 | + def edit | |
25 | + begin | |
26 | + @category = environment.categories.find(params[:id]) | |
27 | + if request.post? | |
28 | + @category.update_attributes!(params[:category]) | |
29 | + redirect_to :action => 'index' | |
30 | + end | |
31 | + rescue Exception => e | |
32 | + render :action => 'edit' | |
33 | + end | |
34 | + end | |
35 | + | |
36 | + post_only :remove | |
37 | + def remove | |
38 | + environment.categories.find(params[:id]).destroy | |
39 | + redirect_to :action => 'index' | |
40 | + end | |
41 | + | |
5 | 42 | end | ... | ... |
app/views/categories/_category.rhtml
1 | 1 | <li> |
2 | -<%= category.name %> | |
3 | -<div> | |
4 | - <%= link_to _('Add subcategory'), :action => 'new', :parent => category %> | |
5 | - <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :post => true, :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> | |
2 | +<div class='treeitem'> | |
3 | + <%= category.name %> | |
4 | + | |
5 | + <div> | |
6 | + <%= link_to _('Add subcategory'), :action => 'new', :parent_id => category %> | |
7 | + <%= link_to _('Edit'), :action => 'edit', :id => category %> | |
8 | + <%= link_to _('Remove'), { :action => 'remove', :id => category, }, :post => true, :confirm => (category.children.empty? ? (_('Are you sure you want to remove "%s"?') % category.name) : (_('Are you sure you want to remove "%s" and all its subcategories?') % category.name) ) %> | |
9 | + </div> | |
6 | 10 | </div> |
7 | -<% unless category.children.empty? %> | |
8 | - <ul> | |
9 | - <%= render :partial => 'category', :collection => category.children %> | |
10 | - </ul> | |
11 | -<% end %> | |
11 | + | |
12 | + <% unless category.children.empty? %> | |
13 | + <ul class='tree'> | |
14 | + <%= render :partial => 'category', :collection => category.children %> | |
15 | + </ul> | |
16 | + <% end %> | |
17 | + | |
12 | 18 | </li> |
19 | + | ... | ... |
app/views/categories/index.rhtml
public/stylesheets/common.css
... | ... | @@ -73,3 +73,15 @@ text-decoration: none !important ; |
73 | 73 | text-decoration: underline !important ; |
74 | 74 | } |
75 | 75 | |
76 | +ul.tree { | |
77 | + margin: 2px; | |
78 | + padding-left: 20px; | |
79 | +} | |
80 | + | |
81 | +ul.tree li { | |
82 | + list-style: none; | |
83 | +} | |
84 | + | |
85 | +ul.tree li div.treeitem:hover { | |
86 | + background: #f0f0f0; | |
87 | +} | ... | ... |