#encoding
module RailsAdmin
  module Config
    module Actions
        class GenerateOrderSheet < 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-star'
            end

            register_instance_option :pjax? do
                false
            end

            register_instance_option :controller do
                Proc.new do
                    require 'rest-client'
                    order_sheet = OrderFile.where("id = ? ",@object.id).first
                    n = "生成成功"
                    if !order_sheet.blank?
                        n = "已成功生成"
                        url = "#{CONFIG_FILE["app_host"]}/railsadmin/order/generate_file/#{@object.id}"
                        begin
                            ret = RestClient.get url, {} #per_page: 5
                        rescue Exception => e
                            n = "生成失败！"
                        end
                    end
                    redirect_to :back, notice: "#{n}"
                end
            end
        end
    end
  end
end