<?php
/**
 * Created by PhpStorm.
 * User: Mead
 * Date: 2017/11/16
 * Time: 15:48
 */
namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class GenerateKeyRow
{
    protected $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

    protected function script()
    {
        return <<<SCRIPT

$('.grid-generate-key-row').on('click', function () {

    // Your code.
    console.log($(this).data('id'));
    var id = $(this).data('id');
    $.get('/admin/key',{id:id},function(data){
        console.log(data);
    });
    
});

SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "<a title='生成key' class='btn btn-xs btn-success fa fa-sitemap grid-generate-key-row' data-id='{$this->id}'></a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}