This commit is contained in:
2026-03-28 11:33:56 +01:00
parent 412e235512
commit aa8e21862d
132 changed files with 24381 additions and 10882 deletions

View File

@@ -0,0 +1,19 @@
<?php
$label = trim((string)($this->label ?? 'Kategorie'));
$inputName = trim((string)($this->inputName ?? 'categories[]'));
$categories = is_array($this->categories ?? null) ? $this->categories : [];
$selectedIds = is_array($this->selectedIds ?? null) ? $this->selectedIds : [];
?>
<div class="form-group row js-coupon-row js-coupon-row-categories">
<label class="col-lg-4 control-label"><?= htmlspecialchars($label, ENT_QUOTES, 'UTF-8'); ?>:</label>
<div class="col-lg-8">
<div class="coupon-categories-box">
<?= \Shared\Tpl\Tpl::view('shop-coupon/coupon-categories-tree', [
'categories' => $categories,
'selectedIds' => $selectedIds,
'inputName' => $inputName,
]); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,68 @@
<?php
$categories = is_array($this->categories ?? null) ? $this->categories : [];
$inputName = trim((string)($this->inputName ?? 'categories[]'));
$selectedRaw = is_array($this->selectedIds ?? null) ? $this->selectedIds : [];
$selected = [];
foreach ($selectedRaw as $value) {
$id = (int)$value;
if ($id > 0) {
$selected[$id] = true;
}
}
?>
<?php if (!empty($categories)): ?>
<ol class="coupon-categories-tree">
<?php foreach ($categories as $category): ?>
<?php
$categoryId = (int)($category['id'] ?? 0);
if ($categoryId <= 0) {
continue;
}
$title = trim((string)($category['title'] ?? ''));
if ($title === '') {
$title = 'Kategoria #' . $categoryId;
}
$isActive = (int)($category['status'] ?? 0) === 1;
$children = is_array($category['subcategories'] ?? null) ? $category['subcategories'] : [];
$hasChildren = !empty($children);
?>
<li class="coupon-category-item<?= $hasChildren ? ' has-children is-collapsed' : ''; ?>">
<div class="coupon-category-row">
<?php if ($hasChildren): ?>
<button type="button" class="coupon-tree-toggle" aria-expanded="false" title="Rozwin / zwin">
<i class="fa fa-caret-right"></i>
</button>
<?php else: ?>
<span class="coupon-tree-spacer"></span>
<?php endif; ?>
<?php if (!$isActive): ?>
<i class="fa fa-ban text-danger" title="Kategoria nieaktywna"></i>
<?php endif; ?>
<label class="coupon-category-label">
<input
type="checkbox"
class="g-checkbox"
name="<?= htmlspecialchars($inputName, ENT_QUOTES, 'UTF-8'); ?>"
value="<?= $categoryId; ?>"
<?= isset($selected[$categoryId]) ? 'checked="checked"' : ''; ?>
/>
<span><?= htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); ?></span>
</label>
</div>
<?php if ($hasChildren): ?>
<?= \Shared\Tpl\Tpl::view('shop-coupon/coupon-categories-tree', [
'categories' => $children,
'selectedIds' => array_keys($selected),
'inputName' => $inputName,
]); ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>

View File

@@ -0,0 +1,109 @@
<style type="text/css">
.coupon-categories-box {
max-height: 420px;
overflow: auto;
border: 1px solid #d6d6d6;
border-radius: 4px;
padding: 8px 10px;
background: #fff;
}
.coupon-categories-tree {
margin: 0;
padding: 0 0 0 16px;
list-style: none;
}
.coupon-category-item {
margin: 2px 0;
}
.coupon-category-item.is-collapsed > ol {
display: none;
}
.coupon-category-row {
display: flex;
align-items: center;
gap: 6px;
min-height: 28px;
}
.coupon-tree-toggle,
.coupon-tree-spacer {
width: 18px;
height: 18px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background: transparent;
padding: 0;
}
.coupon-tree-toggle {
cursor: pointer;
color: #666;
}
.coupon-tree-toggle:focus,
.coupon-tree-toggle:active,
.coupon-tree-toggle:focus-visible {
outline: none;
box-shadow: none;
}
.coupon-category-item:not(.is-collapsed) > .coupon-category-row .coupon-tree-toggle i {
transform: rotate(90deg);
}
.coupon-category-label {
margin: 0;
font-weight: 600;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 6px;
}
.coupon-category-row .icheckbox_minimal-blue {
margin-top: 0;
}
</style>
<script type="text/javascript">
(function($) {
if (!$) {
return;
}
$(document).off('click.shopCouponTree', '.coupon-tree-toggle');
$(document).on('click.shopCouponTree', '.coupon-tree-toggle', function(e) {
e.preventDefault();
var $item = $(this).closest('.coupon-category-item');
$item.toggleClass('is-collapsed');
$(this).attr('aria-expanded', $item.hasClass('is-collapsed') ? 'false' : 'true');
this.blur();
});
function initCouponCategoryCheckboxes() {
if (!$.fn || typeof $.fn.iCheck !== 'function') {
return;
}
$('.coupon-categories-box .g-checkbox').each(function() {
var $checkbox = $(this);
if ($checkbox.parent().hasClass('icheckbox_minimal-blue')) {
return;
}
$checkbox.iCheck({
checkboxClass: 'icheckbox_minimal-blue',
radioClass: 'iradio_minimal-blue'
});
});
}
initCouponCategoryCheckboxes();
})(window.jQuery);
</script>

View File

@@ -0,0 +1,3 @@
<?= \Shared\Tpl\Tpl::view('components/form-edit', ['form' => $this->form]); ?>
<?= \Shared\Tpl\Tpl::view('shop-coupon/coupon-edit-custom-script'); ?>

View File

@@ -0,0 +1,2 @@
<?= \Shared\Tpl\Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>