Class: Caboose::ThemeFilesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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


11
12
13
14
15
16
17
18
19
# File 'app/controllers/caboose/theme_files_controller.rb', line 11

def admin_add
  return unless (user_is_allowed_to 'edit', 'theme_files')
  resp = Caboose::StdClass.new
  c = Caboose::ThemeFile.new
  c.nice_name = params[:nice_name]
  c.save
  resp.redirect = "/admin/theme-files/#{c.id}"
  render :json => resp
end

#admin_bulk_deleteObject


90
91
92
93
94
95
96
97
98
# File 'app/controllers/caboose/theme_files_controller.rb', line 90

def admin_bulk_delete
  return unless user_is_allowed_to 'delete', 'theme_files'
  params[:model_ids].each do |rc_id|
    prop = Caboose::ThemeFile.where(:id => rc_id).first
    prop.destroy
  end
  resp = Caboose::StdClass.new('success' => true)
  render :json => resp
end

#admin_deleteObject


101
102
103
104
105
106
107
# File 'app/controllers/caboose/theme_files_controller.rb', line 101

def admin_delete
  return unless user_is_allowed_to 'delete', 'theme_files'
  prop = Caboose::ThemeFile.find(params[:id])    
  resp = Caboose::StdClass.new('redirect' => "/admin/theme-files")
  prop.destroy
  render :json => resp
end

#admin_editObject


47
48
49
50
51
52
53
# File 'app/controllers/caboose/theme_files_controller.rb', line 47

def admin_edit
  if !user_is_allowed_to 'edit', 'theme_files'
    Caboose.log("invalid permissions")
  else
    @themefile = Caboose::ThemeFile.where(:id => params[:id]).first
  end
end

#admin_indexObject


6
7
8
# File 'app/controllers/caboose/theme_files_controller.rb', line 6

def admin_index
  return unless (user_is_allowed_to 'view', 'theme_files')            
end

#admin_jsonObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/caboose/theme_files_controller.rb', line 22

def admin_json 
  render :json => false and return if !user_is_allowed_to 'view', 'theme_files'
  pager = Caboose::Pager.new(params, {
    'nice_name_like' => ''
  }, {
    'model' => 'Caboose::ThemeFile',
    'sort'  => 'nice_name',
    'desc'  => 'false',
    'base_url' => '/admin/theme-files',
    'items_per_page' => 50
  })
  render :json => {
    :pager => pager,
    :models => pager.items
  } 
end

#admin_json_singleObject


40
41
42
43
44
# File 'app/controllers/caboose/theme_files_controller.rb', line 40

def admin_json_single
  render :json => false and return if !user_is_allowed_to 'edit', 'theme_files'
  prop = Caboose::ThemeFile.find(params[:id])
  render :json => prop
end

#admin_updateObject


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/caboose/theme_files_controller.rb', line 68

def admin_update
  return unless (user_is_allowed_to 'edit', 'theme_files')
  resp = Caboose::StdClass.new
  theme_files = params[:id] == 'bulk' ? params[:model_ids].collect{ |rid| Caboose::ThemeFile.find(rid) } : [Caboose::ThemeFile.find(params[:id])] 
  user = logged_in_user
  if user
    params.each do |k,v|
      case k
        when "filename" then theme_files.each { |r| r.filename = v }
        when "nice_name" then theme_files.each { |r| r.nice_name = v }
        when "default_included" then theme_files.each { |r| r.default_included = v }
      end
    end
    theme_files.each do |r|
      r.save
    end
    resp.success = true
  end
  render :json => resp
end

#admin_update_sassObject


56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/caboose/theme_files_controller.rb', line 56

def admin_update_sass
  return if !user_is_allowed('edit', 'theme_files')
  resp = StdClass.new  
  @themefile = ThemeFile.find(params[:id])
  @themefile.code = params['code']
  @themefile.save
  resp.success = true
  resp.message = "Code has been saved!"
  render :json => resp
end