poprawki w synchronizacji produktow

This commit is contained in:
Mateusz Gruszczyński
2025-07-07 16:29:06 +02:00
parent cd2ad6df0b
commit a4ad7ba58c
4 changed files with 83 additions and 11 deletions

View File

@@ -120,7 +120,7 @@ function setupList(listId, username) {
li.innerHTML = `
<div class="d-flex align-items-center flex-wrap gap-2">
<input type="checkbox">
<input class="large-checkbox" type="checkbox">
<span id="name-${data.id}" class="text-white">${data.name} ${quantityBadge}</span>
</div>
<div class="mt-2 mt-md-0">

View File

@@ -0,0 +1,65 @@
document.addEventListener("DOMContentLoaded", function() {
// Usuń stare eventy
document.querySelectorAll('.sync-btn').forEach(btn => {
btn.replaceWith(btn.cloneNode(true));
});
// Pobierz już "czyste" przyciski
const buttons = document.querySelectorAll('.sync-btn');
buttons.forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
const itemId = this.getAttribute('data-item-id');
const button = this;
button.disabled = true;
fetch(`/admin/sync_suggestion_ajax/${itemId}`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
showToast(data.message, data.success ? 'success' : 'danger');
if (data.success) {
button.innerText = '✅ Zsynchronizowano';
button.classList.remove('btn-outline-primary');
button.classList.add('btn-success');
} else {
button.disabled = false;
}
})
.catch(error => {
showToast('Błąd synchronizacji', 'danger');
button.disabled = false;
});
});
});
});
// Funkcja do wyświetlania toast
function showToast(message, type = 'success') {
const toastContainer = document.getElementById('toast-container');
const toast = document.createElement('div');
toast.className = `toast align-items-center text-white bg-${type} border-0 show`;
toast.role = 'alert';
toast.style.minWidth = '250px';
toast.innerHTML = `
<div class="d-flex">
<div class="toast-body">${message}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
`;
toastContainer.appendChild(toast);
// Automatyczne usunięcie po 3 sekundach
setTimeout(() => {
toast.remove();
}, 1750);
}