Sha256: 10bdc815a3ac114f011d0f24970af76e8ecc7c7686f1cf07715316a172930ab4

Contents?: true

Size: 1.67 KB

Versions: 11

Compression:

Stored size: 1.67 KB

Contents

class CmsAdmin::LayoutsController < CmsAdmin::BaseController

  before_filter :build_layout,  :only => [:new, :create]
  before_filter :load_layout,   :only => [:edit, :update, :destroy]

  def index
    return redirect_to :action => :new if @site.layouts.count == 0
    @layouts = @site.layouts.roots
  end

  def new
    render
  end

  def edit
    render
  end

  def create
    @layout.save!
    flash[:success] = I18n.t('cms.layouts.created')
    redirect_to :action => :edit, :id => @layout
  rescue ActiveRecord::RecordInvalid
    logger.detailed_error($!)
    flash.now[:error] = I18n.t('cms.layouts.creation_failure')
    render :action => :new
  end

  def update
    @layout.update_attributes!(params[:layout])
    flash[:success] = I18n.t('cms.layouts.updated')
    redirect_to :action => :edit, :id => @layout
  rescue ActiveRecord::RecordInvalid
    logger.detailed_error($!)
    flash.now[:error] = I18n.t('cms.layouts.update_failure')
    render :action => :edit
  end

  def destroy
    @layout.destroy
    flash[:success] = I18n.t('cms.layouts.deleted')
    redirect_to :action => :index
  end
  
  def reorder
    (params[:cms_layout] || []).each_with_index do |id, index|
      Cms::Layout.where(:id => id).update_all(:position => index)
    end
    render :nothing => true
  end

protected

  def build_layout
    @layout = @site.layouts.new(params[:layout])
    @layout.parent  ||= Cms::Layout.find_by_id(params[:parent_id])
    @layout.content ||= '{{ cms:page:content:text }}'
  end

  def load_layout
    @layout = @site.layouts.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = I18n.t('cms.layouts.not_found')
    redirect_to :action => :index
  end

end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
comfortable_mexican_sofa-1.8.5 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.8.4 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.8.3 app/controllers/cms_admin/layouts_controller.rb
comfypress-0.1.4 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.8.2 app/controllers/cms_admin/layouts_controller.rb
comfypress-0.1.3 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.8.1 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.8.0 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.7.3 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.7.1 app/controllers/cms_admin/layouts_controller.rb
comfortable_mexican_sofa-1.7.0 app/controllers/cms_admin/layouts_controller.rb