Class: Caboose::ModificationValueInputFieldsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #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/:mod_id/values/:mod_value_id/input-fields


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 53

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."
  elsif ModificationValueInputField.where(:modification_value_id => params[:mod_value_id], :name => name).exists?
    resp.error = "An input field with that name already exists for this modification value."
  else
    last_ip = ModificationValueInputField.where(:modification_value_id => params[:mod_value_id]).reorder("sort_order desc").limit(1).first
    sort_order = last_ip ? last_ip.sort_order + 1 : 0
    ip = ModificationValueInputField.new(:modification_value_id => params[:mod_value_id], :name => name, :sort_order => sort_order)                  
    ip.save
    resp.success = true        
  end
  render :json => resp    
end

#admin_deleteObject

DELETE /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/:id


74
75
76
77
78
79
80
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 74

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

#admin_editObject

GET /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/:id


19
20
21
22
23
24
25
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 19

def admin_edit
  return if !user_is_allowed('products', 'edit')
  @product = Product.find(params[:product_id])
  @modification = Modification.find(params[:mod_id])
  @modification_value_input_field = ModificationValueInputField.find(params[:id])
  render :layout => 'caboose/modal'
end

#admin_field_type_optionsObject

PUT /admin/products/modifications/values/input-fields/field-type-options


93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 93

def admin_field_type_options
  render :json => [      
    { :value => 'color'       , :text => 'Color'      },        
    { :value => 'checkbox'    , :text => 'Checkbox'   }, 
    { :value => 'date'        , :text => 'Date'       },
    { :value => 'time'        , :text => 'Time'       },
    { :value => 'date_time'   , :text => 'Date/Time'  },  
    { :value => 'select'      , :text => 'Select'     },
    { :value => 'text'        , :text => 'Text'       },
    { :value => 'textarea'    , :text => 'Textarea'   }
  ]
end

#admin_jsonObject

GET /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/json


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

def admin_json
  return if !user_is_allowed('products', 'view')
  
  mv = ModificationValue.find(params[:mod_value_id])
  render :json => mv.input_fields            
end

#admin_json_singleObject

GET /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/:id/json


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

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

#admin_updateObject

PUT /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/:id


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 28

def admin_update
  return if !user_is_allowed('products', 'edit')
  
  resp = Caboose::StdClass.new
  ip = ModificationValueInputField.find(params[:id])    
  
  save = true    
  params.each do |name,value|
    case name                        
      when 'sort_order'    then ip.sort_order     = value 
      when 'name'          then ip.name           = value
      when 'description'   then ip.description    = value
      when 'field_type'    then ip.field_type     = value
      when 'default_value' then ip.default_value  = value                                              
      when 'width'         then ip.width          = value
      when 'height'        then ip.height         = value
      when 'options'       then ip.options        = value
      when 'options_url'   then ip.options_url    = value
    end
  end
  resp.success = save && ip.save
  render :json => resp
end

#admin_update_sort_orderObject

PUT /admin/products/:product_id/modifications/:mod_id/values/:mod_value_id/input-fields/sort-order


83
84
85
86
87
88
89
90
# File 'app/controllers/caboose/modification_value_input_fields_controller.rb', line 83

def admin_update_sort_order            
  params[:input_field_ids].each_with_index do |ip_id, i|
    ip = ModificationValueInputField.where(:id => ip_id).first
    ip.sort_order = i
    ip.save
  end      
  render :json => { :success => true }
end