Sha256: 5c0017e77612fa254b02bf38d301b0497a7340beb289f2df4ff4e44067f76274

Contents?: true

Size: 1.89 KB

Versions: 30

Compression:

Stored size: 1.89 KB

Contents

class CamaleonCms::Admin::Settings::PostTypesController < CamaleonCms::Admin::SettingsController
  before_action :set_post_type, only: [:show,:edit,:update, :destroy]
  before_action :set_data_term, only: [:create, :update]
  add_breadcrumb I18n.t("camaleon_cms.admin.sidebar.content_groups"), :cama_admin_settings_post_types_path

  def index
    @post_types = current_site.post_types
    @post_types = @post_types.paginate(:page => params[:page], :per_page => current_site.admin_per_page)
    render "index"
  end

  def show
  end

  def edit
    add_breadcrumb I18n.t("camaleon_cms.admin.button.edit")
  end

  def update
    if @post_type.update(@data_term)
      @post_type.set_field_values(params.require(:field_options).permit!) if params[:field_options].present?
      hooks_run("updated_post_type", {post_type: @post_type})
      flash[:notice] = t('camaleon_cms.admin.post_type.message.updated')
      redirect_to action: :index
    else
      edit
    end
  end

  def create
    @post_type = current_site.post_types.new(@data_term)
    if @post_type.save
      @post_type.set_field_values(params.require(:field_options).permit!) if params[:field_options].present?
      hooks_run("created_post_type", {post_type: @post_type})
      flash[:notice] = t('camaleon_cms.admin.post_type.message.created')
      redirect_to action: :index
    else
      index
    end
  end

  def destroy
    flash[:notice] = t('camaleon_cms.admin.post_type.message.deleted') if @post_type.destroy
    redirect_to action: :index
  end

  private

  def set_data_term
    data_term = params.require(:post_type).permit!
    data_term[:data_options] = params.require(:meta).permit!
    @data_term = data_term
  end

  def set_post_type
    begin
      @post_type = current_site.post_types.find_by_id(params[:id])
    rescue
      flash[:error] = t('camaleon_cms.admin.post_type.message.error')
      redirect_to cama_admin_path
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
camaleon_cms-2.6.4 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.6.3 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.6.2 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.6.1 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.6.0.1 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.6.0 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.5.3.1 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.5.3 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.5.2 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms_rails6-2.5.0 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.5.1 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.5.0 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.9 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.8 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.7 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.6 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.5 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.4 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.3 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb
camaleon_cms-2.4.6.2 app/controllers/camaleon_cms/admin/settings/post_types_controller.rb