ver. 0.271 - ShopAttribute refactor + update package
This commit is contained in:
68
admin/templates/shop-attribute/_partials/value-row.php
Normal file
68
admin/templates/shop-attribute/_partials/value-row.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
$value = is_array($this->value ?? null) ? $this->value : [];
|
||||
$languages = is_array($this->languages ?? null) ? $this->languages : [];
|
||||
$rowKey = (string)($this->rowKey ?? '');
|
||||
$defaultLanguageId = (string)($this->defaultLanguageId ?? '');
|
||||
$valueId = (int)($value['id'] ?? 0);
|
||||
$isDefault = !empty($value['is_default']);
|
||||
$impact = (string)($value['impact_on_the_price'] ?? '');
|
||||
?>
|
||||
<tr class="attribute-value-row" data-row-key="<?= htmlspecialchars($rowKey, ENT_QUOTES, 'UTF-8'); ?>">
|
||||
<td class="text-center" style="width: 90px;">
|
||||
<input
|
||||
type="radio"
|
||||
class="js-default-row"
|
||||
name="default_row_key"
|
||||
value="<?= htmlspecialchars($rowKey, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
<?= $isDefault ? 'checked="checked"' : ''; ?>
|
||||
/>
|
||||
</td>
|
||||
<td style="width: 180px;">
|
||||
<input type="hidden" class="js-value-id" value="<?= $valueId; ?>" />
|
||||
<input
|
||||
type="text"
|
||||
class="form-control input-sm js-impact-on-price"
|
||||
value="<?= htmlspecialchars($impact, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
placeholder="+10.00 / -5.50"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<?php foreach ($languages as $language): ?>
|
||||
<?php
|
||||
if ((int)($language['status'] ?? 0) !== 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$langId = (string)($language['id'] ?? '');
|
||||
if ($langId === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$langName = (string)($language['name'] ?? $langId);
|
||||
$langValue = '';
|
||||
if (is_array($value['languages'] ?? null) && isset($value['languages'][$langId]['name'])) {
|
||||
$langValue = (string)$value['languages'][$langId]['name'];
|
||||
}
|
||||
?>
|
||||
<div class="form-group mb10">
|
||||
<label class="control-label" style="display:block;">
|
||||
<?= htmlspecialchars($langName, ENT_QUOTES, 'UTF-8'); ?>
|
||||
<?= $langId === $defaultLanguageId ? '<span style="color:#e74c3c;">*</span>' : ''; ?>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control input-sm js-value-name"
|
||||
data-lang-id="<?= htmlspecialchars($langId, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
value="<?= htmlspecialchars($langValue, ENT_QUOTES, 'UTF-8'); ?>"
|
||||
placeholder="Nazwa wartosci"
|
||||
/>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</td>
|
||||
<td class="text-center" style="width: 100px;">
|
||||
<button type="button" class="btn btn-xs btn-danger js-value-remove">
|
||||
<i class="fa fa-trash"></i> Usun
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<div class="panel panel-widget draft-widget" value-number="<?= $this -> i;?>">
|
||||
<div class="panel-heading with-buttons">
|
||||
<span class="panel-title">Wartość <?= $this -> i;?></span>
|
||||
<div class="btn btn-danger btn-value-remove">
|
||||
<i class="fa fa-trash"></i> Usuń wartość
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body p20">
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="mb20">
|
||||
<input type="radio" id="default_value<?= $this -> value ? $this -> value['id'] : '0';?>" name="default_value" value="<?= ( $this -> i - 1 );?>" <? if ( $this -> value and $this -> value['is_default'] ):?>checked<? endif;?>>
|
||||
<label for="default_value<?= $this -> value ? $this -> value['id'] : '0';?>">Wartość domyślna</label>
|
||||
</div>
|
||||
<div class="row form-group">
|
||||
<div class="col-xs-8">
|
||||
<div class="input-group">
|
||||
<input class="form-control" name="impact_on_the_price[]" type="text" value="<?= $this -> value ? $this -> value['impact_on_the_price'] : '';?>" placeholder="wpływ na cenę produktu...">
|
||||
<span class="input-group-addon">
|
||||
<i class="fa fa-usd"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="tab-block mb25">
|
||||
<ul class="nav nav-tabs nav-tabs-right tabs-border">
|
||||
<? $z = 0;?>
|
||||
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
|
||||
<? if ( $lg['status'] ):?>
|
||||
<li class="<? if ( !$z++ ):?>active<? endif;?>">
|
||||
<a href="#tab<?= $this -> i;?>_<?= $lg['id'];?>" data-toggle="tab" aria-expanded="true"><?= $lg['name'];?></a>
|
||||
</li>
|
||||
<? endif;?>
|
||||
<? endforeach; endif;?>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<? $z = 0;?>
|
||||
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
|
||||
<? if ( $lg['status'] ):?>
|
||||
<div id="tab<?= $this -> i;?>_<?= $lg['id'];?>" class="tab-pane <? if ( !$z++ ):?>active<? endif;?>">
|
||||
<? if ( $this -> attribute['type'] == 0 ):?>
|
||||
<input type="hidden" name="ids[<?= $lg['id'];?>][]" value="<?= $this -> value ? $this -> value['id'] : '0';?>" />
|
||||
<input type="text" class="name-<?= $i;?> form-control" name="name[<?= $lg['id'];?>][]" value="<?= $this -> value ? $this -> value['languages'][$lg['id']]['name'] : '';?>">
|
||||
<? endif;?>
|
||||
</div>
|
||||
<? endif;?>
|
||||
<? endforeach; endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,106 +1,2 @@
|
||||
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/ckeditor.js"></script>
|
||||
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/adapters/jquery.js"></script>
|
||||
<?php
|
||||
global $db;
|
||||
ob_start();
|
||||
?>
|
||||
<div id="settings-tabs">
|
||||
<ul class="resp-tabs-list settings-tabs">
|
||||
<li><i class="fa fa-file"></i>Treść</li>
|
||||
<li><i class="fa fa-wrench"></i>Ustawienia</li>
|
||||
</ul>
|
||||
<div class="resp-tabs-container settings-tabs">
|
||||
<div>
|
||||
<div id="languages-main">
|
||||
<ul class="resp-tabs-list languages-main htabs">
|
||||
<?php if (is_array($this -> languages)) : foreach ($this -> languages as $lg) : ?>
|
||||
<?php if ($lg['status']) : ?>
|
||||
<li><?php echo $lg['name']; ?></a></li>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; endif; ?>
|
||||
</ul>
|
||||
<div class="resp-tabs-container languages-main">
|
||||
<?php if (is_array($this -> languages)) : foreach ($this -> languages as $lg) : ?>
|
||||
<?php if ($lg['status']) : ?>
|
||||
<div>
|
||||
<?= \Html::input( [
|
||||
'label' => 'Tytuł',
|
||||
'name' => 'name[' . $lg['id'] . ']',
|
||||
'id' => 'name_' . $lg['id'],
|
||||
'value' => $this -> attribute['languages'][ $lg['id'] ]['name'],
|
||||
'inline' => true,
|
||||
] ); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; endif; ?>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<?= \Html::input_switch( [
|
||||
'label' => 'Aktywny',
|
||||
'name' => 'status',
|
||||
'checked' => $this -> attribute['status'] || !$this -> attribute['id'] ? true : false,
|
||||
] );?>
|
||||
<?= \Html::select( [
|
||||
'label' => 'Typ',
|
||||
'name' => 'type',
|
||||
'values' => [0 => 'tekst'],//, 1 => 'kolor', 2 => 'wzór'],
|
||||
'value' => $this -> attribute['type'],
|
||||
] );?>
|
||||
<?= \Html::input( [
|
||||
'label' => 'Kolejność',
|
||||
'name' => 'o',
|
||||
'id' => 'o',
|
||||
'value' => $this -> attribute['o'],
|
||||
] );?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$out = ob_get_clean();
|
||||
<?= \Tpl::view('components/form-edit', ['form' => $this->form]); ?>
|
||||
|
||||
$grid = new \gridEdit();
|
||||
$grid -> id = 'attribute-edit';
|
||||
$grid -> gdb_opt = $gdb;
|
||||
$grid -> include_plugins = true;
|
||||
$grid -> title = 'Edycja cechy';
|
||||
$grid -> fields = [
|
||||
[
|
||||
'db' => 'id',
|
||||
'type' => 'hidden',
|
||||
'value' => $this -> attribute['id'],
|
||||
],
|
||||
];
|
||||
$grid -> actions = [
|
||||
'save' => ['url' => '/admin/shop_attribute/attribute_save/', 'back_url' => '/admin/shop_attribute/view_list/'],
|
||||
'cancel' => ['url' => '/admin/shop_attribute/view_list/'],
|
||||
];
|
||||
$grid -> external_code = $out;
|
||||
$grid -> persist_edit = true;
|
||||
$grid -> id_param = 'id';
|
||||
|
||||
echo $grid -> draw();
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$( function()
|
||||
{
|
||||
disable_menu();
|
||||
|
||||
$( '#settings-tabs' ).easyResponsiveTabs({
|
||||
width: 'auto',
|
||||
fit: true,
|
||||
tabidentify: 'settings-tabs',
|
||||
type: 'vertical'
|
||||
});
|
||||
|
||||
$( '#languages-main' ).easyResponsiveTabs({
|
||||
width: 'auto',
|
||||
fit: true,
|
||||
tabidentify: 'languages-main'
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
|
||||
|
||||
@@ -1,95 +1,2 @@
|
||||
<?php
|
||||
<?= \Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>
|
||||
|
||||
global $gdb;
|
||||
|
||||
$grid = new \grid('pp_shop_attributes');
|
||||
$grid -> gdb_opt = $gdb;
|
||||
$grid -> sql = 'SELECT *'
|
||||
. 'FROM ( '
|
||||
. 'SELECT '
|
||||
. 'id, status, type, o, '
|
||||
. '( SELECT psal.name FROM pp_shop_attributes_langs AS psal, pp_langs AS pl WHERE lang_id = pl.id AND attribute_id = psa.id AND psal.name != \'\' ORDER BY o ASC LIMIT 1 ) AS name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_attributes AS psa '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. '1=1 [where] '
|
||||
. 'ORDER BY '
|
||||
. '[order_p1] [order_p2]';
|
||||
$grid -> sql_count = 'SELECT '
|
||||
. 'COUNT(0) FROM ( '
|
||||
. 'SELECT '
|
||||
. 'id, status, type, o, '
|
||||
. '( SELECT psal.name FROM pp_shop_attributes_langs AS psal, pp_langs AS pl WHERE lang_id = pl.id AND attribute_id = psa.id AND psal.name != \'\' ORDER BY o ASC LIMIT 1 ) AS name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_attributes AS psa '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. '1=1 [where] ';
|
||||
$grid -> debug = true;
|
||||
$grid -> order = [ 'column' => 'o', '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' => 'Kolejność',
|
||||
'td' => [ 'class' => 'g-center', 'style' => 'width: 100px' ],
|
||||
'db' => 'o',
|
||||
'sort' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'Nazwa',
|
||||
'db' => 'name',
|
||||
'php' => 'echo "<a href=\'/admin/shop_attribute/attribute_edit/id=[id]\'>[name]</a>";',
|
||||
'sort' => true,
|
||||
],
|
||||
[
|
||||
'name' => 'Typ',
|
||||
'db' => 'type',
|
||||
'replace' => ['array' => [0 => 'tekst', 1 => 'kolor', 2 => 'wzór']],
|
||||
'td' => ['class' => 'g-center'],
|
||||
'th' => ['class' => 'g-center', 'style' => 'width: 150px;'],
|
||||
'sort' => true,
|
||||
], [
|
||||
'name' => 'Aktywny',
|
||||
'db' => 'status',
|
||||
'replace' => ['array' => [0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak']],
|
||||
'td' => ['class' => 'g-center'],
|
||||
'th' => ['class' => 'g-center', 'style' => 'width: 150px;'],
|
||||
'sort' => true,
|
||||
], [
|
||||
'name' => 'Wartości',
|
||||
'td' => ['class' => 'g-center'],
|
||||
'th' => ['class' => 'g-center', 'style' => 'width: 150px;'],
|
||||
'php' => 'echo "<a href=\'/admin/shop_attribute/values_edit/attribute-id=[id]\'>edytuj wartości</a>";',
|
||||
],
|
||||
[
|
||||
'name' => 'Edytuj',
|
||||
'action' => ['type' => 'edit', 'url' => '/admin/shop_attribute/attribute_edit/id=[id]'],
|
||||
'th' => ['class' => 'g-center', 'style' => 'width: 70px;'],
|
||||
'td' => ['class' => 'g-center'],
|
||||
],
|
||||
[
|
||||
'name' => 'Usuń',
|
||||
'action' => ['type' => 'delete', 'url' => '/admin/shop_attribute/delete_attribute/id=[id]'],
|
||||
'th' => ['class' => 'g-center', 'style' => 'width: 70px;'],
|
||||
'td' => ['class' => 'g-center'],
|
||||
],
|
||||
];
|
||||
$grid -> buttons = [
|
||||
[
|
||||
'label' => 'Dodaj cechę',
|
||||
'url' => '/admin/shop_attribute/attribute_edit/',
|
||||
'icon' => 'fa-plus-circle',
|
||||
'class' => 'btn-success',
|
||||
],
|
||||
];
|
||||
echo $grid -> draw();
|
||||
|
||||
@@ -1,138 +1,274 @@
|
||||
<div class="panel panel-widget draft-widget" value-numer="<?= $this -> i;?>">
|
||||
<?php
|
||||
$attribute = is_array($this->attribute ?? null) ? $this->attribute : [];
|
||||
$values = is_array($this->values ?? null) ? $this->values : [];
|
||||
$languages = is_array($this->languages ?? null) ? $this->languages : [];
|
||||
$defaultLanguageId = (string)($this->defaultLanguageId ?? '');
|
||||
|
||||
$activeLanguages = [];
|
||||
foreach ($languages as $language) {
|
||||
if ((int)($language['status'] ?? 0) === 1) {
|
||||
$activeLanguages[] = $language;
|
||||
}
|
||||
}
|
||||
|
||||
if ($defaultLanguageId === '' && !empty($activeLanguages[0]['id'])) {
|
||||
$defaultLanguageId = (string)$activeLanguages[0]['id'];
|
||||
}
|
||||
|
||||
$attributeName = '';
|
||||
if ($defaultLanguageId !== '' && isset($attribute['languages'][$defaultLanguageId]['name'])) {
|
||||
$attributeName = trim((string)$attribute['languages'][$defaultLanguageId]['name']);
|
||||
}
|
||||
if ($attributeName === '' && is_array($attribute['languages'] ?? null)) {
|
||||
foreach ($attribute['languages'] as $languageData) {
|
||||
$candidateName = trim((string)($languageData['name'] ?? ''));
|
||||
if ($candidateName !== '') {
|
||||
$attributeName = $candidateName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($attributeName === '') {
|
||||
$attributeName = 'ID: ' . (int)($attribute['id'] ?? 0);
|
||||
}
|
||||
|
||||
$rowCounter = 0;
|
||||
$initialRowsHtml = '';
|
||||
if (!empty($values)) {
|
||||
foreach ($values as $value) {
|
||||
++$rowCounter;
|
||||
$rowKey = 'existing-' . (int)($value['id'] ?? 0);
|
||||
$initialRowsHtml .= \Tpl::view('shop-attribute/_partials/value-row', [
|
||||
'rowKey' => $rowKey,
|
||||
'value' => $value,
|
||||
'languages' => $activeLanguages,
|
||||
'defaultLanguageId' => $defaultLanguageId,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$rowCounter = 1;
|
||||
$initialRowsHtml .= \Tpl::view('shop-attribute/_partials/value-row', [
|
||||
'rowKey' => 'new-1',
|
||||
'value' => ['id' => 0, 'is_default' => 1, 'impact_on_the_price' => null, 'languages' => []],
|
||||
'languages' => $activeLanguages,
|
||||
'defaultLanguageId' => $defaultLanguageId,
|
||||
]);
|
||||
}
|
||||
|
||||
$newRowTemplate = \Tpl::view('shop-attribute/_partials/value-row', [
|
||||
'rowKey' => '__ROW_KEY__',
|
||||
'value' => ['id' => 0, 'is_default' => 0, 'impact_on_the_price' => null, 'languages' => []],
|
||||
'languages' => $activeLanguages,
|
||||
'defaultLanguageId' => $defaultLanguageId,
|
||||
]);
|
||||
?>
|
||||
|
||||
<div class="panel panel-widget draft-widget">
|
||||
<div class="panel-heading with-buttons">
|
||||
<span class="panel-title">Edycja wartości dla cechy: <?= $this -> attribute['languages']['pl']['name'];?></span>
|
||||
<span class="panel-title">Wartosci cechy: <?= htmlspecialchars($attributeName, ENT_QUOTES, 'UTF-8'); ?></span>
|
||||
<div class="buttons">
|
||||
<a class="btn btn-success btn-save" href="#">
|
||||
<a class="btn btn-success js-values-save" href="#">
|
||||
<i class="fa fa-save"></i> zapisz
|
||||
</a>
|
||||
<a class="btn btn-dark" href="/admin/shop_attribute/view_list/">
|
||||
<a class="btn btn-dark" href="/admin/shop_attribute/list/">
|
||||
<i class="fa fa-ban"></i> wstecz
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel-body p20">
|
||||
<button class="btn btn-success mb10 btn-value-add">
|
||||
<i class="fa fa-plus-circle mr5"></i>Dodaj wartość
|
||||
</button>
|
||||
<div class="values-content">
|
||||
<?
|
||||
if ( $this -> values ):
|
||||
foreach ( $this -> values as $value ):
|
||||
echo \Tpl::view( 'shop-attribute/_partials/value', [
|
||||
'i' => ++$i,
|
||||
'value' => $value,
|
||||
'languages' => $this -> languages,
|
||||
'attribute' => $this -> attribute
|
||||
] );
|
||||
endforeach;
|
||||
endif;
|
||||
?>
|
||||
<div class="mb10">
|
||||
<button type="button" class="btn btn-success js-value-add">
|
||||
<i class="fa fa-plus-circle mr5"></i>Dodaj wartosc
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-info">
|
||||
<strong>Wskazowka:</strong> zaznacz jedna wartosc domyslna i uzupelnij nazwe w jezyku domyslnym.
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-bordered table-striped" id="attribute-values-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center" style="width: 90px;">Domyslna</th>
|
||||
<th style="width: 180px;">Wplyw na cene</th>
|
||||
<th>Nazwy w jezykach</th>
|
||||
<th class="text-center" style="width: 100px;">Akcje</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="attribute-values-body">
|
||||
<?= $initialRowsHtml; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function ()
|
||||
{
|
||||
disable_menu();
|
||||
$(function() {
|
||||
disable_menu();
|
||||
|
||||
$( 'body' ).on( 'click', '.btn-save', function()
|
||||
{
|
||||
var values = jQuery( '.dashboard-page' ).find( 'input, select, textarea' ).serializeObject();
|
||||
var attributeId = <?= (int)($attribute['id'] ?? 0); ?>;
|
||||
var defaultLanguageId = <?= json_encode($defaultLanguageId); ?>;
|
||||
var rowCounter = <?= (int)$rowCounter; ?>;
|
||||
var newRowTemplate = <?= json_encode($newRowTemplate); ?>;
|
||||
|
||||
jQuery.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/shop_attribute/values_save/',
|
||||
data: {
|
||||
values: JSON.stringify( values ),
|
||||
attribute_id: <?= $this -> attribute['id'];?>,
|
||||
},
|
||||
beforeSend: function() {
|
||||
jQuery( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
var data = jQuery.parseJSON( response );
|
||||
jQuery( '#overlay' ).hide();
|
||||
if ( data.status === 'ok' )
|
||||
{
|
||||
var msg = "Zapisano wartości atrybutu";
|
||||
alert_message( msg );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( data.msg )
|
||||
var msg = data.msg;
|
||||
else
|
||||
var msg = "Przepraszamy. Podczas wczytywania danych wystąpił błąd. Prosimy spróbować ponownie.";
|
||||
create_error( msg );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
function showError(message) {
|
||||
if (typeof create_error === 'function') {
|
||||
create_error(message);
|
||||
return;
|
||||
}
|
||||
alert(message);
|
||||
}
|
||||
|
||||
$( 'body').on( 'click', '.btn-value-add', function ()
|
||||
{
|
||||
var maxVal = Math.max.apply(null, $('div[value-number]').map(function() {
|
||||
var val = parseInt($(this).attr('value-number'));
|
||||
return isNaN(val) ? 0 : val; // Jeżeli wartość nie jest liczbą, zwróć 0
|
||||
}).get());
|
||||
function showSuccess(message) {
|
||||
if (typeof alert_message === 'function') {
|
||||
alert_message(message);
|
||||
return;
|
||||
}
|
||||
alert(message);
|
||||
}
|
||||
|
||||
if (!isFinite(maxVal)) {
|
||||
maxVal = 0;
|
||||
function addRow() {
|
||||
rowCounter += 1;
|
||||
var rowKey = 'new-' + rowCounter;
|
||||
var rowHtml = newRowTemplate.split('__ROW_KEY__').join(rowKey);
|
||||
$('#attribute-values-body').append(rowHtml);
|
||||
|
||||
if ($('input[name="default_row_key"]:checked').length === 0) {
|
||||
$('input[name="default_row_key"][value="' + rowKey + '"]').prop('checked', true);
|
||||
}
|
||||
}
|
||||
|
||||
function collectRows() {
|
||||
var defaultRowKey = $('input[name="default_row_key"]:checked').val() || '';
|
||||
var rows = [];
|
||||
|
||||
$('#attribute-values-body .attribute-value-row').each(function() {
|
||||
var $row = $(this);
|
||||
var rowKey = String($row.data('rowKey') || '');
|
||||
var valueId = parseInt($row.find('.js-value-id').val(), 10);
|
||||
if (isNaN(valueId)) {
|
||||
valueId = 0;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/admin/shop_attribute/attribute_value_tpl/',
|
||||
type: 'POST',
|
||||
data: {
|
||||
i: maxVal + 1,
|
||||
value: null,
|
||||
languages: <?= json_encode( $this -> languages );?>,
|
||||
attribute: <?= json_encode( $this -> attribute );?>
|
||||
},
|
||||
success: function( response )
|
||||
{
|
||||
$('.values-content').append(response);
|
||||
var impactOnPrice = $.trim(String($row.find('.js-impact-on-price').val() || ''));
|
||||
var translations = {};
|
||||
|
||||
$row.find('.js-value-name').each(function() {
|
||||
var $input = $(this);
|
||||
var langId = String($input.data('langId') || '');
|
||||
if (langId === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
translations[langId] = {
|
||||
name: $.trim(String($input.val() || '')),
|
||||
value: ''
|
||||
};
|
||||
});
|
||||
|
||||
rows.push({
|
||||
id: valueId,
|
||||
row_key: rowKey,
|
||||
is_default: rowKey !== '' && rowKey === defaultRowKey,
|
||||
impact_on_the_price: impactOnPrice,
|
||||
translations: translations
|
||||
});
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.btn-value-remove', function()
|
||||
{
|
||||
var button = $( this );
|
||||
$.alert({
|
||||
title: 'Potwierdź',
|
||||
content: 'Na pewno chcesz usunąć wybraną wartość?',
|
||||
type: 'orange',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-close',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
autoClose: 'confirm|10000',
|
||||
useBootstrap: false,
|
||||
theme: 'modern',
|
||||
autoClose: 'cancel|10000',
|
||||
icon: 'fa fa-exclamation',
|
||||
buttons:
|
||||
{
|
||||
confirm:
|
||||
{
|
||||
text: 'TAK usuń',
|
||||
btnClass: 'btn-orange',
|
||||
keys: ['enter'],
|
||||
action: function()
|
||||
{
|
||||
button.closest( '.panel' ).remove();
|
||||
}
|
||||
},
|
||||
cancel:
|
||||
{
|
||||
text: 'anuluj',
|
||||
btnClass: 'btn-blue',
|
||||
action: function() {}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
function validateRows(rows) {
|
||||
if (!Array.isArray(rows) || rows.length === 0) {
|
||||
return 'Dodaj co najmniej jedna wartosc cechy.';
|
||||
}
|
||||
|
||||
var defaultCount = 0;
|
||||
var decimalRegex = /^-?[0-9]+([.,][0-9]{1,4})?$/;
|
||||
|
||||
for (var i = 0; i < rows.length; i += 1) {
|
||||
var row = rows[i] || {};
|
||||
if (row.is_default) {
|
||||
defaultCount += 1;
|
||||
}
|
||||
|
||||
var translations = row.translations || {};
|
||||
var defaultLang = translations[defaultLanguageId] || {};
|
||||
var defaultName = $.trim(String(defaultLang.name || ''));
|
||||
if (defaultName === '') {
|
||||
return 'Wiersz nr ' + (i + 1) + ': nazwa w jezyku domyslnym jest wymagana.';
|
||||
}
|
||||
|
||||
var impact = $.trim(String(row.impact_on_the_price || ''));
|
||||
if (impact !== '' && !decimalRegex.test(impact)) {
|
||||
return 'Wiersz nr ' + (i + 1) + ': nieprawidlowy format "wplyw na cene".';
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultCount !== 1) {
|
||||
return 'Wybierz dokladnie jedna wartosc domyslna.';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$('body').on('click', '.js-value-add', function() {
|
||||
addRow();
|
||||
});
|
||||
|
||||
$('body').on('click', '.js-value-remove', function() {
|
||||
var $row = $(this).closest('.attribute-value-row');
|
||||
if ($('#attribute-values-body .attribute-value-row').length <= 1) {
|
||||
showError('Musi pozostac przynajmniej jeden wiersz wartosci.');
|
||||
return;
|
||||
}
|
||||
|
||||
$row.remove();
|
||||
if ($('input[name="default_row_key"]:checked').length === 0) {
|
||||
$('#attribute-values-body .attribute-value-row:first .js-default-row').prop('checked', true);
|
||||
}
|
||||
});
|
||||
|
||||
$('body').on('click', '.js-values-save', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var rows = collectRows();
|
||||
var validationError = validateRows(rows);
|
||||
if (validationError !== '') {
|
||||
showError(validationError);
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/shop_attribute/values_save/id=' + attributeId,
|
||||
dataType: 'json',
|
||||
data: {
|
||||
payload: JSON.stringify({ rows: rows })
|
||||
},
|
||||
beforeSend: function() {
|
||||
$('#overlay').show();
|
||||
},
|
||||
success: function(response) {
|
||||
$('#overlay').hide();
|
||||
|
||||
if (response && response.status === 'ok') {
|
||||
showSuccess('Wartosci cechy zostaly zapisane.');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
var message = (response && response.msg) ? response.msg : 'Wystapil blad podczas zapisu danych.';
|
||||
showError(message);
|
||||
},
|
||||
error: function() {
|
||||
$('#overlay').hide();
|
||||
showError('Wystapil blad polaczenia podczas zapisu danych.');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
$attributes = explode( '|', $product['permutation_hash'] );
|
||||
foreach ( $attributes as $attribute ):
|
||||
$attribute_tmp = explode( '-', $attribute );
|
||||
echo \admin\factory\ShopAttribute::get_attribute_name_by_id( $attribute_tmp[0] ) . ' - <b>' . \admin\factory\ShopAttribute::get_attribute_value_by_id( $attribute_tmp[1] ) . '</b>';
|
||||
echo \shop\ProductAttribute::getAttributeName( (int)$attribute_tmp[0], $this -> default_language ) . ' - <b>' . \shop\ProductAttribute::get_value_name( (int)$attribute_tmp[1], $this -> default_language ) . '</b>';
|
||||
if ( $attribute != end( $attributes ) )
|
||||
echo ', ';
|
||||
endforeach;
|
||||
@@ -130,4 +130,4 @@
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<i class="fa fa-bars"></i>Komplety Produktów
|
||||
</a>
|
||||
</li>
|
||||
<li><a href="/admin/shop_attribute/view_list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produktów</a></li>
|
||||
<li><a href="/admin/shop_attribute/list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produktów</a></li>
|
||||
<li><a href="/admin/shop_transport/list/"><img src="/admin/layout/icon/icon-menu/bus.svg">Rodzaje transportu</a></li>
|
||||
<li><a href="/admin/shop_payment_method/list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody płatności</a></li>
|
||||
<li>
|
||||
|
||||
Reference in New Issue
Block a user