Sha256: 6f83921f4a1f1715a0d4db38c42c0d09d89df46094867adfdbaf9b8a4b06d8a7

Contents?: true

Size: 1.91 KB

Versions: 18

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Spotlight
  ##
  # CRUD actions for about pages and contacts
  class AboutPagesController < PagesController
    load_and_authorize_resource through: :exhibit, instance_name: 'page'
    before_action :attach_breadcrumbs, except: [:update_contacts]

    # We're oddly getting an unknown action
    # error w/o explicitly defining this here
    def clone
      super
    end

    def update_contacts
      if @exhibit.update(contact_params)
        redirect_to exhibit_about_pages_path(@exhibit), notice: t(:'helpers.submit.contact.batch_updated')
      else
        render action: 'index'
      end
    end

    protected

    def attach_breadcrumbs
      super
      if @page
        attach_section_breadcrumbs
        attach_page_breadcrumbs
      elsif action_name == 'index'
        add_breadcrumb t(:'spotlight.curation.sidebar.header'), exhibit_dashboard_path(@exhibit)
        add_breadcrumb t(:'spotlight.pages.index.about_pages.header'), exhibit_about_pages_path(@exhibit)
      end
    end

    def attach_page_breadcrumbs
      return if @page == @exhibit.main_about_page

      if action_name == 'edit'
        add_breadcrumb @page.title, [:edit, @page.exhibit, @page]
      else
        add_breadcrumb @page.title, [@page.exhibit, @page]
      end
    end

    def attach_section_breadcrumbs
      if action_name == 'edit'
        add_breadcrumb t(:'spotlight.pages.index.about_pages.header'), exhibit_about_pages_path(@exhibit)
      else
        add_breadcrumb(@exhibit.main_navigations.about.label_or_default, [spotlight, @exhibit, @exhibit.main_about_page])
      end
    end

    def contact_params
      params.require(:exhibit).permit('contacts_attributes' => [:id, :show_in_sidebar, :weight])
    end

    def update_all_page_params
      params.require(:exhibit).permit('about_pages_attributes' => page_attributes)
    end

    def allowed_page_params
      super.concat [:published]
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.alpha.2 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-3.0.0.alpha.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.13.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.12.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.12.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.11.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.10.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.9.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.8.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.7.2 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.7.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.7.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.6.1.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.6.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.6.0 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.5.2 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.5.1 app/controllers/spotlight/about_pages_controller.rb
blacklight-spotlight-2.5.0 app/controllers/spotlight/about_pages_controller.rb