Class: Caboose::StackableGroupsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_update, #admin_edit, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #under_construction_or_forwarding_domain?, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_addObject


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 60

def admin_add
  return if !user_is_allowed('products', 'add')
  
  resp = Caboose::StdClass.new      
  name = params[:name]
  
  if name.length == 0
    resp.error = "The title cannot be empty."
  elsif StackableGroup.where(:name => name).exists?
    resp.error = "A stackable group with that name already exists."
  else
    sg = StackableGroup.new(:name => name)
    sg.save
    resp.refresh = true
  end
  render :json => resp    
end

#admin_bulk_deleteObject


87
88
89
90
91
92
93
94
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 87

def admin_bulk_delete
  return if !user_is_allowed('products', 'delete')
  params[:model_ids].each do |sg_id|
    sg = StackableGroup.where(:id => sg_id).first
    sg.destroy if sg
  end          
  render :json => { :success => true }
end

#admin_deleteObject


79
80
81
82
83
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 79

def admin_delete
  return if !user_is_allowed('products', 'delete')
  StackableGroup.find(params[:id]).destroy      
  render :json => true      
end

#admin_indexObject


5
6
7
8
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 5

def admin_index
  return if !user_is_allowed('products', 'view')      
  render :layout => 'caboose/admin'
end

#admin_jsonObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 11

def admin_json
  return if !user_is_allowed('products', 'view')
  
  pager = Caboose::PageBarGenerator.new(params, {
    'name'  => ''        
  }, {
    'model'          => 'Caboose::StackableGroup',
    'sort'           => 'name',
    'desc'           => false,
    'base_url'       => '/admin/stackable-groups',
    'items_per_page' => 25,
    'use_url_params' => false        
  })
  render :json => {
    :pager => pager,
    :models => pager.items
  }      
end

#admin_json_singleObject


31
32
33
34
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 31

def admin_json_single
  sg = StackableGroup.find(params[:id])
  render :json => sg      
end

#admin_optionsObject


98
99
100
101
102
103
104
105
106
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 98

def admin_options      
  options = StackableGroup.reorder(:name).all.collect do |sg|
    {
      :value => sg.id,
      :text => sg.name
    }
  end
  render :json => options
end

#admin_updateObject


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 37

def admin_update
  return if !user_is_allowed('products', 'edit')
  
  resp = Caboose::StdClass.new
  sg = StackableGroup.find(params[:id])    
  
  save = true    
  params.each do |name,value|
    case name
      when 'name'           then sg.name          = value
      when 'extra_length'   then sg.extra_length  = value.to_f
      when 'extra_width'    then sg.extra_width   = value.to_f
      when 'extra_height'   then sg.extra_height  = value.to_f
      when 'max_length'     then sg.max_length    = value.to_f
      when 'max_width'      then sg.max_width     = value.to_f
      when 'max_height'     then sg.max_height    = value.to_f                      
    end
  end
  resp.success = save && sg.save
  render :json => resp
end