Class: Caboose::VendorsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#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, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in

Instance Method Details

#admin_addObject

POST /admin/vendors



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

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

DELETE /admin/vendors/:id



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

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

GET /admin/vendors/:id



26
27
28
29
30
# File 'app/controllers/caboose/vendors_controller.rb', line 26

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

#admin_indexObject

GET /admin/vendors



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

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

GET /admin/vendors/new



63
64
65
66
# File 'app/controllers/caboose/vendors_controller.rb', line 63

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

#admin_updateObject

PUT /admin/vendors/:id/update



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/caboose/vendors_controller.rb', line 33

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

POST /admin/vendors/:id/update/image



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/caboose/vendors_controller.rb', line 50

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.attributes = { :image => { :value => vendor.image.url(:thumb) }}
  resp.success = vendor.save            
end

#status_optionsObject

GET /admin/vendors/status-options



95
96
97
98
99
100
101
# File 'app/controllers/caboose/vendors_controller.rb', line 95

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