Class: Cms::Admin::PagesController

Inherits:
BaseController show all
Includes:
Public::PagePaths, Public::PageRendering
Defined in:
app/controllers/cms/admin/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @page = current_site.pages.build(page_params)
  @translation_locale = requested_locale
  purge_media_if_requested(@page)

  if @page.save
    redirect_to admin_pages_path, notice: t("cms.notices.page_created")
  else
    @parent_options = parent_options_for(nil)
    render :new, status: :unprocessable_content
  end
end

#destroyObject



87
88
89
90
# File 'app/controllers/cms/admin/pages_controller.rb', line 87

def destroy
  @page.discard!
  redirect_to admin_pages_path, notice: t("cms.notices.page_deleted")
end

#editObject



55
56
57
58
59
# File 'app/controllers/cms/admin/pages_controller.rb', line 55

def edit
  @translation_locale = requested_locale
  @page.page_translations.find_or_initialize_by(locale: @translation_locale)
  @parent_options = parent_options_for(@page)
end

#indexObject



17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/cms/admin/pages_controller.rb', line 17

def index
  pages = current_site.pages.kept.includes(:localised).ordered.to_a
  depths = page_depths(pages)

  @page_rows = if params[:q].present?
                 matching_page_rows(pages, depths)
               else
                 flattened_page_rows(pages)
               end
end

#newObject



48
49
50
51
52
53
# File 'app/controllers/cms/admin/pages_controller.rb', line 48

def new
  @page = current_site.pages.build
  @translation_locale = requested_locale
  @page.page_translations.build(locale: @translation_locale)
  @parent_options = parent_options_for(nil)
end

#previewObject



39
40
41
42
43
44
45
46
# File 'app/controllers/cms/admin/pages_controller.rb', line 39

def preview
  @translation_locale = requested_locale
  @page.page_translations.find_or_initialize_by(locale: @translation_locale)
  I18n.with_locale(@translation_locale) do
    assign_public_page(site: current_site, page: @page)
    render template: "cms/public/pages/show", layout: Cms.config.public_layout
  end
end

#showObject



28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/cms/admin/pages_controller.rb', line 28

def show
  @translation_locale = requested_locale
  @subpages = @page.subpages.sort_by { |page| [page.position || 0, page.id] }
  @page_sections = @page.page_sections.ordered.includes(:section)
  @available_sections = current_site.sections
                                    .kept
                                    .global
                                    .where.not(id: @page.section_ids)
                                    .ordered
end

#updateObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/cms/admin/pages_controller.rb', line 74

def update
  @translation_locale = requested_locale
  @page.assign_attributes(page_params)
  purge_media_if_requested(@page)

  if @page.save
    redirect_to admin_pages_path, notice: t("cms.notices.page_updated")
  else
    @parent_options = parent_options_for(@page)
    render :edit, status: :unprocessable_content
  end
end