ActiveAdmin.register JamRuby::PromoLatest, :as => 'Latest' do

  menu :label => 'Promo Latest', :parent => 'Misc'

  config.batch_actions = false
  config.sort_order = ''
  # config.clear_action_items!
  config.filters = false

  form :partial => 'form'

  index do
    column 'Latest' do |pp| pp.latest_display_name end
    column 'Latest ID' do |pp| pp.latest_id end
    column 'State' do |pp| pp.aasm_state end
    column 'Position' do |pp| pp.position end
    column 'Updated' do |pp| pp.updated_at end
    actions
  end

  show do 
    attributes_table do
      row 'Latest' do |pp| pp.latest_display_name end
      row 'State' do |obj| obj.aasm_state end
      row 'Position' do |obj| obj.position end
      row 'Updated' do |obj| obj.updated_at end
    end
  end

  controller do

    def new
      @promo = JamRuby::PromoLatest.new
      @promo.aasm_state = 'active'
      super
    end

    def create 
      promo = PromoLatest.create_with_params(params[:jam_ruby_promo_latest])
      redirect_to admin_latests_path
    end

    def edit
      @promo = resource
      super
    end

    def update
      resource.update_with_params(params[:jam_ruby_promo_latest]).save!
      redirect_to admin_latests_path
    end

  end


end
