From f4070f7e9d76d2e16932bd55b50d5f66de44c3e0 Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 15 Jan 2025 17:48:56 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20js?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/views/stores-type-list/index.php | 69 +-------------------- erp24/web/js/crud/stores-type-list/index.js | 64 +++++++++++++++++++ 2 files changed, 65 insertions(+), 68 deletions(-) create mode 100644 erp24/web/js/crud/stores-type-list/index.js diff --git a/erp24/views/stores-type-list/index.php b/erp24/views/stores-type-list/index.php index 7d689fde..d5901d45 100644 --- a/erp24/views/stores-type-list/index.php +++ b/erp24/views/stores-type-list/index.php @@ -10,7 +10,7 @@ use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ /* @var $model yii_app\records\StoresTypeList */ - +$this->registerJsFile('/js/crud/stores-type-list/index.js', ['position' => \yii\web\View::POS_END]); $this->title = 'Тип магазина'; $this->params['breadcrumbs'][] = $this->title; ?> @@ -78,70 +78,3 @@ $this->params['breadcrumbs'][] = $this->title; - - \ No newline at end of file diff --git a/erp24/web/js/crud/stores-type-list/index.js b/erp24/web/js/crud/stores-type-list/index.js new file mode 100644 index 00000000..d2d5167c --- /dev/null +++ b/erp24/web/js/crud/stores-type-list/index.js @@ -0,0 +1,64 @@ +document.addEventListener('DOMContentLoaded', function () { + const list = document.getElementById('record-list'); + const typeNameField = document.getElementById('type-name-field'); + const editIdInput = document.getElementById('edit-id'); + const deleteIdInput = document.getElementById('delete-id'); + const deleteBtn = document.getElementById('delete-btn'); + const cancelBtn = document.getElementById('cancel-btn'); + const saveBtn = document.getElementById('save-btn'); + const editBtn = document.getElementById('edit-btn'); + + list.addEventListener('click', function (event) { + const target = event.target; + if (target.classList.contains('list-group-item')) { + const id = target.dataset.id; + + fetch('/stores-type-list/get-record?id=' + id) + .then(response => response.json()) + .then(data => { + if (data.error) { + alert(data.error); + } else { + typeNameField.value = data.type_name; + editIdInput.value = id; + deleteIdInput.value = ''; + + document.querySelectorAll('.list-group-item').forEach(item => { + item.classList.remove('active'); + }); + target.classList.add('active'); + deleteBtn.classList.remove('d-none'); + editBtn.classList.remove('d-none'); + } + }); + } + }); + + editBtn.addEventListener('click', function () { + const id = editIdInput.value; + if (id) { + saveBtn.click(); + } else { + alert('Выберите запись для редактирования.'); + } + }); + + deleteBtn.addEventListener('click', function () { + const id = editIdInput.value; + if (id && confirm('Вы уверены, что хотите удалить запись?')) { + deleteIdInput.value = id; + saveBtn.click(); + } + }); + + cancelBtn.addEventListener('click', function () { + typeNameField.value = ''; + editIdInput.value = ''; + deleteIdInput.value = ''; + deleteBtn.classList.add('d-none'); + editBtn.classList.add('d-none'); + document.querySelectorAll('.list-group-item').forEach(item => { + item.classList.remove('active'); + }); + }); +}); \ No newline at end of file -- 2.39.5