From: marina Date: Tue, 4 Feb 2025 07:53:29 +0000 (+0300) Subject: ERP-302 Редактирование букета X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=25fe351844d6d327797b10f14e5dd13ba7548643;p=erp24_rep%2Fyii-erp24%2F.git ERP-302 Редактирование букета --- diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 1444a2f2..c2a7d73b 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -31,6 +31,7 @@ class BouquetController extends Controller $products = Products1c::find() ->where(['tip' => Products1c::TYPE_PRODUCTS, 'view' => Products1c::IS_VISIBLE]) + ->andWhere(['ilike', 'name', 'роза']) ->asArray() ->all(); diff --git a/erp24/views/bouquet/update.php b/erp24/views/bouquet/update.php index 83a862af..1c9eef7c 100644 --- a/erp24/views/bouquet/update.php +++ b/erp24/views/bouquet/update.php @@ -11,7 +11,10 @@ use yii_app\records\Products1c; $this->title = 'Три гладиолуса'; $this->params['breadcrumbs'][] = ['label' => 'Букеты', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; + +$this->registerJsFile('/js/bouquet/bouquet.js', ['position' => \yii\web\View::POS_END]); ?> +
'h4']) ?>

title) ?>

@@ -54,10 +57,11 @@ $this->params['breadcrumbs'][] = $this->title; 'options' => [ 'multiple' => true, 'size' => 10, + 'id' => 'dual-list-box' ], 'triggerButton' => 'apply-button', // Кнопка, которая будет обновлять список 'clientOptions' => [ - 'moveOnSelect' => false, + 'moveOnSelect' => true, 'nonSelectedListLabel' => 'Выбор', 'selectedListLabel' => 'Состав букета', 'filterTextClear' => 'Показать всё', diff --git a/erp24/web/js/bouquet/bouquet.js b/erp24/web/js/bouquet/bouquet.js new file mode 100644 index 00000000..5f6a623e --- /dev/null +++ b/erp24/web/js/bouquet/bouquet.js @@ -0,0 +1,9 @@ +const observer = new MutationObserver(() => { + $('.removeall').each(function() { + $(this).remove(); + }); + console.log("Удалены все .removeall!"); +}); + +// Наблюдаем за изменениями в контейнере дуал-листбокса +observer.observe(document.body, { childList: true, subtree: true }); diff --git a/erp24/widgets/DualList.php b/erp24/widgets/DualList.php index 8aab21fd..2021cee1 100644 --- a/erp24/widgets/DualList.php +++ b/erp24/widgets/DualList.php @@ -2,65 +2,81 @@ namespace app\widgets; -use yii\helpers\Json; -use yii\web\View; use yii\helpers\Url; use softark\duallistbox\DualListbox; +use yii\web\View; + class DualList extends DualListbox { public $ajaxUrl; // URL для AJAX-запроса - public $triggerButton; // ID кнопки, которая будет запускать AJAX-запрос - protected function registerPlugin($id) - { - parent::registerPlugin($id); + public $triggerButton; // ID кнопки, которая запускает AJAX-запрос - $view = $this->getView(); + public function run() + { +// Рендерим сам виджет DualListbox + echo DualListbox::widget([ + 'name' => $this->name, + 'options' => $this->options, + 'items' => $this->items, // Передаем начальные данные + ]); - // Проверяем, что URL и кнопка переданы - if (!$this->ajaxUrl || !$this->triggerButton) { - return; +// Подключаем AJAX-обработчик, если передан URL и кнопка + if ($this->ajaxUrl && $this->triggerButton) { + $this->registerAjaxScript(); } + } - // Получаем URL для AJAX-запроса и кнопки + protected function registerAjaxScript() + { + $id = $this->options['id']; // ID DualListbox $ajaxUrl = Url::to($this->ajaxUrl); - $triggerButton = $this->triggerButton ? '#' . $this->triggerButton : null; - - // Скрипт для обработки клика по кнопке и отправки AJAX-запроса - $js = << ``); - $('#$id').html(options.join('')); // Очищаем список и добавляем новые данные - $('#$id').bootstrapDualListbox('refresh'); // Обновляем плагин - } - }, - error: function(xhr) { - console.error('Ошибка загрузки данных:', xhr); - } - }); - } + $buttonId = $this->triggerButton; // ID кнопки - // Проверим, что кнопка существует - $(document).on('click', '$triggerButton', function() { - console.log('Кнопка с ID $triggerButton нажата!'); - loadDualListboxData(); - }); + $script = <<registerJs($js); - } +// Очищаем список, но оставляем выбранные элементы +dualListbox.find('option').each(function() { +if (!selectedOptions.includes($(this).val())) { +$(this).remove(); } +}); +// Добавляем новые элементы +$.each(response, function(value, label) { +if (!dualListbox.find('option[value="'+ value +'"]').length) { +dualListbox.append(new Option(label, value, false, false)); +} +}); +// Восстанавливаем выбранные элементы +dualListbox.find('option').each(function() { +if (selectedOptions.includes($(this).val())) { +$(this).prop('selected', true); +} +}); +// Перезагрузка DualListbox +dualListbox.bootstrapDualListbox('refresh'); +}, +error: function(xhr) { +console.error('Ошибка AJAX-запроса:', xhr); +} +}); +}); +JS; + $this->view->registerJs($script, View::POS_READY); + } +}