Class: Kuhsaft::Cms::PagesController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/kuhsaft/cms/pages_controller.rb

Instance Method Summary collapse

Methods inherited from AdminController

#default_url_options, #set_content_locale

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 22

def create
  @page = Kuhsaft::Page.create(page_params)

  if @page.valid?
    flash[:success] = t('layouts.kuhsaft.cms.flash.success', subject: Kuhsaft::Page.model_name.human)
    respond_with @page, location: kuhsaft.edit_cms_page_path(@page)
  else
    render 'new'
  end
end

#destroyObject



50
51
52
53
54
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 50

def destroy
  @page = Kuhsaft::Page.find(params[:id])
  @page.destroy
  redirect_to kuhsaft.cms_pages_path
end

#editObject



33
34
35
36
37
38
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 33

def edit
  @page = Kuhsaft::Page.find(params[:id])
  @page.published ||= Kuhsaft::PublishState::UNPUBLISHED
  @page.bricks.each { |brick| brick.valid? }
  respond_with @page
end

#indexObject



6
7
8
9
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 6

def index
  @pages = Kuhsaft::Page.roots
  respond_with @pages
end

#mirrorObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 60

def mirror
  @page = Kuhsaft::Page.find(params[:page_id])

  unless @page.bricks.empty?
    if params[:rutheless] == 'true' || @page.bricks.unscoped.where(locale: params[:target_locale]).empty?
      @page.clear_bricks_for_locale(params[:target_locale])
      params[:failed_bricks] = @page.clone_bricks_to(params[:target_locale])
      params[:rutheless] = 'true'
    end
  end

  respond_to :js, :html
end

#newObject



16
17
18
19
20
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 16

def new
  @page = Kuhsaft::Page.new
  @page.published ||= Kuhsaft::PublishState::UNPUBLISHED
  respond_with @page
end

#showObject



11
12
13
14
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 11

def show
  @page = Kuhsaft::Page.find(params[:id])
  respond_with @page
end

#sortObject



56
57
58
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 56

def sort
  Kuhsaft::PageTree.update(params[:page_tree])
end

#updateObject



40
41
42
43
44
45
46
47
48
# File 'app/controllers/kuhsaft/cms/pages_controller.rb', line 40

def update
  @page = Kuhsaft::Page.find(params[:id])
  if @page.update_attributes(page_params)
    flash[:success] = t('layouts.kuhsaft.cms.flash.success', subject: Kuhsaft::Page.model_name.human)
    respond_with @page, location: kuhsaft.edit_cms_page_path(@page)
  else
    render 'edit'
  end
end