# encoding:utf-8
require Rails.root.join('lib','rails_admin', 'generate_menu')
require Rails.root.join('lib','rails_admin', 'push_tmpl_redirect')
require Rails.root.join('lib','rails_admin', 'push_xcx_tmpl_redirect')
require Rails.root.join('lib', 'rails_admin', 'audit_takecash_order.rb')
require Rails.root.join('lib', 'rails_admin', 'refuse_takecash')
require Rails.root.join('lib', 'rails_admin', 'takecash_at_once')
require Rails.root.join('lib', 'wxku_commodity', 'add_wxku_commodity')
require Rails.root.join('lib', 'wxku_commodity', 'check_wxku_commodity')
require Rails.root.join('lib', 'wxku_commodity', 'get_wxku_commodity')
require Rails.root.join('lib', 'wxku_commodity', 'update_wxku_commodity')
require Rails.root.join('lib', 'rails_admin', 'correct_takecash')
require Rails.root.join('lib', 'rails_admin', 'update_intro_user')
require Rails.root.join('lib', 'rails_admin', 'order_dispatch')
require Rails.root.join('lib', 'rails_admin', 'create_xcx_qrcode')
require Rails.root.join('lib', 'rails_admin', 'generate_order_static')
require Rails.root.join('lib', 'product', 'copy_product')
require Rails.root.join('lib', 'rails_admin', 'update_shop_application')
require Rails.root.join('lib', 'rails_admin', 'audit_order_refund')
require Rails.root.join('lib', 'rails_admin', 'generate_user_perfomance')
require Rails.root.join('lib', 'rails_admin', 'generate_live_award')
require Rails.root.join('lib', 'rails_admin', 'balance_order_confirm')
require Rails.root.join('lib', 'rails_admin', 'generate_order_sheet')
require Rails.root.join('lib','rails_admin', 'group_message_redirect')
require Rails.root.join('lib', 'rails_admin', 'order_award')
require Rails.root.join('lib', 'rails_admin', 'refund_food')




RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GenerateMenu)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::PushTmplRedirect)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::PushXcxTmplRedirect)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::AuditTakecashOrder)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::RefuseTakecash)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::TakecashAtOnce)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::AddWxkuCommodity)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::CheckWxkuCommodity)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GetWxkuCommodity)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::UpdateWxkuCommodity)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::CorrectTakecash)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::UpdateIntroUser)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::OrderDispatch)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::CreateXcxQrcode)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::CopyProduct)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GenerateOrderStatic)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::UpdateShopApplication)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::AuditOrderRefund)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GenerateUserPerfomance)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GenerateLiveAward)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::BalanceOrderConfirm)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GenerateOrderSheet)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::GroupMessageRedirect)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::OrderAward)
RailsAdmin::Config::Actions.register(RailsAdmin::Config::Actions::RefundFood)






RailsAdmin.config do |config|

  config.total_columns_width = 3000
  config.default_items_per_page = 50
  # config.current_user_method { current_admin_user }
  config.authenticate_with do
    warden.authenticate! scope: :admin_user
  end
  config.current_user_method(&:current_admin_user)
  config.authorize_with :cancan
  config.label_methods << :nickname
  config.label_methods << :wx_name
  config.label_methods << :real_name
  config.label_methods << :nick_name
  config.label_methods << :user_name
  config.label_methods << :key
  config.label_methods << :bank_name  
  config.label_methods << :remark
  config.label_methods << :title
  config.label_methods << :name
  config.label_methods << :channel
  config.label_methods << :channel_value
  config.label_methods << :product_name
  config.audit_with :paper_trail, 'AdminUser', 'PaperTrail::Version'
  config.model 'FoodUnsub' do
    visible false
  end
  #
  # config.model 'ckeditor\attachment_file' do
  #   visible false
  # end
  config.excluded_models= ['Ckeditor::Asset','Ckeditor::AttachmentFile']
  # config.excluded_models= [Ckeditor::AttachmentFile]
  config.model 'Ckeditor::Picture' do
    navigation_label '富文本编辑器'
  end

  # config.excluded_models << "Project"
  # PAPER_TRAIL_AUDIT_MODEL = ['Project','Picture','Bonusorder','Bonusordertransfer','Bonusproject','Menmber','Zczjraised']
  # PAPER_TRAIL_AUDIT_MODEL = ['AdItem','AdPosition','ProjectFollow','Address','AdminPermission','AdminPermissionAdminRole','AdminRole','AdminRolesAdminUser']
  # PAPER_TRAIL_AUDIT_MODEL = ['AdminUser','Article','ArticleCat','Balance','BalanceHistory','BalanceOrder','ChannelQrcode','ChannelQrcodeResult','ClickFromChannel','ClickFromUser','Company','Express']
  # PAPER_TRAIL_AUDIT_MODEL = ['FriendlyLink','Industry','PartnerLink','ProjectJoin','ProjectComment','ProjectInfo','ProjectLoan','ProjectProgress','ProjectQa']
  # PAPER_TRAIL_AUDIT_MODEL = ['RailsAdmin','Session','SignUpChannel','TakeCashOrder','User','UserBankcard','WxEvent','WxEventItem','WxGongzonghao','WxMenu','WxUser']


  config.actions do
    # root actions
    dashboard                     # mandatory
    # collection actions
    index                         # mandatory
    new do
      except ['EmployStaticFood','StaticFood']
      # except ['Address','WxUser', 'User','BalanceHistory', 'ProjectFollow', 'BalanceOrder', 'TakeCashOrder', 'UserBankcard', 'ProjectJoin']
    end
    export
    import do
      only ["UpdateOrder","LiveAward","Order","OrderDetail","Employ"]
    end
    history_index do
      # PAPER_TRAIL_AUDIT_MODEL
    end
    bulk_delete
    # member actions

    correct_takecash do
      only ["TakeCashOrder"]
    end

    update_intro_user do
      only ["WxUser"]
    end

    update_shop_application do
      only ["ShopApplication"]
    end

    audit_order_refund do
      only ["OrderRefund"]
    end
    generate_order_sheet do
      only ["OrderFile"]
    end
    create_xcx_qrcode do
      only ["WxUser"]
    end
    order_dispatch do
      only ["Order"]
    end
    #发放佣金
    order_award do
      only ["Order"]
    end
    generate_menu do
      only ["WxMenu"]
    end
    #订餐退餐
    refund_food do
      only ["EmployStaticFood"]
    end
    push_tmpl_redirect do
      only ["PushTmpl"]
    end

    group_message_redirect do
      only ["GroupMessage"]
    end

    push_xcx_tmpl_redirect do
      only ["XcxPushTmpl"]
    end

    #提现审批
    audit_takecash_order do
      only ["TakeCashOrder"]
    end
    #拒绝提现
    refuse_takecash do
      only ["TakeCashOrder"]
    end
    #马上提现
    takecash_at_once do
      only ["TakeCashOrder"]
    end
    copy_product do
      only ["Product"]
    end

    #审核充值
    balance_order_confirm do
      only ["BalanceOrder"]
    end
    generate_order_static do
      only ["OrderStatic"]
    end
    generate_live_award do
      only ["LiveAward"]
    end

    generate_user_perfomance do
      only ["UserPerfomance"]
    end

    add_wxku_commodity do
      only ["WxkuCommodity"]
    end
    update_wxku_commodity do
      only ["WxkuCommodity"]
    end
    get_wxku_commodity do
      only ["WxkuCommodity"]
    end
    check_wxku_commodity do
      only ["WxkuCommodity"]
    end

    show
    edit do
      except ['EmployStaticFood','StaticFood']
      # except ['Balance','BalanceHistory', 'ProjectFollow', 'BalanceOrder', 'TakeCashOrder', 'UserBankcard', 'ProjectJoin','AddressDeletedItem','ProjectDeletedItem']
    end
    delete do
      except ['EmployStaticFood','StaticFood']
      # except ['Project','Address','WxUser', 'User','Balance','BalanceHistory', 'ProjectFollow', 'BalanceOrder', 'TakeCashOrder', 'UserBankcard', 'ProjectJoin']
    end
    history_show do
      # PAPER_TRAIL_AUDIT_MODEL
    end
    show_in_app
    # Add the nestable action for configured models
    nestable
  end
end

# When class reloading is enabled (cache_classes = false), RailsAdmin keeps the
# model config registry between reloads, which can lead to "can\x27t modify frozen Array"
# errors when redefining fields. Reset Product config before each request.
Rails.application.config.to_prepare do
  RailsAdmin::Config.reset_model("Product")
end
