Class Admin::CategoriesController
In: app/controllers/admin/categories_controller.rb
Parent: Admin::BaseController

Methods

create   destroy   edit   edit_tags   index   new   sort   update  

Public Instance methods

[Source]

    # File app/controllers/admin/categories_controller.rb, line 27
27:   def create
28:     @page_title = "Nueva categoría"
29:     @category = @tree.categories.new(params[:category])
30:     if @category.parent
31:       @category.position = @category.parent.position + 1
32:     end
33:     
34:     respond_to do |format|
35:       if @category.save
36:         format.html { 
37:           flash[:notice] = 'category was successfully created.'
38:           redirect_to admin_tree_category_url(@tree, @category) 
39:         }
40:         format.js { 
41:           render :update do |page|
42:             if @category.parent
43:               page.replace_html "cat_#{@category.parent.id}", :partial => "category", :locals => {:category => @category.parent, :tree => @category.tree}
44:               page.replace_html "new_container#{@category.parent.id}", ""
45:             else
46:               page.insert_html :bottom, "categories", :partial => "category", :locals => {:category => @category, :tree => @category.tree}
47:               page.replace_html "new_container", ""
48:             end
49:             
50:             page.visual_effect :highlight, "cat_#{@category.id}"
51:             
52:           end
53:         }
54:       else
55:         format.html { render :action => "new" }
56:         format.js {
57:           render :update do |page|
58:             page.replace_html "new_container#{@category.parent_id}", :partial => "new", :object => @category
59:             page[:name_es].focus
60:           end
61:         }
62:       end
63:     end
64:   end

[Source]

     # File app/controllers/admin/categories_controller.rb, line 115
115:   def destroy
116:     @page_title = "Eliminar categoría"
117:     @category = Category.find(params[:id])
118:     if @category.destroy
119:       respond_to do |format|
120:         format.html { 
121:           flash[:notice] = 'La categoría se ha eliminado correctamente'
122:           redirect_to admin_tree_url(@tree) 
123:         }
124:         format.js {
125:           render :update do |page|
126:             page.visual_effect :fade, "cat_#{@category.id}"
127:           end
128:         }
129:       end
130:     else
131:       respond_to do |format|
132:         format.html { 
133:           flash[:error] = 'La categoría NO se ha eliminado correctamente'
134:           redirect_to admin_tree_url(@tree) 
135:         }
136:         format.js {
137:           render :update do |page|
138:             page.alert 'La categoría NO se ha eliminado correctamente'
139:           end
140:         }
141:       end
142:     end
143:   end

[Source]

    # File app/controllers/admin/categories_controller.rb, line 66
66:   def edit
67:     @category = @tree.categories.find(params[:id])
68:     respond_to do |format|
69:       format.html {
70:         
71:       }
72:       format.js {
73:         render :update do |page| 
74:           page.replace_html "cat_#{params[:id].to_i}", :partial => 'edit'
75:           page[:name_es].focus
76:         end
77:       }
78:     end
79:   end

[Source]

     # File app/controllers/admin/categories_controller.rb, line 162
162:   def edit_tags
163:     @category= @tree.categories.find(params[:id])
164:     render :update do |page|
165:       page.replace_html "tags_#{@category.id}", :partial => "tags_form", :locals => { :category => @category}
166:       page[:category_tag_list].focus
167:     end
168:   end

cache_sweeper :category_sweeper, :only => [:create, :update, :destroy, :sort]

[Source]

    # File app/controllers/admin/categories_controller.rb, line 10
10:   def index
11:   end

[Source]

    # File app/controllers/admin/categories_controller.rb, line 13
13:   def new
14:     @category = @tree.categories.new
15:     @page_title = "Nueva categoría"
16:     respond_to do |format|
17:       format.html # show.rhtml
18:       format.js {
19:         render :update do |page| 
20:           page.replace_html "new_container#{params[:parent_id]}", :partial => 'new'
21:           page[:name_es].focus
22:         end
23:       }
24:     end
25:   end

[Source]

     # File app/controllers/admin/categories_controller.rb, line 147
147:   def sort
148:     @page_title = "Reordenar categorías"
149:     @categories = Category.find(:all, :conditions => {:tree_id => params[:tree_id], :parent_id => params[:parent_id]})
150:     # The parameter containing the items to be ordered has different name depending on the sublist
151:     # we are ordering. Its name always starts with "categories"
152:     order_param = params.keys.select {|k| k =~ /categories/}[0]
153:     Category.transaction do 
154:       @categories.each do |cat|
155:         cat.position = params[order_param].index(cat.id.to_s) + 1
156:         cat.save
157:       end
158:     end
159:     render :nothing => true
160:   end

[Source]

     # File app/controllers/admin/categories_controller.rb, line 81
 81:   def update
 82:     @category = @tree.categories.find(params[:id])
 83:     if @category.update_attributes(params[:category])
 84:       respond_to do |format|
 85:         format.html {
 86:           flash[:notice] = "La sección se ha actualizado correctamente"
 87:           redirect_to admin_tree_path(@tree)
 88:         }
 89:         format.js {
 90:           render :update do |page| 
 91:             if params[:category][:tag_list]
 92:               page.replace_html "tags_#{@category.id}", :partial => 'tags', :locals => { :category => @category}
 93:               page.visual_effect :highlight, "tags_#{@category.id}"
 94:             else
 95:               page.replace "cat_#{@category.id}", :partial => 'category', :object => @category
 96:               page.visual_effect :highlight, "cat_#{@category.id}"
 97:             end
 98:           end
 99:         }
100:       end
101:     else
102:       respond_to do |format|
103:         format.html {
104:           render :action => "edit"
105:         }
106:         format.js {
107:           render :update do |page| 
108:             page.insert_html :top, "cat_#{@category.id}", "<div class='flash_error'>la categoria no se ha actualizado</div>"
109:           end
110:         }
111:       end
112:     end
113:   end

[Validate]