Class: Spina::Admin::PagesController
- Inherits:
-
AdminController
- Object
- ActionController::Base
- Spina::ApplicationController
- AdminController
- Spina::Admin::PagesController
- Defined in:
- app/controllers/spina/admin/pages_controller.rb
Instance Method Summary collapse
- #children ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #update ⇒ Object
Methods inherited from AdminController
Instance Method Details
#children ⇒ Object
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 |
#create ⇒ Object
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) I18n.t('spina.pages.new') if @page.save @page. << 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 |
#destroy ⇒ Object
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 |
#edit ⇒ Object
38 39 40 41 42 43 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 38 def edit @page.title @page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) } render layout: 'spina/admin/admin' end |
#index ⇒ Object
8 9 10 11 12 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 8 def index 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 |
#new ⇒ Object
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) if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] } @page.view_template = params[:view_template] end 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 |
#sort ⇒ Object
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 |
#update ⇒ Object
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 |