From: fomichev Date: Fri, 22 Nov 2024 16:23:08 +0000 (+0300) Subject: Настройка привязки классов X-Git-Tag: 1.7~212^2~13 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=23245c7cc63c70750c29d761a2c71fe9d3522be2;p=erp24_rep%2Fyii-erp24%2F.git Настройка привязки классов --- diff --git a/erp24/controllers/ProductsController.php b/erp24/controllers/ProductsController.php index 7601c844..62395779 100755 --- a/erp24/controllers/ProductsController.php +++ b/erp24/controllers/ProductsController.php @@ -224,7 +224,7 @@ class ProductsController extends Controller ->all(); $properties = ArrayHelper::map($properties, 'id', 'name'); - // var_dump($properties); die(); + $result = []; foreach ($characteristics as $characteristic) { $propertyName = $properties[$characteristic['property_id']] ?? 'Неизвестное свойство'; @@ -398,7 +398,7 @@ class ProductsController extends Controller if ($productClass) { if ($productClass->delete()) { - return "Метка удалена"; + return "ok"; } else { return "Ошибка удаления метки"; } diff --git a/erp24/records/ProductsClass.php b/erp24/records/ProductsClass.php index a018cdfc..03bee199 100755 --- a/erp24/records/ProductsClass.php +++ b/erp24/records/ProductsClass.php @@ -57,4 +57,9 @@ class ProductsClass extends \yii\db\ActiveRecord 'tip' => 'Tip', ]; } + + public static function primaryKey() + { + return ['category_id', 'tip']; + } } diff --git a/erp24/web/js/products/products-1c.js b/erp24/web/js/products/products-1c.js index 79b385f7..ad502291 100644 --- a/erp24/web/js/products/products-1c.js +++ b/erp24/web/js/products/products-1c.js @@ -1,5 +1,7 @@ //document.addEventListener('DOMContentLoaded', function () { - +function capitalizeFirstLetter(string) { + return string.charAt(0).toUpperCase() + string.slice(1) +} function ajax_product_provider(id) { $('#modal-7').modal('show', {backdrop: 'static'}); $('#modal-7 .modal-title').text('Поставщики'); @@ -77,7 +79,7 @@ function ajax_group_config(id) { $.ajax({ url: '/products/ajax-group-config/', method: 'post', - dataType: 'json', // Ожидаем данные в формате JSON + dataType: 'json', data: { id: id, [param3]: token3 }, success: function(response) { if (response.error) { @@ -86,18 +88,19 @@ function ajax_group_config(id) { } - let html = '
'; // Flex-контейнер + let html = '
'; const classes = response.classes; const data2 = response.data2; + for (const [key, name] of Object.entries(classes)) { html += `
${name}
${data2[key] - ? `
(${key})
` - : `
(${key})
`} + ? `
(${key})
` + : `
(${key})
`}
`; @@ -183,6 +186,59 @@ function ajax_group_config(id) { }); } +function ajax_class_group(parent_id, tip) { + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-class-group/', + method: 'post', + dataType: 'html', + data: { parent_id: parent_id, tip: tip, [param3]: token3 }, + success: function (data) { + if (data === 'ok') { + const button = $(`.dd${parent_id}${tip}`); + button.removeClass('add btn-success') + .addClass('delete btn-danger') + .attr('onclick', `ajax_class_group_remove('${parent_id}', '${tip}');`) + .text('удалить'); + } else { + alert('Ошибка: ' + data); + } + }, + error: function () { + alert('Ошибка при выполнении запроса.'); + }, + }); +} + + +function ajax_class_group_remove(id, tip) { + const param3 = $('meta[name=csrf-param]').attr('content'); + const token3 = $('meta[name=csrf-token]').attr('content'); + + $.ajax({ + url: '/products/ajax-class-group-remove/', + method: 'post', + dataType: 'html', + data: { id: id, tip: tip, [param3]: token3 }, + success: function (data) { + if (data === 'ok') { + const button = $(`.dd${id}${tip}`); + button.removeClass('delete btn-danger') + .addClass('add btn-success') + .attr('onclick', `ajax_class_group('${id}', '${tip}');`) + .text('добавить'); + } else { + alert('Ошибка: ' + data); + } + }, + error: function () { + alert('Ошибка при выполнении запроса.'); + }, + }); +} + function save_providerder(){ const param3 = $('meta[name=csrf-param]').attr('content'); @@ -256,8 +312,6 @@ function ajax_group_config(id) { }}); } -function capitalizeFirstLetter(string) { - return string.charAt(0).toUpperCase() + string.slice(1) -} + //}); \ No newline at end of file