Class: Spina::Admin::PagesController

Inherits:
AdminController show all
Defined in:
app/controllers/spina/admin/pages_controller.rb

Instance Method Summary collapse

Methods inherited from AdminController

#current_admin_path

Instance Method Details

#childrenObject



70
71
72
73
# File 'app/controllers/spina/admin/pages_controller.rb', line 70

def children
  @children = @page.children.active.sorted
  render layout: false
end

#createObject



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

def create
  @page = Page.new(page_params)
  add_breadcrumb I18n.t('spina.pages.new')
  if @page.save
    @page.navigations << Spina::Navigation.where(auto_add_pages: true)
    redirect_to spina.edit_admin_page_url(@page), flash: {success: t('spina.pages.saved')}
  else
    @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
    render :new, layout: 'spina/admin/admin'
  end
end

#destroyObject



75
76
77
78
# File 'app/controllers/spina/admin/pages_controller.rb', line 75

def destroy        
  @page.destroy
  redirect_to spina.admin_pages_url
end

#editObject



38
39
40
41
42
43
# File 'app/controllers/spina/admin/pages_controller.rb', line 38

def edit        
  add_index_breadcrumb
  add_breadcrumb @page.title
  @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
  render layout: 'spina/admin/admin'
end

#indexObject



8
9
10
11
12
# File 'app/controllers/spina/admin/pages_controller.rb', line 8

def index
  add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
  redirect_to admin_pages_path unless current_admin_path.starts_with?('/pages')
  @pages = Page.active.sorted.roots.regular_pages
end

#newObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spina/admin/pages_controller.rb', line 14

def new
  @resource = Resource.find_by(id: params[:resource_id])
  @page = Page.new(resource: @resource, parent: Page.find_by(id: params[:parent_id]) || @resource&.parent_page)
  add_index_breadcrumb
  if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] }
    @page.view_template = params[:view_template]
  end
  add_breadcrumb I18n.t('spina.pages.new')
  @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
  render layout: 'spina/admin/admin'
end

#sortObject



62
63
64
65
66
67
68
# File 'app/controllers/spina/admin/pages_controller.rb', line 62

def sort
  params[:list].each_pair do |parent_pos, parent_node|
    update_child_pages_position(parent_node)
    update_page_position(parent_node, parent_pos, nil)
  end
  head :ok
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/spina/admin/pages_controller.rb', line 45

def update 
  respond_to do |format|
    Mobility.locale = @locale
    if @page.update(page_params)
      @page.touch
      format.html { redirect_to spina.edit_admin_page_url(@page, params: {locale: @locale}), flash: {success: t('spina.pages.saved')} }
      format.js
    else
      format.html do
        @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
        Mobility.locale = I18n.default_locale
        render :edit, layout: 'spina/admin/admin'
      end
    end
  end
end