nemmo\attachments\components\AttachmentsTable::run PHP Method

run() public method

public run ( )
    public function run()
    {
        $confirm = Yii::t('yii', 'Are you sure you want to delete this item?');
        $js = <<<JS
        \$(".delete-button").click(function(){
            var tr = this.closest('tr');
            var url = \$(this).data('url');
            if (confirm("{$confirm}")) {
                \$.ajax({
                    method: "POST",
                    url: url,
                    success: function(data) {
                        if (data) {
                            tr.remove();
                        }
                    }
                });
            }
        });
JS;
        Yii::$app->view->registerJs($js);
        return GridView::widget(['dataProvider' => new ArrayDataProvider(['allModels' => $this->model->getFiles()]), 'layout' => '{items}', 'tableOptions' => $this->tableOptions, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => $this->getModule()->t('attachments', 'File name'), 'format' => 'raw', 'value' => function ($model) {
            return Html::a("{$model->name}.{$model->type}", $model->getUrl());
        }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
            return Html::a('<span class="glyphicon glyphicon-trash"></span>', '#', ['class' => 'delete-button', 'title' => Yii::t('yii', 'Delete'), 'data-url' => Url::to(['/attachments/file/delete', 'id' => $model->id])]);
        }]]]]);
    }
AttachmentsTable