Sha256: 0859a6a111cbe14504c24fe8ae92a84a343733814eba6def43d5eba23ecae8d7

Contents?: true

Size: 1.79 KB

Versions: 29

Compression:

Stored size: 1.79 KB

Contents

class CmsAdmin::RevisionsController < CmsAdmin::BaseController
  
  before_filter :load_record
  before_filter :load_revision, :except => :index
  
  def index
    redirect_to :action => :show, :id => @record.revisions.first.try(:id) || 0
  end
  
  def show
    case @record
    when Cms::Page
      @current_content    = @record.blocks.inject({}){|c, b| c[b.identifier] = b.content; c }
      @versioned_content  = @record.blocks.inject({}){|c, b| c[b.identifier] = @revision.data['blocks_attributes'].detect{|r| r[:identifier] == b.identifier}.try(:[], :content); c }
    else
      @current_content    = @record.revision_fields.inject({}){|c, f| c[f] = @record.send(f); c }
      @versioned_content  = @record.revision_fields.inject({}){|c, f| c[f] = @revision.data[f]; c }
    end
  end
  
  def revert
    @record.restore_from_revision(@revision)
    flash[:notice] = I18n.t('cms.revisions.reverted')
    redirect_to_record
  end
  
protected
  
  def load_record
    @record = if params[:layout_id]
      Cms::Layout.find(params[:layout_id])
    elsif params[:page_id]
      Cms::Page.find(params[:page_id])
    elsif params[:snippet_id]
      Cms::Snippet.find(params[:snippet_id])
    end
  rescue ActiveRecord::RecordNotFound
    flash[:error] = I18n.t('cms.revisions.record_not_found')
    redirect_to cms_admin_path
  end
  
  def load_revision
    @revision = @record.revisions.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = I18n.t('cms.revisions.not_found')
    redirect_to_record
  end
  
  def redirect_to_record
    redirect_to case @record
      when Cms::Layout  then edit_cms_admin_site_layout_path(@site, @record)
      when Cms::Page    then edit_cms_admin_site_page_path(@site, @record)
      when Cms::Snippet then edit_cms_admin_site_snippet_path(@site, @record)
    end
  end
  
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
comfortable_mexican_sofa-1.6.31 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.30 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.26 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.25 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.24 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.23 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.22 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.21 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.20 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.19 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.18 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.17 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.16 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.15 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.14 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.13 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.12 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.11 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.10 app/controllers/cms_admin/revisions_controller.rb
comfortable_mexican_sofa-1.6.9 app/controllers/cms_admin/revisions_controller.rb