Class: Caboose::MediaCategoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/media_categories_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_index, #admin_json, #admin_json_single, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_addObject

POST /admin/media-categories



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/caboose/media_categories_controller.rb', line 6

def admin_add
  return unless user_is_allowed('mediacategories', 'add')

  resp = Caboose::StdClass.new
  
  cat = MediaCategory.new(
    :site_id   => @site.id,
    :parent_id => params[:parent_id],
    :name      => params[:name]
  )      
  if !cat.save
    resp.error = cat.errors.first[1]
  else
    resp.refresh = true
  end
 
  render :json => resp
end

#admin_deleteObject

DELETE /admin/media-categories/:id



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/caboose/media_categories_controller.rb', line 44

def admin_delete
  return unless user_is_allowed('mediacategories', 'delete')
  cat = MediaCategory.find(params[:id])
  cat.destroy
  
  resp = StdClass.new({
    'redirect' => '/admin/media-categories'
  })
  render :json => resp
end

#admin_updateObject

PUT /admin/media-categories/:id



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/caboose/media_categories_controller.rb', line 26

def admin_update
  return unless user_is_allowed('mediacategories', 'edit')
  
  resp = StdClass.new
  cat = MediaCategory.find(params[:id])
  
  save = true      
  params.each do |name, value|
    case name          
      when 'name' then cat.name = value            
    end
  end

  resp.success = save && cat.save
  render :json => resp
end