Class: Platform::Admin::CategoriesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/platform/admin/categories_controller.rb

Overview

– Copyright © 2011 Michael Berkovich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++

Instance Method Summary collapse

Instance Method Details

#assign_categoryObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/platform/admin/categories_controller.rb', line 82

def assign_category
  app = Platform::Application.find_by_id(params[:app_id])
  category = Platform::Category.find(params[:category_id])
  
  if params[:checked] == "true"
    cat = category
    while cat do
      app.add_category(cat) unless cat.root?
      cat = cat.parent
    end  
  else  
    app.remove_category(category)
  end
  app.reload
  
  render(:partial=>"/platform/admin/apps/categories", :locals => {:app => app})
end

#category_assignerObject



100
101
102
103
# File 'app/controllers/platform/admin/categories_controller.rb', line 100

def category_assigner
  @app = Platform::Application.find_by_id(params[:app_id])
  render :layout=>false
end

#category_assigner_treeObject



105
106
107
108
109
110
111
# File 'app/controllers/platform/admin/categories_controller.rb', line 105

def category_assigner_tree
  @app = Platform::Application.find_by_id(params[:app_id])
  @root_keyword = params[:root_keyword] || "root"
  @root = Platform::Category.find_by_keyword(@root_keyword)
  
  render :layout=>false
end

#delete_categoryObject



77
78
79
80
# File 'app/controllers/platform/admin/categories_controller.rb', line 77

def delete_category
  recursive_category_delete(params[:category_id])
  redirect_to :action => :index
end

#indexObject



26
27
28
29
30
# File 'app/controllers/platform/admin/categories_controller.rb', line 26

def index
  @root = Platform::Category.root
  @category =  Platform::Category.find(params[:category_id]) if params[:category_id]
  @category ||= @root
end

#itemsObject



39
40
41
42
43
44
45
46
# File 'app/controllers/platform/admin/categories_controller.rb', line 39

def items
  @parent = Platform::Category.find(params[:parent_id])
  @children = @parent.children
  @featured_apps = @parent.featured_application_categories
  @apps = @parent.regular_application_categories
  
  render  :layout => false
end

#lb_update_application_categoryObject



66
67
68
69
# File 'app/controllers/platform/admin/categories_controller.rb', line 66

def lb_update_application_category
  @app_cat = Platform::ApplicationCategory.find_by_category_id_and_application_id(params[:category_id], params[:app_id])
  render  :layout => false
end

#lb_update_categoryObject



48
49
50
51
52
53
# File 'app/controllers/platform/admin/categories_controller.rb', line 48

def lb_update_category
  @parent = Platform::Category.find(params[:parent_id]) if params[:parent_id]
  @category = Platform::Category.find(params[:category_id]) if params[:category_id]
  @category = Platform::Category.new(:parent_id=>params[:parent_id]) unless @category
  render  :layout => false
end

#treeObject



32
33
34
35
36
37
# File 'app/controllers/platform/admin/categories_controller.rb', line 32

def tree
  @root = Platform::Category.root
  @category =  Platform::Category.find(params[:category_id]) if params[:category_id]
  @category ||= @root
  render  :layout => false
end

#update_application_categoryObject



71
72
73
74
75
# File 'app/controllers/platform/admin/categories_controller.rb', line 71

def update_application_category
  app_cat = Platform::ApplicationCategory.find(params[:application_category][:id])
  app_cat.update_attributes(params[:application_category])
  redirect_to :action => :index, :category_id => app_cat.category.id
end

#update_categoryObject



55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/platform/admin/categories_controller.rb', line 55

def update_category
  if params[:category][:id] != "" 
    @category = Platform::Category.find(params[:category][:id])
    @category.update_attributes(params[:category])
  else
    @category = Platform::Category.create(params[:category])
  end
  
  redirect_to :action => :index, :category_id => @category.id
end


113
114
115
116
117
# File 'app/controllers/platform/admin/categories_controller.rb', line 113

def update_featured_flag
  app_cat = Platform::ApplicationCategory.find(params[:app_category_id])
  app_cat.update_attributes(:featured => params[:checked])
  render(:partial=>"/platform/admin/apps/categories", :locals => {:app => app_cat.application})
end