# encoding: utf-8
class ForbidDate < ActiveRecord::Base
  self.table_name = "food_forbid_date"
  validates :forbid_date,:source,presence: true

  TYPE_ENUM = [["早餐",1],["中餐",2],["晚餐",3]]

  after_update :sync_forbid_date
  after_create :sync_forbid_date
  after_destroy :sync_forbid_date

  def sync_forbid_date
    #发放未发放赠品
    url = "#{CONFIG_FILE["xj_host"]}/base/synchronize-forbid-food/?id=#{self.id}"
    open(url)
  end

  rails_admin do
    navigation_label '食堂管理'
    weight -500
    list do
      filters [:source]
      field :id
      field :forbid_date
      field :source, :enum do
        filterable true
        enum do
          TYPE_ENUM
        end
      end
      field :created_at
      # field :updated_at
    end
    show do
      field :id
      field :forbid_date
      field :source, :enum do
        filterable true
        enum do
          TYPE_ENUM
        end
      end
      field :created_at
      field :updated_at
    end
    edit do
      field :forbid_date
      field :source, :enum do
        filterable true
        enum do
          TYPE_ENUM
        end
      end
    end
  end
end
