Class: Caboose::ThemesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/caboose/themes_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_index, #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_compileObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/caboose/themes_controller.rb', line 91

def admin_compile
  return if !user_is_allowed('theme', 'edit')
  resp = StdClass.new     
  theme = @site.theme
  if params['code']
    theme.custom_sass = params['code']
    theme.save
  elsif params['btsm_id']
    btsm = Caboose::BlockTypeSiteMembership.find(params['btsm_id'])
    btsm.custom_css = params['custom_css']
    btsm.save
  end
  theme.compile(@site.id) if Rails.env.development?
  theme.delay(:queue => 'general', :priority => 5).compile(@site.id) if Rails.env.production?
  resp.success = true
  resp.message = Rails.env.development? ? "Theme has been compiled!" : "Theme has been queued for compilation!"
  render :json => resp
end

#admin_editObject



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

def admin_edit
  return if !user_is_allowed('theme', 'edit')            
  @theme = @site.theme
  redirect_to '/admin' and return if @theme.nil?
end

#admin_sassObject



111
112
113
114
# File 'app/controllers/caboose/themes_controller.rb', line 111

def admin_sass
  return if !user_is_allowed('theme', 'edit')
  @theme = @site.theme
end

#admin_toggle_fileObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/controllers/caboose/themes_controller.rb', line 140

def admin_toggle_file
  resp = Caboose::StdClass.new
  checked = params[:checked]
  theme_id = params[:id]
  file_id = params[:file_id]
  if checked && checked != false && checked != 'false'
    am = Caboose::ThemeFileMembership.where(:theme_id => theme_id, :theme_file_id => file_id).first
    am = am ? am : Caboose::ThemeFileMembership.new
    am.theme_id = theme_id
    am.theme_file_id = file_id
    am.save
  else
    Caboose::ThemeFileMembership.delete_all(:theme_id => theme_id, :theme_file_id => file_id)
  end
  resp.success = "Success"
  render :json => resp
end

#admin_updateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/caboose/themes_controller.rb', line 13

def admin_update
  return if !user_is_allowed('theme', 'edit')
  resp = StdClass.new     
  theme = @site.theme
  save = true
  params.each do |name,value|
    case name
      when 'color_main'              then theme.color_main              = value
      when 'color_alt'                 then theme.color_alt                 = value
      when 'color_dark' then theme.color_dark = value
      when 'color_light' then theme.color_light = value
      when 'max_width' then theme.max_width = value
      when 'body_bg_color' then theme.body_bg_color = value
      when 'font_size' then theme.font_size = value
      when 'header_height' then theme.header_height = value
      when 'header_bg_color' then theme.header_bg_color = value
      when 'header_font_color' then theme.header_font_color = value
      when 'dropdown_color' then theme.dropdown_color = value
      when 'mobile_menu_bg_color' then theme.mobile_menu_bg_color = value
      when 'mobile_menu_font_color' then theme.mobile_menu_font_color = value
      when 'mobile_menu_border_color' then theme.mobile_menu_border_color = value
      when 'mobile_menu_icon_color' then theme.mobile_menu_icon_color = value
      when 'mobile_menu_icon_top' then theme.mobile_menu_icon_top = value
      when 'footer_height' then theme.footer_height = value
      when 'footer_bg_color' then theme.footer_bg_color = value
      when 'footer_font_color' then theme.footer_font_color = value
      when 'btn_border_radius' then theme.btn_border_radius = value
      when 'btn_border_width' then theme.btn_border_width = value
      when 'btn_border_color' then theme.btn_border_color = value
      when 'btn_font_color' then theme.btn_font_color = value
      when 'btn_font_size' then theme.btn_font_size = value
      when 'btn_font_weight' then theme.btn_font_weight = value
      when 'btn_font_case' then theme.btn_font_case = value
      when 'btn_border_side' then theme.btn_border_side = value
      when 'input_border_radius' then theme.input_border_radius = value
      when 'input_bg_color' then theme.input_bg_color = value
      when 'input_border_color' then theme.input_border_color = value
      when 'input_border_width' then theme.input_border_width = value
      when 'input_font_color' then theme.input_font_color = value
      when 'input_font_size' then theme.input_font_size = value
      when 'input_padding' then theme.input_padding = value

      when 'body_line_height' then theme.body_line_height = value
      when 'body_font_color' then theme.body_font_color = value
      when 'button_padding' then theme.button_padding = value
      when 'button_line_height' then theme.button_line_height = value
      when 'footer_padding' then theme.footer_padding = value
      when 'footer_font_size' then theme.footer_font_size = value
      when 'header_font_size' then theme.header_font_size = value
      when 'note_padding' then theme.note_padding = value
      when 'header_nav_spacing' then theme.header_nav_spacing = value
      when 'logo_width' then theme.logo_width = value
      when 'logo_height' then theme.logo_height = value
      when 'logo_top_padding' then theme.logo_top_padding = value
      when 'heading_line_height' then theme.heading_line_height = value
      when 'mobile_menu_nav_padding' then theme.mobile_menu_nav_padding = value
      when 'mobile_menu_font_size' then theme.mobile_menu_font_size = value
      when 'banner_padding' then theme.banner_padding = value
      when 'banner_overlay_color' then theme.banner_overlay_color = value
      when 'banner_overlay_opacity' then theme.banner_overlay_opacity = value
      when 'default_header_style' then theme.default_header_style = value
      when 'default_header_position' then theme.default_header_position = value
      when 'sidebar_width' then theme.sidebar_width = value
      when 'sidebar_bg_color' then theme.sidebar_bg_color = value

      when 'banner_font_size' then theme.banner_font_size = value
      when 'footer_hover_color' then theme.footer_hover_color = value
      when 'actual_footer_height' then theme.actual_footer_height = value
      when 'actual_banner_height' then theme.actual_banner_height = value
      when 'dropdown_nav_padding' then theme.dropdown_nav_padding = value

    end
  end
  resp.success = save && theme.save
  render :json => resp
end

#admin_update_default_banner_imageObject



129
130
131
132
133
134
135
136
137
# File 'app/controllers/caboose/themes_controller.rb', line 129

def admin_update_default_banner_image
  return if !user_is_allowed('theme', 'edit')
  resp = Caboose::StdClass.new
  theme = @site.theme
  theme.default_banner_image = params[:default_banner_image]            
  resp.success = theme.save
  resp.attributes = { 'default_banner_image' => { 'value' => theme.default_banner_image.url(:huge) }}
  render :text => resp.to_json
end

#admin_update_sassObject



117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/caboose/themes_controller.rb', line 117

def admin_update_sass
  return if !user_is_allowed('theme', 'edit')
  resp = StdClass.new  
  @theme = @site.theme
  @theme.custom_sass = params['code']
  @theme.save
  resp.success = true
  resp.message = "Theme has been saved!"
  render :json => resp
end