Class: CamaleonCms::Admin::Posts::DraftsController

Inherits:
CamaleonCms::Admin::PostsController
  • Object
show all
Defined in:
app/controllers/camaleon_cms/admin/posts/drafts_controller.rb

Overview

Camaleon CMS is a content management system

Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify   it under the terms of the GNU Affero General Public License as  published by the Free Software Foundation, either version 3 of the  License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the  GNU Affero General Public License (GPLv3) for more details.

Instance Method Summary collapse

Instance Method Details

#createObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 16

def create
  if params[:post_id].present?
    @post_draft = CamaleonCms::Post.drafts.where(post_parent: params[:post_id]).first
    if @post_draft.present?
      @post_draft.set_option('draft_status', @post_draft.status)
      @post_draft.attributes = @post_data
    end
  end
  @post_draft = @post_type.posts.new(@post_data) unless @post_draft.present?
  r = {post: @post_draft, post_type: @post_type}; hooks_run("create_post_draft", r)
  if @post_draft.save(:validate => false)
    @post_draft.set_params(params[:meta], params[:field_options], @post_data[:keywords])
    msg = {draft: {id: @post_draft.id}, _drafts_path: cama_admin_post_type_draft_path(@post_type.id, @post_draft)}
    r = {post: @post_draft, post_type: ""}; hooks_run("created_post_draft", r)
  else
    msg = {error: @post_draft.errors.full_messages}
  end

  render json: msg
end

#destroyObject


51
52
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 51

def destroy
end

#indexObject


12
13
14
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 12

def index
  render json: @post_type
end

#updateObject


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/camaleon_cms/admin/posts/drafts_controller.rb', line 37

def update
  @post_draft = CamaleonCms::Post.drafts.find(params[:id])
  @post_draft.attributes = @post_data
  r = {post: @post_draft, post_type: @post_type}; hooks_run("update_post", r)
  if @post_draft.save(validate: false)
    @post_draft.set_params(params[:meta], params[:field_options], @post_data[:keywords])
    hooks_run("updated_post_draft", {post: @post_draft, post_type: ""})
    msg = {draft: {id: @post_draft.id}}
  else
    msg = {error: @post_draft.errors.full_messages}
  end
  render json: msg
end