Commit c2a63906deef02eee63f1befccf9dc68a5afce86
1 parent
288990c5
Exists in
master
and in
29 other branches
ActionItem4: Added edit and destroy tags
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@45 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
4 changed files
with
28 additions
and
7 deletions
Show diff stats
app/controllers/manage_tags_controller.rb
| @@ -9,7 +9,7 @@ class ManageTagsController < ApplicationController | @@ -9,7 +9,7 @@ class ManageTagsController < ApplicationController | ||
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | def new | 11 | def new |
| 12 | - @tags = Tag.find_all | 12 | + @parent_tags = Tag.find_all |
| 13 | @tag = Tag.new | 13 | @tag = Tag.new |
| 14 | end | 14 | end |
| 15 | 15 | ||
| @@ -24,4 +24,27 @@ class ManageTagsController < ApplicationController | @@ -24,4 +24,27 @@ class ManageTagsController < ApplicationController | ||
| 24 | render :action => 'new' | 24 | render :action => 'new' |
| 25 | end | 25 | end |
| 26 | end | 26 | end |
| 27 | + | ||
| 28 | + def edit | ||
| 29 | + @parent_tags = Tag.find_all | ||
| 30 | + @tag = Tag.find(params[:id]) | ||
| 31 | + end | ||
| 32 | + | ||
| 33 | + def update | ||
| 34 | + @tag = Tag.find(params[:id]) | ||
| 35 | + @tag.name = params[:tag][:name] | ||
| 36 | + @tag.parent = params[:parent_id] != "0" ? Tag.find(params[:parent_id].to_i) : nil | ||
| 37 | + if @tag.save | ||
| 38 | + flash[:notice] = _('Tag was successfully updated.') | ||
| 39 | + redirect_to :action => 'list' | ||
| 40 | + else | ||
| 41 | + render :action => 'edit' | ||
| 42 | + end | ||
| 43 | + end | ||
| 44 | + | ||
| 45 | + def destroy | ||
| 46 | + @tag = Tag.find(params[:id]) | ||
| 47 | + @tag.destroy | ||
| 48 | + redirect_to :action => 'list' | ||
| 49 | + end | ||
| 27 | end | 50 | end |
app/views/manage_tags/_form.rhtml
| 1 | - | ||
| 2 | Name: <%= text_field 'tag', 'name' %> <br> | 1 | Name: <%= text_field 'tag', 'name' %> <br> |
| 3 | -Parent tag: <%= select_tag 'parent_id', ['<option value="0"></option>'] + @tags.map {|n|"<option value=\"#{n.id}\">" + n.name + '</option>'} %> <br> | 2 | +Parent tag: <%= select_tag 'parent_id', ['<option value="0"></option>'] + @parent_tags.select{|pt| !pt.ancestors.include?(@tag) and pt != @tag}.map {|n|"<option value=\"#{n.id}\" #{'selected="selected"' if @tag.parent == n} >" + n.name + '</option>'} %> <br> |
app/views/manage_tags/list.rhtml
| 1 | <h2> <%= _("Listing tags") %> </h2> | 1 | <h2> <%= _("Listing tags") %> </h2> |
| 2 | 2 | ||
| 3 | <ul> | 3 | <ul> |
| 4 | - <% @tags.select{|t| !t.parent }.each do |a_tag| %> | ||
| 5 | - <%= render :partial => 'list', :locals => {:a_tag => a_tag} %> | ||
| 6 | - <% end %> | 4 | + <%= render :partial => 'a_tag', :collection => @tags.select{|t|!t.parent} %> |
| 7 | </ul> | 5 | </ul> |
| 8 | 6 | ||
| 9 | <%= link_to _('New tag'), {:action => 'new'} %> | 7 | <%= link_to _('New tag'), {:action => 'new'} %> |
app/views/manage_tags/new.rhtml
| @@ -2,5 +2,6 @@ | @@ -2,5 +2,6 @@ | ||
| 2 | 2 | ||
| 3 | <%= start_form_tag :action =>'create' %> | 3 | <%= start_form_tag :action =>'create' %> |
| 4 | <%= render :partial => 'form' %> | 4 | <%= render :partial => 'form' %> |
| 5 | - <%= submit_tag 'Create' %> | 5 | + <%= submit_tag _('Create') %> |
| 6 | + <%= link_to _('Cancel'), {:action => 'list'} %> | ||
| 6 | <%= end_form_tag %> | 7 | <%= end_form_tag %> |