ver. 0.272 - ShopProductSets refactor + update package

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 10:21:29 +01:00
parent e51ac7f82b
commit fe51a1f4c4
23 changed files with 993 additions and 297 deletions

View File

@@ -0,0 +1,64 @@
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.css">
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.default.css">
<script type="text/javascript" src="/libraries/selectize/js/standalone/selectize.js"></script>
<script type="text/javascript">
(function($) {
if (!$) return;
$(function() {
$('#set_products_id').selectize({
maxItems: 999,
plugins: ['remove_button']
});
var $form = $('#shop-product-set-edit');
if ($form.length) {
var origSerialize = $form.data('origSerialize');
if (!origSerialize) {
$form.on('submit', function(e) {
e.preventDefault();
});
}
$form.find('[data-action="save"]').off('click.productSetSave').on('click.productSetSave', function(e) {
e.preventDefault();
var formData = $form.serializeArray();
var selectedProducts = $('#set_products_id').val();
if (selectedProducts && selectedProducts.length) {
for (var i = 0; i < selectedProducts.length; i++) {
formData.push({ name: 'set_products_id[]', value: selectedProducts[i] });
}
}
var actionUrl = $(this).data('url') || $form.attr('action');
var backUrl = $(this).data('back-url') || '/admin/shop_product_sets/list/';
$.ajax({
url: actionUrl,
type: 'POST',
data: formData,
dataType: 'json',
success: function(response) {
if (response.success || response.status === 'ok') {
var msg = response.message || response.msg || 'Zapisano.';
$('<div class="alert alert-success">' + msg + '</div>').insertBefore($form).delay(2000).fadeOut();
if (response.id && !$form.find('input[name="id"]').val()) {
$form.find('input[name="id"]').val(response.id);
}
} else {
var errorMsg = (response.errors && response.errors.general) || response.msg || 'Wystapil blad.';
$('<div class="alert alert-danger">' + errorMsg + '</div>').insertBefore($form).delay(3000).fadeOut();
}
},
error: function() {
$('<div class="alert alert-danger">Blad komunikacji z serwerem.</div>').insertBefore($form).delay(3000).fadeOut();
}
});
});
}
});
})(window.jQuery);
</script>

View File

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

View File

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

View File

@@ -1,84 +0,0 @@
<?
ob_start();
?>
<div id="settings-tabs">
<ul class="resp-tabs-list settings-tabs">
<li><i class="fa fa-wrench"></i>Ustawienia</li>
</ul>
<div class="resp-tabs-container settings-tabs">
<div>
<?= \Html::input( [
'label' => 'Nazwa',
'name' => 'name',
'id' => 'name',
'value' => $this -> set[ 'name' ],
] );
?>
<?=
\Html::input_switch( [
'label' => 'Aktywny',
'name' => 'status',
'checked' => $this -> set[ 'status' ] == 1 ? true : false
] );
?>
<div class="form-group row">
<label class="col-lg-4 control-label">Produkty do kompletu:</label>
<div class="col-lg-8">
<select id="set_products_id" multiple name="set_products_id[]" placeholder="produkty do kompletu">
<option value="">wybierz produkt...</option>
<? foreach ( $this -> products as $key => $val ):?>
<? if ( $key != $this -> product[ 'id' ] ):?>
<option value="<?= $key;?>" <? if ( in_array( $key, $this -> set[ 'products' ] ) ):?>selected<? endif;?>><?= $val;?></option>
<? endif;?>
<? endforeach;?>
</select>
</div>
</div>
</div>
</div>
</div>
<?
$out = ob_get_clean();
$grid = new \gridEdit;
$grid -> id = 'set-edit';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = 'Edycja kompletu produktów: <u>' . '' . '</u>';
$grid -> fields = [
[
'db' => 'id',
'type' => 'hidden',
'value' => $this -> set[ 'id' ]
]
];
$grid -> actions = [
'save' => [ 'url' => '/admin/shop_product_sets/save/', 'back_url' => '/admin/shop_product_sets/view_list/' ],
'cancel' => [ 'url' => '/admin/shop_product_sets/view_list/' ]
];
$grid -> external_code = $out;
$grid -> persist_edit = true;
$grid -> id_param = 'id';
echo $grid -> draw();
?>
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.css">
<link type="text/css" rel="stylesheet" href="/libraries/selectize/css/selectize.default.css">
<script type="text/javascript" src="/libraries/selectize/js/standalone/selectize.js"></script>
<script type="text/javascript">
$( function()
{
$('#settings-tabs').easyResponsiveTabs({
width: 'auto',
fit: true,
tabidentify: 'settings-tabs',
type: 'vertical'
});
$('#set_products_id').selectize({
maxItems: 999,
plugins: ['remove_button']
});
});
</script>

View File

@@ -1,76 +0,0 @@
<?php
global $gdb;
$grid = new \grid( 'pp_shop_product_sets' );
$grid -> gdb_opt = $gdb;
$grid -> limit = 10;
$grid -> sql = 'SELECT *'
. 'FROM ( '
. 'SELECT '
. 'id, name, status '
. 'FROM '
. 'pp_shop_product_sets AS psps '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] '
. 'ORDER BY '
. '[order_p1] [order_p2]';
$grid -> sql_count = 'SELECT '
. 'COUNT(0) FROM ( '
. 'SELECT '
. 'id, name, status '
. 'FROM '
. 'pp_shop_product_sets AS psps '
. ') AS q1 '
. 'WHERE '
. '1=1 [where] ';
$grid -> debug = true;
$grid -> order = [ 'column' => 'name', 'type' => 'ASC' ];
$grid -> search = [
[ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
];
$grid -> columns_view = [
[
'name' => 'Lp.',
'th' => [ 'class' => 'g-lp' ],
'td' => [ 'class' => 'g-center' ],
'autoincrement' => true
],
[
'name' => 'Nazwa',
'db' => 'name',
'sort' => true,
'php' => 'echo "<a href=\'/admin/shop_product_sets/set_edit/id=[id]\'>" . htmlspecialchars( \'[name]\' ) . "</a>";'
],
[
'name' => 'Aktywny',
'db' => 'status',
'replace' => [ 'array' => [ 0 => '<span class="text-danger">nie</span>', 1 => 'tak' ] ],
'td' => [ 'class' => 'g-center' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
'sort' => true
],
[
'name' => 'Edytuj',
'action' => [ 'type' => 'edit', 'url' => '/admin/shop_product_sets/set_edit/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
],
[
'name' => 'Usuń',
'action' => [ 'type' => 'delete', 'url' => '/admin/shop_product_sets/set_delete/id=[id]' ],
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
'td' => [ 'class' => 'g-center' ]
]
];
$grid -> buttons = [
[
'label' => 'Dodaj komplet produktów',
'url' => '/admin/shop_product_sets/set_edit/',
'icon' => 'fa-plus-circle',
'class' => 'btn-success'
]
];
echo $grid -> draw();
?>

View File

@@ -65,7 +65,7 @@
</a>
</li>
<li>
<a href="/admin/shop_product_sets/view_list/">
<a href="/admin/shop_product_sets/list/">
<i class="fa fa-bars"></i>Komplety Produkt&#243;w
</a>
</li>