Encore\Admin\Tree::buildupScript PHP Method

buildupScript() protected method

Build tree grid scripts.
protected buildupScript ( ) : void
return void
    protected function buildupScript()
    {
        $confirm = trans('admin::lang.delete_confirm');
        $token = csrf_token();
        $this->script = <<<SCRIPT

        \$('#{$this->elementId}').nestable({});

        \$('._delete').click(function() {
            var id = \$(this).data('id');
            if(confirm("{$confirm}")) {
                \$.post('/{$this->path}/' + id, {_method:'delete','_token':'{$token}'}, function(data){
                    \$.pjax.reload('#pjax-container');
                });
            }
        });

        \$('.{$this->elementId}-save').click(function () {
            var serialize = \$('#{$this->elementId}').nestable('serialize');
            \$.get('/{$this->path}', {'_tree':JSON.stringify(serialize)}, function(data){
                \$.pjax.reload('#pjax-container');
            });
        });

        \$('.{$this->elementId}-refresh').click(function () {
            \$.pjax.reload('#pjax-container');
        });


SCRIPT;
    }