cirandas.net

ref: master

app/controllers/themes_controller.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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
class ThemesController < ApplicationController

  before_filter :login_required
  before_filter :check_user_can_edit_appearance, :only => [:index]

  no_design_blocks

  # attr_reader :target

  def target
    @target
  end

  def index
    @environment = environment
    @themes = (environment.themes + Theme.approved_themes(target)).uniq(&:id).sort_by(&:name)

    @current_theme = target.theme

    @layout_templates = LayoutTemplate.all.reject{ |lt| lt.id == 'nosidebars' }
    @current_template = target.layout_template
  end

  def set
    target.update_theme(params[:id])
    redirect_to :action => 'index'
  end

  def unset
    if target.kind_of?(Environment)
      target.update_theme('default')
    else
      target.update_theme(nil)
    end
    redirect_to :action => 'index'
  end

  def set_layout_template
    target.update_layout_template(params[:id])
    redirect_to :action => 'index'
  end

  private

  def check_user_can_edit_appearance
    user_can_edit_appearance = user.is_admin?(environment) || environment.enabled?('enable_appearance')
    redirect_to request.referer || "/" unless user_can_edit_appearance
  end

end