Class: Caboose::ModificationsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_edit, #admin_index, #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

POST /admin/products/:product_id/modifications



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/caboose/modifications_controller.rb', line 36

def admin_add
  return if !user_is_allowed('products', 'add')
  
  resp = Caboose::StdClass.new
  name = params[:name]
        
  if name.length == 0
    resp.error = "The name cannot be empty."
  else
    m = Modification.new(:product_id => params[:product_id], :name => name)                  
    m.save
    resp.success = true        
  end
  render :json => resp    
end

#admin_deleteObject

DELETE /admin/products/:product_id/modifications/:id



53
54
55
56
57
58
59
# File 'app/controllers/caboose/modifications_controller.rb', line 53

def admin_delete
  return if !user_is_allowed('products', 'delete')
  m = Modification.find(params[:id]).destroy      
  render :json => Caboose::StdClass.new({
    :success => true
  })
end

#admin_jsonObject

GET /admin/products/:product_id/modifications/json



5
6
7
8
9
10
# File 'app/controllers/caboose/modifications_controller.rb', line 5

def admin_json
  return if !user_is_allowed('products', 'view')
  
  p = Product.find(params[:product_id])
  render :json => p.modifications.as_json(:include => :modification_values)            
end

#admin_json_singleObject

GET /admin/products/:product_id/modifications/:id/json



13
14
15
16
# File 'app/controllers/caboose/modifications_controller.rb', line 13

def admin_json_single
  m = Modification.find(params[:id])
  render :json => m.as_json(:include => :modification_values)      
end

#admin_updateObject

PUT /admin/products/:product_id/modifications/:id



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/caboose/modifications_controller.rb', line 19

def admin_update
  return if !user_is_allowed('products', 'edit')
  
  resp = Caboose::StdClass.new
  m = Modification.find(params[:id])    
  
  save = true    
  params.each do |name,value|
    case name          
      when 'name' then m.name = value                                    
    end
  end
  resp.success = save && m.save
  render :json => resp
end

#admin_update_sort_orderObject

PUT /admin/products/:product_id/modifications/sort-order



62
63
64
65
66
67
68
69
# File 'app/controllers/caboose/modifications_controller.rb', line 62

def admin_update_sort_order            
  params[:modification_ids].each_with_index do |mod_id, i|
    m = Modification.where(:id => mod_id).first
    m.sort_order = i
    m.save
  end      
  render :json => { :success => true }
end