Рефакторинг POS терминала: устранение дублирования кода и оптимизация UI
- Удалены дублирующиеся функции getCookie() и getCsrfToken() в terminal.js - Оставлена единая версия getCookie() с алиасом getCsrfToken для совместимости - Удалены неиспользуемые пустые кнопки из панели действий - Добавлена логика скрытия поля 'Количество букетов' в режиме редактирования комплекта - Оптимизирована компоновка кнопок действий (используется offset-4) - Улучшены комментарии в коде Результат: -44 строки, код стал чище и поддерживаемее
This commit is contained in:
@@ -1171,8 +1171,9 @@ async function openEditKitModal(kitId) {
|
||||
document.getElementById('createTempKitModalLabel').textContent = 'Редактирование витринного букета';
|
||||
document.getElementById('confirmCreateTempKit').textContent = 'Сохранить изменения';
|
||||
|
||||
// Показываем кнопку "Разобрать" в режиме редактирования
|
||||
// Показываем кнопку "Разобрать" и скрываем поле "Количество букетов" в режиме редактирования
|
||||
document.getElementById('disassembleKitBtn').style.display = 'block';
|
||||
document.getElementById('showcaseKitQuantityBlock').style.display = 'none';
|
||||
|
||||
// Открываем модальное окно
|
||||
const modal = new bootstrap.Modal(document.getElementById('createTempKitModal'));
|
||||
@@ -1579,7 +1580,7 @@ document.getElementById('disassembleKitBtn').addEventListener('click', async ()
|
||||
}
|
||||
});
|
||||
|
||||
// Вспомогательная функция для получения CSRF токена
|
||||
// Вспомогательная функция для получения CSRF токена (единая версия)
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
@@ -1595,11 +1596,15 @@ function getCookie(name) {
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
// Алиас для обратной совместимости
|
||||
const getCsrfToken = () => getCookie('csrftoken');
|
||||
|
||||
// Сброс режима редактирования при закрытии модального окна
|
||||
document.getElementById('createTempKitModal').addEventListener('hidden.bs.modal', function() {
|
||||
// Очищаем tempCart (изолированное состояние модалки)
|
||||
tempCart.clear();
|
||||
|
||||
// Сброс режима редактирования при закрытии модального окна
|
||||
if (isEditMode) {
|
||||
// Сбрасываем режим редактирования
|
||||
isEditMode = false;
|
||||
@@ -1609,8 +1614,9 @@ document.getElementById('createTempKitModal').addEventListener('hidden.bs.modal'
|
||||
document.getElementById('createTempKitModalLabel').textContent = 'Создать витринный букет из корзины';
|
||||
document.getElementById('confirmCreateTempKit').innerHTML = '<i class="bi bi-check-circle"></i> Создать и зарезервировать';
|
||||
|
||||
// Скрываем кнопку "Разобрать"
|
||||
// Скрываем кнопку "Разобрать" и показываем поле "Количество букетов"
|
||||
document.getElementById('disassembleKitBtn').style.display = 'none';
|
||||
document.getElementById('showcaseKitQuantityBlock').style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1833,21 +1839,6 @@ async function handleCheckoutSubmit(paymentsData) {
|
||||
}
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
// ===== ОБРАБОТЧИКИ ДЛЯ РАБОТЫ С КЛИЕНТОМ =====
|
||||
|
||||
// Кнопка "Выбрать клиента" в корзине
|
||||
@@ -1958,22 +1949,7 @@ document.addEventListener('click', async (e) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Вспомогательная функция для получения CSRF токена
|
||||
function getCsrfToken() {
|
||||
const name = 'csrftoken';
|
||||
let cookieValue = null;
|
||||
if (document.cookie && document.cookie !== '') {
|
||||
const cookies = document.cookie.split(';');
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
const cookie = cookies[i].trim();
|
||||
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
||||
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookieValue;
|
||||
}
|
||||
|
||||
|
||||
// Обработчик поиска с debounce
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
|
||||
@@ -98,22 +98,6 @@
|
||||
<i class="bi bi-flower1"></i><br>На витрину
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-secondary rounded-3 w-100" style="height: 60px;">
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-secondary rounded-3 w-100" style="height: 60px;">
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-secondary rounded-3 w-100" style="height: 60px;">
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-secondary rounded-3 w-100" style="height: 60px;">
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-primary rounded-3 w-100" id="scheduleLater" style="height: 60px;">
|
||||
<i class="bi bi-calendar2"></i><br>Отложенный заказ
|
||||
@@ -124,11 +108,7 @@
|
||||
<i class="bi bi-trash"></i><br>Очистить
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<button class="btn btn-outline-secondary rounded-3 w-100" style="height: 60px;">
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="col-4 offset-4">
|
||||
<button class="btn btn-success rounded-3 w-100" id="checkoutNow" style="height: 60px;">
|
||||
<i class="bi bi-check2-circle"></i><br>Продать
|
||||
</button>
|
||||
@@ -170,8 +150,8 @@
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<!-- Количество букетов -->
|
||||
<div class="mb-3">
|
||||
<!-- Количество букетов (только при создании) -->
|
||||
<div class="mb-3" id="showcaseKitQuantityBlock">
|
||||
<label for="showcaseKitQuantity" class="form-label">Сколько букетов создать</label>
|
||||
<input type="number" class="form-control" id="showcaseKitQuantity" value="1" min="1" max="99">
|
||||
<small class="text-muted">Будет создано указанное количество одинаковых букетов на витрину</small>
|
||||
|
||||
Reference in New Issue
Block a user