Class: Pulitzer::PostTypeVersionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pulitzer/post_type_versions_controller.rb

Defined Under Namespace

Classes: ChangeState, Clone, ClonePostWithVersionElements, Create, Export, ImportPost

Instance Method Summary collapse

Instance Method Details

#change_stateObject



28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 28

def change_state
  Pulitzer::PostTypeVersionsController::ChangeState.new(@post_type_version,params[:state_change]).call
  if @post_type_version.errors.empty?
    render partial: 'show', locals: {post_type_version: @post_type_version}
  else
    render json: {
      flash_message: @post_type_version.errors.full_messages.join('<br>'),
      html: render_to_string(partial: 'show', locals: {post_type_version: @post_type_version}) },
      status: :conflict
  end
end

#cloneObject



40
41
42
43
44
45
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 40

def clone
  post_type_version = Pulitzer::PostTypeVersionsController::Create.new(post_type_version_params, false).call
  post_type_version.processing!
  Pulitzer::ClonePostTypeVersion.perform_later(post_type_version)
  render_ajax locals: {post_type_version: post_type_version, post_type: post_type_version.post_type}
end

#createObject



10
11
12
13
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 10

def create
  @post_type_version = Create.new(post_type_version_params).call
  render partial: 'show_wrapper', locals: {post_type_version: @post_type_version}
end

#destroyObject



19
20
21
22
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 19

def destroy
  @post_type_version.destroy
  head :ok and return
end

#exportObject



47
48
49
50
51
52
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 47

def export
  post_type_version_json = Export.new(@post_type_version).call
  send_data(post_type_version_json,
    disposition: 'attachment',
    filename: @post_type_version.full_name.parameterize + '.json')
end

#import_postObject



54
55
56
57
58
59
60
61
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 54

def import_post
  @post = ImportPost.new(@post_type_version, post_type_version_params).call
  if @post.errors.empty?
    render partial: 'show', locals: {post_type_version: @post_type_version}
  else
    render json: {flash_message: "Error importing: #{@post.errors.full_messages}"}, status: 409
  end
end

#indexObject



4
5
6
7
8
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 4

def index
  @post_type = Pulitzer::PostType.find(params[:post_type_id])
  @post_type_versions = @post_type.post_type_versions
  render_ajax
end

#showObject



15
16
17
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 15

def show
  render partial: 'show', locals: {post_type_version: @post_type_version}
end

#templateObject



24
25
26
# File 'app/controllers/pulitzer/post_type_versions_controller.rb', line 24

def template
  render_ajax locals: {post_type_version: @post_type_version}
end