Class: Comfy::Admin::Cms::PagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/comfy/admin/cms/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @page.save!
  flash[:success] = I18n.t('comfy.admin.cms.pages.created')
  redirect_to action: :edit, id: @page
rescue ActiveRecord::RecordInvalid
  flash.now[:danger] = I18n.t('comfy.admin.cms.pages.creation_failure')
  render action: :new
end

#destroyObject



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

def destroy
  @page.destroy
  flash[:success] = I18n.t('comfy.admin.cms.pages.deleted')
  redirect_to action: :index
end

#editObject



27
28
29
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 27

def edit
  render
end

#form_fragmentsObject



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

def form_fragments
  @page = @site.pages.find_by(id: params[:id]) || @site.pages.new
  @page.layout = @site.layouts.find_by(id: params[:layout_id])
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 9

def index
  return redirect_to action: :new if site_has_no_pages?

  return index_for_redactor if params[:source] == 'redactor'

  @pages_by_parent = pages_grouped_by_parent

  @pages = if params[:categories].present?
    @site.pages.includes(:categories).for_category(params[:categories]).order(:label)
  else
    [@site.pages.root].compact
  end
end

#newObject



23
24
25
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 23

def new
  render
end

#reorderObject



70
71
72
73
74
75
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 70

def reorder
  (params[:comfy_cms_page] || []).each_with_index do |id, index|
    ::Comfy::Cms::Page.where(id: id).update_all(position: index)
  end
  head :ok
end

#toggle_branchObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/comfy/admin/cms/pages_controller.rb', line 60

def toggle_branch
  @pages_by_parent = pages_grouped_by_parent
  @page = @site.pages.find(params[:id])
  s   = (session[:cms_page_tree] ||= [])
  id  = @page.id.to_s
  s.member?(id) ? s.delete(id) : s << id
rescue ActiveRecord::RecordNotFound
  # do nothing
end

#updateObject



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

def update
  @page.save!
  flash[:success] = I18n.t('comfy.admin.cms.pages.updated')
  redirect_to action: :edit, id: @page
rescue ActiveRecord::RecordInvalid
  flash.now[:danger] = I18n.t('comfy.admin.cms.pages.update_failure')
  render action: :edit
end