Исправление: кнопки работают — обработчики пересоздаются в updateSelectionPanel

This commit is contained in:
tore 2026-09-14 20:42:59 +00:00
parent 18cdfb1593
commit 159360aeb0

View File

@ -457,6 +457,56 @@ function updateSelectionPanel() {
panel.style.display = 'block';
document.getElementById('selected-count').textContent = count;
// Пересоздаём обработчики кнопок каждый раз
const btnConfirm = document.getElementById('btn-confirm');
const btnReject = document.getElementById('btn-reject');
// Клонируем кнопки, чтобы сбросить старые обработчики
const newConfirm = btnConfirm.cloneNode(true);
const newReject = btnReject.cloneNode(true);
btnConfirm.parentNode.replaceChild(newConfirm, btnConfirm);
btnReject.parentNode.replaceChild(newReject, btnReject);
// Вешаем новые обработчики
newConfirm.addEventListener('click', function() {
if (appState.selectedItems.size === 0) return;
const comment = document.getElementById('group-comment').value || 'Подтверждено пользователем';
const processedGroups = new Set();
appState.selectedItems.forEach(key => {
const [groupId, itemIndex] = key.split('-');
const group = appState.groups.find(g => g.id === groupId);
if (group && group.status === 'new') {
group.status = 'confirmed';
group.comment = comment;
processedGroups.add(groupId);
}
});
appState.selectedItems.clear();
saveState();
renderGroups();
document.getElementById('group-comment').value = '';
});
newReject.addEventListener('click', function() {
if (appState.selectedItems.size === 0) return;
const comment = document.getElementById('group-comment').value || 'Отклонено пользователем';
const processedGroups = new Set();
appState.selectedItems.forEach(key => {
const [groupId, itemIndex] = key.split('-');
const group = appState.groups.find(g => g.id === groupId);
if (group && group.status === 'new') {
group.status = 'rejected';
group.comment = comment;
processedGroups.add(groupId);
}
});
appState.selectedItems.clear();
saveState();
renderGroups();
document.getElementById('group-comment').value = '';
});
}
// Обработка группы
@ -522,43 +572,8 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
document.getElementById('btn-confirm').addEventListener('click', function() {
if (appState.selectedItems.size === 0) return;
const comment = document.getElementById('group-comment').value || 'Подтверждено пользователем';
const processedGroups = new Set();
appState.selectedItems.forEach(key => {
const [groupId, itemIndex] = key.split('-');
const group = appState.groups.find(g => g.id === groupId);
if (group && group.status === 'new') {
group.status = 'confirmed';
group.comment = comment;
processedGroups.add(groupId);
}
});
appState.selectedItems.clear();
saveState();
renderGroups();
document.getElementById('group-comment').value = '';
});
document.getElementById('btn-reject').addEventListener('click', function() {
if (appState.selectedItems.size === 0) return;
const comment = document.getElementById('group-comment').value || 'Отклонено пользователем';
const processedGroups = new Set();
appState.selectedItems.forEach(key => {
const [groupId, itemIndex] = key.split('-');
const group = appState.groups.find(g => g.id === groupId);
if (group && group.status === 'new') {
group.status = 'rejected';
group.comment = comment;
processedGroups.add(groupId);
}
});
appState.selectedItems.clear();
saveState();
renderGroups();
document.getElementById('group-comment').value = '';
});
// Первичная инициализация обработчиков кнопок
updateSelectionPanel();
});
</script>