ActiveAdmin.register JamRuby::PromoBuzz, :as => 'Buzz' do

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

  config.sort_order = 'position ASC aasm_state DESC updated_at DESC'
  config.batch_actions = false
  # config.clear_action_items!
  config.filters = false

  form :partial => 'form'

  index do
    column 'Who?' do |pp| pp.text_short end
    column 'Image' do |pp| 
      image_tag(pp.image_url, :size => '50x50') 
    end
    column 'Quote' do |pp| pp.text_long[0..256] 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 'Who?' do |obj| obj.text_short end
      row 'Quote' do |obj| obj.text_long end
      row :image do |obj|
        image_tag(obj.image_url, :size => '50x50')
      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::PromoBuzz.new
      @promo.key = params[:key] if params[:key].present?
      @promo.aasm_state = 'active'
      @uploader = @promo.image
      @uploader.success_action_redirect = new_admin_buzz_url
      super
    end

    def create 
      promo = PromoBuzz.create_with_params(params[:jam_ruby_promo_buzz])
      redirect_to admin_buzzs_path
    end

    def edit
      @promo = resource
      @promo.key = params[:key] if params[:key].present? && params[:key] != @promo.key
      @uploader = @promo.image
      @uploader.success_action_redirect = edit_admin_buzz_url(@promo)
      super
    end

    def update
      resource.update_with_params(params[:jam_ruby_promo_buzz]).save!
      redirect_to admin_buzzs_path
    end

  end

end
