action btn

This commit is contained in:
Kavalar 2024-11-19 16:52:00 +03:00
parent 6c2798c123
commit 0bfeabce33
6 changed files with 42 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "Tags", "name": "Tags",
"version": "0.12", "version": "0.2",
"author": "ITGuild", "author": "ITGuild",
"slug": "tag", "slug": "tag",
"description": "Tags module", "description": "Tags module",

View File

@ -8,6 +8,10 @@ use Itguild\EloquentTable\EloquentDataProvider;
use Itguild\EloquentTable\ListEloquentTable; use Itguild\EloquentTable\ListEloquentTable;
use kernel\app_modules\tag\models\Tag; use kernel\app_modules\tag\models\Tag;
use kernel\IGTabel\btn\PrimaryBtn; use kernel\IGTabel\btn\PrimaryBtn;
use kernel\models\Menu;
use kernel\modules\menu\table\columns\MenuDeleteActionColumn;
use kernel\modules\menu\table\columns\MenuEditActionColumn;
use kernel\modules\menu\table\columns\MenuViewActionColumn;
$table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [ $table = new ListEloquentTable(new EloquentDataProvider(Tag::class, [
'currentPage' => $page_number, 'currentPage' => $page_number,

View File

@ -8,6 +8,7 @@
*/ */
use kernel\widgets\ActionButtonWidget; use kernel\widgets\ActionButtonWidget;
use kernel\widgets\IconBtn\IconBtnViewWidget;
use kernel\widgets\ModuleTabsWidget; use kernel\widgets\ModuleTabsWidget;
$meta = []; $meta = [];
@ -41,20 +42,17 @@ $table->addAction(function ($row, $url) use ($moduleService) {
} else { } else {
return ActionButtonWidget::create([ return ActionButtonWidget::create([
'label' => "<i class='fa-regular fa-circle-check'></i>", 'label' => "<i class='fa-regular fa-circle-check'></i>",
'url' => "$url/deactivate/?slug=$slug", 'url' => "$url/activate/?slug=$slug",
'btn_type' => "success" 'btn_type' => "success",
'title' => "Активировать",
])->run(); ])->run();
} }
}); });
$table->addAction(function ($row, $url) use ($moduleService) { $table->addAction(function ($row, $url) use ($moduleService) {
$slug = $row['slug']; $url = "$url/view/?slug=". $row['slug'];
return ActionButtonWidget::create([ return IconBtnViewWidget::create(['url' => $url])->run();
'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>",
'url' => "$url/view/?slug=$slug",
])->run();
}); });
$table->addAction(function ($row, $url) use ($moduleService){ $table->addAction(function ($row, $url) use ($moduleService){

View File

@ -3,7 +3,8 @@
* @var string $label * @var string $label
* @var string $btn_type * @var string $btn_type
* @var string $url * @var string $url
* @var string $title
*/ */
?> ?>
<a class='btn btn-<?= $btn_type ?>' href='<?= $url ?>' style='margin: 3px' ><?= $label ?></a> <a title="<?= $title ?>" class='btn btn-<?= $btn_type ?>' href='<?= $url ?>' style='margin: 3px' ><?= $label ?></a>

View File

@ -18,7 +18,8 @@ class ActionButtonWidget extends Widget
$label = $this->data['label']; $label = $this->data['label'];
$btn_type = $this->data['btn_type']; $btn_type = $this->data['btn_type'];
$url = $this->data['url']; $url = $this->data['url'];
$title = $this->data['title'] ?? '';
return $this->cgView->fetch('/action_button.php', ['label' => $label, 'btn_type' => $btn_type, 'url' => $url]); return $this->cgView->fetch('/action_button.php', ['label' => $label, 'btn_type' => $btn_type, 'url' => $url, 'title' => $title]);
} }
} }

View File

@ -0,0 +1,27 @@
<?php
namespace kernel\widgets\IconBtn;
use kernel\Widget;
use kernel\widgets\ActionButtonWidget;
class IconBtnViewWidget extends Widget
{
public static function create(array $data = []): IconBtnViewWidget
{
return new static($data);
}
public function run(): string
{
$url = $this->data['url'];
return ActionButtonWidget::create([
'btn_type' => "primary",
'label' => "<i class='fa-regular fa-eye'></i>",
'url' => $url,
'title' => "Просмотреть"
])->run();
}
}