Class: CamaleonCms::Admin::PostsController
- Inherits:
-
CamaleonCms::AdminController
- Object
- CamaleonCms::AdminController
- CamaleonCms::Admin::PostsController
- Defined in:
- app/controllers/camaleon_cms/admin/posts_controller.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#ajax ⇒ Object
ajax options.
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #restore ⇒ Object
- #show ⇒ Object
- #trash ⇒ Object
- #update ⇒ Object
Instance Method Details
#ajax ⇒ Object
ajax options
147 148 149 150 151 152 153 154 155 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 147 def ajax json = {error: 'Not Found'} case params[:method] when 'exist_slug' slug = current_site.get_valid_post_slug(params[:slug].to_s, params[:post_id]) json = {slug: slug, index: 1} end render json: json end |
#create ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 65 def create :create_post, @post_type post_data = get_post_data(true) CamaleonCms::Post.drafts.find(post_data[:draft_id]).destroy rescue nil @post = @post_type.posts.new(post_data) r = {post: @post, post_type: @post_type}; hooks_run("create_post", r) @post = r[:post] if @post.save @post.(params[:meta]) @post.set_field_values(params[:field_options]) @post.(params[:options]) flash[:notice] = t('camaleon_cms.admin.post.message.created', post_type: @post_type.decorate.the_title) r = {post: @post, post_type: @post_type}; hooks_run("created_post", r) redirect_to action: :edit, id: @post.id else # render 'form' new end end |
#destroy ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 132 def destroy :destroy, @post r = {post: @post, post_type: @post_type, flag: true} hooks_run("destroy_post", r) if r[:flag] @post.destroy hooks_run("destroy_post", {post: @post, post_type: @post_type}) flash[:notice] = t('camaleon_cms.admin.post.message.deleted', post_type: @post_type.decorate.the_title) else # flash[:error] = t('camaleon_cms.admin.post.message.deleted') end redirect_to action: :index, s: params[:s] end |
#edit ⇒ Object
85 86 87 88 89 90 91 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 85 def edit I18n.t("camaleon_cms.admin.button.edit") :update, @post @post_form_extra_settings = [] r = {post: @post, post_type: @post_type, extra_settings: @post_form_extra_settings, render: "form"}; hooks_run("edit_post", r) render r[:render] end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 8 def index :posts, @post_type per_page = current_site.admin_per_page posts_all = @post_type.posts.eager_load(:parent, :post_type) if params[:taxonomy].present? && params[:taxonomy_id].present? if params[:taxonomy] == "category" cat_owner = current_site.full_categories.find(params[:taxonomy_id]).decorate posts_all = cat_owner.posts t("camaleon_cms.admin.post_type.category"), @post_type.the_admin_url("category") cat_owner.the_title, cat_owner.the_edit_url end if params[:taxonomy] == "post_tag" tag_owner = current_site..find(params[:taxonomy_id]).decorate posts_all = tag_owner.posts t("camaleon_cms.admin.post_type.tags"), @post_type.the_admin_url("tag") tag_owner.the_title, tag_owner.the_edit_url end end if params[:q].present? params[:q] = (params[:q] || '').downcase posts_all = posts_all.where("LOWER(#{CamaleonCms::Post.table_name}.title) LIKE ?", "%#{params[:q]}%") end @posts = posts_all params[:s] = 'published' unless params[:s].present? @lists_tab = params[:s] I18n.t("camaleon_cms.admin.post_type.#{params[:s]}") if params[:s].present? case params[:s] when "published", "pending", "draft", "trash" @posts = @posts.where(status: params[:s]) when "all" @posts = @posts.no_trash end @btns = {published: "#{t('camaleon_cms.admin.post_type.published')} (#{posts_all.where(status: "published").size})", all: "#{t('camaleon_cms.admin.post_type.all')} (#{posts_all.no_trash.size})", pending: "#{t('camaleon_cms.admin.post_type.pending')} (#{posts_all.where(status: "pending").size})", draft: "#{t('camaleon_cms.admin.post_type.draft')} (#{posts_all.where(status: "draft").size})", trash: "#{t('camaleon_cms.admin.post_type.trash')} (#{posts_all.where(status: "trash").size})"} r = {posts: @posts, post_type: @post_type, btns: @btns, all_posts: posts_all, render: 'index', per_page: per_page } hooks_run("list_post", r) per_page = 9999999 if @post_type.manage_hierarchy? @posts = r[:posts].paginate(:page => params[:page], :per_page => r[:per_page]) render r[:render] end |
#new ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 56 def new I18n.t("camaleon_cms.admin.button.new") :create_post, @post_type @post_form_extra_settings = [] @post ||= @post_type.posts.new r = {post: @post, post_type: @post_type, extra_settings: @post_form_extra_settings, render: "form"}; hooks_run("new_post", r) render r[:render] end |
#restore ⇒ Object
123 124 125 126 127 128 129 130 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 123 def restore @post = @post_type.posts.find(params[:post_id]) :update, @post @post.update_column('status', @post.[:status_default] || 'pending') @post.update_extra_data flash[:notice] = t('camaleon_cms.admin.post.message.restore', post_type: @post_type.decorate.the_title) redirect_to action: :index, s: params[:s] end |
#show ⇒ Object
53 54 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 53 def show end |
#trash ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 112 def trash @post = @post_type.posts.find(params[:post_id]) :destroy, @post @post.set_option('status_default', @post.status) # @post.children.destroy_all unless @post.draft? TODO: why delete children? @post.update_column('status', 'trash') @post.update_extra_data flash[:notice] = t('camaleon_cms.admin.post.message.trash', post_type: @post_type.decorate.the_title) redirect_to action: :index, s: params[:s] end |
#update ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/controllers/camaleon_cms/admin/posts_controller.rb', line 93 def update @post = @post.parent if @post.draft? && @post.parent.present? :update, @post @post.drafts.destroy_all post_data = get_post_data r = {post: @post, post_type: @post_type}; hooks_run("update_post", r) @post = r[:post] if @post.update(post_data) @post.(params[:meta]) @post.set_field_values(params[:field_options]) @post.(params[:options]) hooks_run("updated_post", {post: @post, post_type: @post_type}) flash[:notice] = t('camaleon_cms.admin.post.message.updated', post_type: @post_type.decorate.the_title) redirect_to action: :edit, id: @post.id else edit end end |