action button class
This commit is contained in:
parent
772ad48961
commit
0f47f73dda
15
kernel/IGTabel/btn/ActionButton.php
Normal file
15
kernel/IGTabel/btn/ActionButton.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\IGTabel\btn;
|
||||
|
||||
|
||||
class ActionButton
|
||||
{
|
||||
public static function create(array $data): string
|
||||
{
|
||||
$btn_type = $data['btn_type'];
|
||||
$url = $data['url'];
|
||||
$label = $data['label'];
|
||||
return "<a class='btn btn-$btn_type' href='$url' style='margin: 3px'>$label</a>";
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ class Widget
|
||||
public function __construct(array $data = [])
|
||||
{
|
||||
$this->cgView = new CgView();
|
||||
$this->cgView->viewPath = ROOT_DIR . "/views/widgets";
|
||||
$this->cgView->viewPath = KERNEL_DIR . "/views/widgets";
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
|
@ -7,6 +7,9 @@
|
||||
* @var \kernel\services\ModuleService $moduleService
|
||||
*/
|
||||
|
||||
use kernel\IGTabel\btn\ActionButton;
|
||||
use kernel\widgets\ActionButtonWidget;
|
||||
|
||||
$meta = [];
|
||||
$meta['columns'] = [
|
||||
"name" => "Название",
|
||||
@ -29,22 +32,36 @@ $table = new \Itguild\Tables\ListJsonTable(json_encode($info_to_table, JSON_PRET
|
||||
$table->addAction(function ($row, $url) use ($moduleService) {
|
||||
$slug = $row['slug'];
|
||||
if ($moduleService->isActive($slug)) {
|
||||
$label = "Деактивировать";
|
||||
$btn_type = "warning";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
return ActionButton::create([
|
||||
'btn_type' => "warning",
|
||||
'label' => "<i class='fa-regular fa-circle-xmark'></i>",
|
||||
'url' => "$url/deactivate/?slug=$slug",
|
||||
]);
|
||||
|
||||
} else {
|
||||
$label = "<i class='fa-regular fa-circle-check'></i>";
|
||||
$btn_type = "success";
|
||||
$btn = "<a class='btn btn-$btn_type' href='$url/activate/?slug=$slug' style='margin: 3px;' >$label</a>";
|
||||
}
|
||||
ActionButtonWidget::create([
|
||||
'label' => "<i class='fa-regular fa-circle-check'></i>",
|
||||
'url' => "$url/deactivate/?slug=$slug",
|
||||
'btn_type' => "success"
|
||||
])->run();
|
||||
|
||||
return $btn;
|
||||
// return ActionButton::create([
|
||||
// 'btn_type' => "success",
|
||||
// 'label' => "<i class='fa-regular fa-circle-check'></i>",
|
||||
// 'url' => "$url/deactivate/?slug=$slug",
|
||||
// ]);
|
||||
}
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService) {
|
||||
$slug = $row['slug'];
|
||||
return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
|
||||
// return "<a class='btn btn-primary' href='$url/view/?slug=$slug' style='margin: 3px; width: 150px;' >Просмотр</a>";
|
||||
|
||||
return ActionButton::create([
|
||||
'btn_type' => "primary",
|
||||
'label' => "<i class='fa-regular fa-eye'></i>",
|
||||
'url' => "$url/view/?slug=$slug",
|
||||
]);
|
||||
});
|
||||
|
||||
$table->addAction(function ($row, $url) use ($moduleService){
|
||||
@ -63,16 +80,22 @@ $table->addAction(function ($row, $url) use ($moduleService){
|
||||
$table->addAction(function ($row) use ($moduleService){
|
||||
$slug = $row['slug'];
|
||||
if (!$moduleService->isKernelModule($slug)){
|
||||
$label = "Удалить";
|
||||
$btn_type = "danger";
|
||||
return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
// $label = "Удалить";
|
||||
// $btn_type = "danger";
|
||||
// return "<a class='btn btn-$btn_type' href='admin/module_shop_client/delete/?slug=$slug' style='margin: 3px; width: 150px;' >$label</a>";
|
||||
|
||||
return ActionButton::create([
|
||||
'btn_type' => "danger",
|
||||
'label' => "<i class='fa-regular fa-trash-can'></i>",
|
||||
'url' => "admin/module_shop_client/delete/?slug=$slug",
|
||||
]);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
$table->create();
|
||||
|
||||
if ($moduleService->isActive('module_shop_client')) {
|
||||
\kernel\widgets\ModuleTabsWidget::create()->run();
|
||||
}
|
||||
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
9
kernel/views/widgets/action_button.php
Normal file
9
kernel/views/widgets/action_button.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $label
|
||||
* @var string $btn_type
|
||||
* @var string $url
|
||||
*/
|
||||
?>
|
||||
|
||||
<a class='btn btn-<?= $btn_type ?>' href='<?= $url ?>' style='margin: 3px' ><?= $label ?></a>
|
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @var string $icon
|
||||
* @var string $btn
|
||||
* @var string $url
|
||||
*/
|
||||
?>
|
||||
|
||||
"<a class='btn btn-$btn' href='$url/deactivate/?slug=$slug' style='margin: 3px; width: 150px;' >$icon</a>";
|
@ -8,9 +8,9 @@ class ActionButtonWidget extends Widget
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$icon = $this->data['icon'];
|
||||
$btn = $this->data['btn'];
|
||||
$label = $this->data['label'];
|
||||
$btn_type = $this->data['btn_type'];
|
||||
$url = $this->data['url'];
|
||||
$this->cgView->render('/admin/action_button.php', ['icon' => $icon, 'btn' => $btn, 'url' => $url]);
|
||||
$this->cgView->render('/action_button.php', ['label' => $label, 'btn_type' => $btn_type, 'url' => $url]);
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ class MenuWidget extends Widget
|
||||
public function run(): void
|
||||
{
|
||||
$menu = Menu::where("parent_id", 0)->get()->sortBy("priority");
|
||||
$this->cgView->render('/admin/menu.php', ['menu' => $menu]);
|
||||
$this->cgView->render('/menu.php', ['menu' => $menu]);
|
||||
}
|
||||
|
||||
}
|
@ -13,6 +13,6 @@ class ModuleTabsWidget extends Widget
|
||||
'/admin' => 'Локальные',
|
||||
'/admin/module_shop_client' => 'Каталог'
|
||||
];
|
||||
$this->cgView->render('/admin/module_tabs.php', ['tabs' => $tabs]);
|
||||
$this->cgView->render('/module_tabs.php', ['tabs' => $tabs]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user