#encoding
module RailsAdmin
  module Config
    module Actions

        class BalanceOrderConfirm < RailsAdmin::Config::Actions::Base
            register_instance_option :visible?  do
                authorized?
            end

            register_instance_option :member do
                true
            end

            register_instance_option :link_icon do
                'icon-share'
            end

            register_instance_option :pjax? do
                false
            end

            register_instance_option :controller do
                Proc.new do
                    require 'rest-client'
                    order = BalanceOrder.where("id = ? and state = ?",@object.id, 0).first

                    n = "此状态不支持操作"
                    if not order.blank?
                        n = "已成功审核"
                        url = "#{CONFIG_FILE["api_host"]}/railsadmin/balance_order/confirm/#{@object.id}"
                        begin
                            order.update_user=@current_admin_user.id
                            order.save
                            ret = RestClient.get url, {} #per_page: 5
                        rescue Exception => e
                            n = "审核失败！"
                        end
                    end
                    redirect_to :back, notice: "#{n}"
                end
            end
        end
    end
  end
end