Sha256: 6ce6b29ac4c706c7a409aaaab6efd62696b8fc57962ce94196ae1eac764699da

Contents?: true

Size: 1.79 KB

Versions: 61

Compression:

Stored size: 1.79 KB

Contents

module Pageflow
  class ChaptersController < Pageflow::ApplicationController
    respond_to :json

    before_action :authenticate_user!

    def create
      storyline = Storyline.find(params[:storyline_id])
      chapter = storyline.chapters.build(chapter_params)

      authorize!(:create, chapter)
      verify_edit_lock!(storyline.entry)
      chapter.save

      respond_with(chapter)
    end

    def scaffold
      storyline = Storyline.find(params[:storyline_id])
      chapter_scaffold = ChapterScaffold.build(storyline, chapter_params, depth: 'page')

      authorize!(:create, chapter_scaffold.to_model)
      verify_edit_lock!(storyline.entry)
      chapter_scaffold.save!

      respond_with(chapter_scaffold)
    end

    def update
      chapter = Chapter.find(params[:id])

      authorize!(:update, chapter)
      verify_edit_lock!(chapter.entry)
      chapter.update_attributes(chapter_params)

      respond_with(chapter)
    end

    def order
      storyline = Storyline.find(params[:storyline_id])
      entry = DraftEntry.new(storyline.entry)

      authorize!(:edit_outline, storyline.entry)
      verify_edit_lock!(storyline.entry)
      params.require(:ids).each_with_index do |id, index|
        entry.chapters.update(id, storyline_id: storyline.id, position: index)
      end

      head :no_content
    end

    def destroy
      chapter = Chapter.find(params[:id])

      authorize!(:destroy, chapter)
      verify_edit_lock!(chapter.entry)
      chapter.entry.snapshot(creator: current_user)

      chapter.destroy

      respond_with(chapter)
    end

    private

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

      params.require(:chapter)
        .permit(:position, :title)
        .merge(configuration: configuration)
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
pageflow-16.0.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.8.0 app/controllers/pageflow/chapters_controller.rb
pageflow-14.5.2 app/controllers/pageflow/chapters_controller.rb
pageflow-15.7.1 app/controllers/pageflow/chapters_controller.rb
pageflow-15.7.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.6.1 app/controllers/pageflow/chapters_controller.rb
pageflow-15.6.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.5.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.4.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.3.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.2.2 app/controllers/pageflow/chapters_controller.rb
pageflow-15.2.1 app/controllers/pageflow/chapters_controller.rb
pageflow-15.2.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.2 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.1 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.0.rc0 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.0.beta6 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.0.beta5 app/controllers/pageflow/chapters_controller.rb
pageflow-15.1.0.beta4 app/controllers/pageflow/chapters_controller.rb