Class: Caboose::SettingsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_ga_event, #admin_add, #admin_bulk_add, #admin_bulk_delete, #admin_bulk_update, #admin_delete, #admin_edit, #admin_index, #admin_json, #admin_json_single, #admin_update, #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

#before_actionObject


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

def before_action
  @page = Page.page_with_uri(request.host_with_port, '/admin')
end

#createObject


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

def create
  return if !user_is_allowed('settings', 'add')
  
  resp = StdClass.new({
      'error' => nil,
      'redirect' => nil
  })
  
  setting = Setting.new()
  setting.name  = params[:name]
  setting.value = params[:value]
  
  if (setting.name.strip.length == 0)
    resp.error = "The setting name is required."
  else      
    setting.save
    resp.redirect = "/admin/settings/#{setting.id}/edit"
  end
  render json: resp
end

#destroyObject


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

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

#editObject


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

def edit
  return if !user_is_allowed('settings', 'edit')
  @setting = Setting.find(params[:id])
end

#indexObject


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

def index
  return if !user_is_allowed('settings', 'view')
  
  @gen = PageBarGenerator.new(params, {
		  'name'        => nil,
		  'value'       => nil,
      'site_id'     => @site.id
		},{
		  'model'       => 'Caboose::Setting',
	    'sort'			  => 'name',
		  'desc'			  => false,
		  'base_url'		=> '/admin/settings',
		  'use_url_params' => false
	})
	@settings = @gen.items    	
end

#newObject


28
29
30
31
# File 'app/controllers/caboose/settings_controller.rb', line 28

def new
  return if !user_is_allowed('settings', 'add')
  @setting = Setting.new
end

#optionsObject


94
95
96
97
98
99
# File 'app/controllers/caboose/settings_controller.rb', line 94

def options
  return if !user_is_allowed('settings', 'view')
  settings = Setting.reorder('name').all
  options = settings.collect { |s| { 'value' => s.id, 'text' => s.name }}
  render json: options
end

#updateObject


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

def update
  return if !user_is_allowed('settings', 'edit')

  resp = StdClass.new     
  setting = Setting.find(params[:id])

  save = true
  params.each do |name,value|
    case name
	  	when "name"  then setting.name  = value
	  	when "value" then setting.value = value
	  end
	end
	
	resp.success = save && setting.save
	render :json => resp
end