fix(products): improve bulk category modal and batch selection handling

- Add null check for selectAllCheckbox to avoid errors in batch-selection.js
- Replace clear existing categories toggle with radio buttons for add, replace, and clear modes
- Disable category search input and fade category list when 'clear' mode is selected
- Update mode hint text dynamically based on selected mode with explanatory messages
- Enable apply button when 'clear' mode is selected regardless of category selection
- Remove clear all categories button from modal footer
- Add event listeners for mode radio buttons to update UI and error states on change
- Initialize mode UI and apply button state on modal setup
- Bump static JS files versions for batch-selection and bulk-category-modal to 1.2 and 1.4 respectively
This commit is contained in:
2026-01-10 00:47:42 +03:00
parent b63162b1cb
commit 0d6d62d1ad
3 changed files with 101 additions and 21 deletions

View File

@@ -415,22 +415,41 @@
<span id="selectedItemsBreakdown" class="ms-2 text-muted"></span>
</div>
<!-- Опции применения -->
<!-- Режим изменения категорий -->
<div class="mb-4">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="clearExistingCategoriesToggle" role="switch">
<label class="form-check-label" for="clearExistingCategoriesToggle">
<i class="bi bi-trash"></i> Очистить существующие категории перед сохранением
<label class="form-label fw-bold">Что сделать с категориями выбранных товаров?</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="bulkCategoryMode"
id="bulkCategoryModeAdd" value="add" checked>
<label class="form-check-label" for="bulkCategoryModeAdd">
Добавить выбранные категории к существующим
</label>
<div class="form-text text-warning">
<i class="bi bi-exclamation-triangle"></i>
При включении все текущие категории товаров будут удалены, а затем применены только выбранные ниже
</div>
</div>
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="bulkCategoryMode"
id="bulkCategoryModeReplace" value="replace">
<label class="form-check-label" for="bulkCategoryModeReplace">
Заменить существующие категории выбранными
</label>
</div>
<div class="form-check mt-2">
<input class="form-check-input" type="radio" name="bulkCategoryMode"
id="bulkCategoryModeClear" value="clear">
<label class="form-check-label text-danger" for="bulkCategoryModeClear">
<strong>Удалить все категории</strong>
</label>
</div>
<div id="bulkCategoryModeHint" class="form-text text-muted mt-2">
Добавленные категории будут присоединены к уже существующим.
</div>
</div>
<!-- Выбор категорий -->
<div class="mb-3">
<div class="mb-3" id="bulkCategoryListSection">
<label class="form-label fw-bold">Выберите категории:</label>
<!-- Поиск по категориям -->
@@ -452,9 +471,6 @@
<div id="bulkCategoryError" class="alert alert-danger d-none" role="alert"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger me-auto" id="clearAllCategoriesBtn">
<i class="bi bi-trash3"></i> Очистить все категории
</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="bi bi-x-circle"></i> Отмена
</button>
@@ -469,6 +485,6 @@
{% block extra_js %}
{% load static %}
<script src="{% static 'products/js/batch-selection.js' %}?v=1.1"></script>
<script src="{% static 'products/js/bulk-category-modal.js' %}?v=1.3"></script>
<script src="{% static 'products/js/batch-selection.js' %}?v=1.2"></script>
<script src="{% static 'products/js/bulk-category-modal.js' %}?v=1.4"></script>
{% endblock %}