diff --git a/app/controllers/manage_tags_controller.rb b/app/controllers/manage_tags_controller.rb
index cc65203..193c0ed 100644
--- a/app/controllers/manage_tags_controller.rb
+++ b/app/controllers/manage_tags_controller.rb
@@ -4,63 +4,65 @@ require 'extended_tag.rb'
class ManageTagsController < ApplicationController
# Index redirects to list action without modifing the url
def index
- list
- render :action => 'list'
+ redirect_to :action => 'list'
end
- # Lists the tags strting with the top tags or with the chidren of @parent if its provided
+ # Lists the tags starting with the top tags or with the chidren of @parent if its provided
def list
@parent = Tag.find(params[:parent]) if params[:parent]
- @tags = @parent ? @parent.children : Tag.find(:all).select{|t|!t.parent}
+ @tags = @parent ? @parent.children : Tag.roots
@pending_tags = Tag.find_pendings
end
- # Prompt to data for a new tag
+ # Prompt for data to a new tag
def new
- @parent_tags = Tag.find_all
+ @parent_tags = Tag.find(:all)
@tag = Tag.new
end
# Collects the data and creates a new tag with it
def create
@tag = Tag.new(params[:tag])
-
if @tag.save
flash[:notice] = _('Tag was successfully created.')
redirect_to :action => 'list'
else
+ @parent_tags = Tag.find(:all)
render :action => 'new'
end
end
# Prompt for modifications on the attributes of a tag
def edit
- @tag = Tag.original_find(params[:id])
- @parent_tags = Tag.find_all - @tag.descendents - [@tag]
+ @tag = Tag.find_with_pendings(params[:id])
+ @parent_tags = @tag.parents_candidates
end
# Do the modifications collected by edit
def update
- @tag = Tag.original_find(params[:id])
+ @tag = Tag.find_with_pendings(params[:id])
if @tag.update_attributes(params[:tag])
flash[:notice] = _('Tag was successfully updated.')
redirect_to :action => 'list'
else
+ @parent_tags = @tag.parents_candidates
render :action => 'edit'
end
end
- # Destroy a tag
+ # Destroy a tag and all its children
def destroy
- @tag = Tag.original_find(params[:id])
- @tag.destroy
+ @tag = Tag.find_with_pendings(params[:id])
+ if @tag.destroy
+ flash[:notice] = _('Tag was successfuly destroyed')
+ end
redirect_to :action => 'list'
end
+ # Approve a pending tag so now ita can be used to tag things
def approve
- @tag = Tag.original_find(params[:id])
- @tag.pending = false
- if @tag.save
+ @tag = Tag.find_with_pendings(params[:id])
+ if @tag.update_attribute(:pending, false)
flash[:notice] = _('Tag was successfuly approved')
redirect_to :action => 'list'
end
diff --git a/app/views/manage_tags/_form.rhtml b/app/views/manage_tags/_form.rhtml
index 44278db..3e36b02 100644
--- a/app/views/manage_tags/_form.rhtml
+++ b/app/views/manage_tags/_form.rhtml
@@ -1,3 +1,3 @@
Name: <%= text_field 'tag', 'name' %>
-Parent tag: <%= select_tag 'tag[parent_id]', [''] + @parent_tags.map {|pt|"'} %>
+Parent tag: <%= select_tag 'tag[parent_id]', [''] + @parent_tags.map {|pt|"'} %>
Pending: <%= check_box 'tag', 'pending' %>
diff --git a/app/views/manage_tags/edit.rhtml b/app/views/manage_tags/edit.rhtml
index 4cdb4ef..4bc8e04 100644
--- a/app/views/manage_tags/edit.rhtml
+++ b/app/views/manage_tags/edit.rhtml
@@ -1,7 +1,7 @@