#encoding
module RailsAdmin
  module Config
    module Actions
      class UpdateWxkuCommodity < RailsAdmin::Config::Actions::Base
        register_instance_option :visible?  do
          if not bindings[:object].blank?
               if  bindings[:object].class.base_class.name == 'WxkuCommodity'
                authorized? && bindings[:object].status_ticket != ''
               else
                authorized?
              end             
          else
            authorized?
          end
        end

        register_instance_option :member do
            true
        end

        register_instance_option :link_icon do
            'icon-refresh'
        end

        register_instance_option :pjax? do
            false
        end

        register_instance_option :controller do
          Proc.new do
            require 'rest-client'
            n = "更新商品成功！"
            url = "#{CONFIG_FILE["api_host"]}/railsadmin/wxku_commodity/#{@object.id}/addOrUpdate"
            p url
            begin
              ret = RestClient.post url, {partUpdate: 0 }
            rescue Exception => e
              p "************ UpdateWxkuCommodity fail . #{e.to_s}"
              n = "更新商品失败！"
            end
            redirect_to :back, notice: "#{n}"
          end
        end
      end
    end
  end
end