Class: Caboose::VendorsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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



71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/caboose/vendors_controller.rb', line 71

def admin_add
  return if !user_is_allowed('vendors', 'add')
  
  render :json => { :success => false, :message => 'Must define a name' } and return if params[:name].nil? || params[:name].empty?
  
  vendor = Vendor.new(
    :site_id => @site.id,
    :name    => params[:name],
    :status  => 'Active'
  )      
  render :json => { :success => vendor.save, :redirect => "/admin/vendors/#{vendor.id}" }
end

#admin_deleteObject



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

def admin_delete      
  return if !user_is_allowed('vendors', 'delete')
  v = Vendor.find(params[:id])
  v.destroy
  
  resp = StdClass.new({
    'redirect' => '/admin/vendors'
  })
  render :json => resp
end

#admin_editObject



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

def admin_edit
  return if !user_is_allowed('vendors', 'edit')
  @vendor = Vendor.find(params[:id])
  render :layout => 'caboose/admin'
end

#admin_indexObject



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

def admin_index
  return if !user_is_allowed('vendors', 'view')
  
  @pager = Caboose::Pager.new(params, {
    'site_id'   => @site.id,
    'name_like' => ''
  }, {
    'model'          => 'Caboose::Vendor',
    'sort'           => 'name',
    'desc'           => false,
    'base_url'       => '/admin/vendors',
    'items_per_page' => 25,
    'use_url_params' => false
  });
  
  @vendors = @pager.items
  
  render :layout => 'caboose/admin'
end

#admin_newObject



34
35
36
37
# File 'app/controllers/caboose/vendors_controller.rb', line 34

def admin_new
  return if !user_is_allowed('vendors', 'add')
  render :layout => 'caboose/admin'
end

#admin_updateObject



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

def admin_update
  return if !user_is_allowed('vendors', 'edit')
  vendor = Vendor.find(params[:id])
  
  params.each do |name, value|
    case name
      when 'site_id'  then vendor.site_id  = value
      when 'name'     then vendor.name     = value
      when 'status'   then vendor.status   = value
      when 'featured' then vendor.featured = value
    end
  end
  
  render :json => { :success => vendor.save }
end

#admin_update_imageObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/caboose/vendors_controller.rb', line 40

def admin_update_image
  return if !user_is_allowed('vendors', 'edit')
  
  vendor = Vendor.find(params[:id])       
  vendor.image = params[:image]
  vendor.save
  
  resp = StdClass.new
  resp.success = true
  resp.attributes = { :image => { :value => vendor.image.url(:thumb) }}
  render :json => resp            
end

#optionsObject



99
100
101
# File 'app/controllers/caboose/vendors_controller.rb', line 99

def options      
  render :json => Vendor.where(:site_id => @site.id).reorder(:name).all.collect{ |v| { :value => v.id, :text => v.name }}      
end

#status_optionsObject



105
106
107
108
109
110
111
# File 'app/controllers/caboose/vendors_controller.rb', line 105

def status_options      
  render :json => [
    { :text => 'Active'   , :value => 'Active'   },
    { :text => 'Inactive' , :value => 'Inactive' },
    { :text => 'Deleted'  , :value => 'Deleted'  }
  ]      
end