Sha256: b6e9000605a9284b9ee563496e8a73e7be0269ad911d45c322e8bd5950e1a877

Contents?: true

Size: 1.75 KB

Versions: 11

Compression:

Stored size: 1.75 KB

Contents

module PageflowScrolled
  module Editor
    # @api private
    class SectionsController < ActionController::Base
      include Pageflow::EditorController

      def create
        chapter = Chapter.all_for_revision(@entry.draft).find(params[:chapter_id])
        section = chapter.sections.create(section_params)

        render partial: 'pageflow_scrolled/sections/section',
               locals: {section: section},
               status: :created
      end

      def update
        section = Section.all_for_revision(@entry.draft).find(params[:id])
        section.update_attributes(section_params)

        render partial: 'pageflow_scrolled/sections/section', locals: {section: section}
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      def destroy
        section = Section.all_for_revision(@entry.draft).find(params[:id])
        section.destroy

        render partial: 'pageflow_scrolled/sections/section', locals: {section: section}
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      def order
        chapter = Chapter.all_for_revision(@entry.draft).find(params[:chapter_id])
        storyline = chapter.storyline

        params.require(:ids).each_with_index do |id, index|
          storyline.sections.update(id,
                                    chapter_id: chapter.id,
                                    position: index)
        end

        head :no_content
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      private

      def section_params
        configuration = params.require(:section)[:configuration].try(:permit!) || {}
        params.require(:section)
              .permit(:position)
              .merge(configuration: configuration)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
pageflow-15.2.2 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.2.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.2.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.2 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0.rc0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0.beta6 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0.beta5 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0.beta4 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.1.0.beta3 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb