Sha256: 07320c1e63f8aef632b8befc40e821605da0a07e1279c90052a64373c7ad3708

Contents?: true

Size: 1.81 KB

Versions: 7

Compression:

Stored size: 1.81 KB

Contents

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

      def create
        chapter = Chapter.create(chapter_params.merge(revision: @entry.draft))

        render partial: 'pageflow_scrolled/chapters/chapter',
               locals: {chapter: chapter},
               status: :created
      end

      def update
        chapter = Chapter.all_for_revision(@entry.draft).find(params[:id])
        chapter.update_attributes(chapter_params)

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

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

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

      def order
        storyline = find_storyline
        chapters = Chapter.all_for_revision(@entry.draft)

        params.require(:ids).each_with_index do |id, index|
          chapters.update(id, storyline_id: storyline.id, position: index)
        end

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

      private

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

      def find_storyline
        if params[:storyline_id]
          Storyline.all_for_revision(@entry.draft).find(params[:storyline_id])
        else
          Storyline.all_for_revision(@entry.draft).first
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pageflow-15.2.2 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.2.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.2.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.1.2 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.1.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.1.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb
pageflow-15.1.0.rc0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/chapters_controller.rb