poprawki w synchronizacji produktow

This commit is contained in:
Mateusz Gruszczyński
2025-07-07 16:36:22 +02:00
parent bb28952adf
commit c8472c9423
3 changed files with 55 additions and 13 deletions

View File

@@ -3,10 +3,12 @@ document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll('.sync-btn').forEach(btn => {
btn.replaceWith(btn.cloneNode(true));
});
document.querySelectorAll('.delete-suggestion-btn').forEach(btn => {
btn.replaceWith(btn.cloneNode(true));
});
// Pobierz już "czyste" przyciski
// Synchronizacja sugestii
const buttons = document.querySelectorAll('.sync-btn');
buttons.forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
@@ -16,7 +18,7 @@ document.addEventListener("DOMContentLoaded", function() {
button.disabled = true;
fetch(`/admin/sync_suggestion_ajax/${itemId}`, {
fetch(`/admin/sync_suggestion/${itemId}`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
@@ -40,6 +42,44 @@ document.addEventListener("DOMContentLoaded", function() {
});
});
});
// Usuwanie sugestii
const deleteButtons = document.querySelectorAll('.delete-suggestion-btn');
deleteButtons.forEach(btn => {
btn.addEventListener('click', function(e) {
e.preventDefault();
const suggestionId = this.getAttribute('data-suggestion-id');
const button = this;
button.disabled = true;
fetch(`/admin/delete_suggestion/${suggestionId}`, {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
showToast(data.message, data.success ? 'success' : 'danger');
if (data.success) {
// Możesz usunąć cały wiersz lub np. odświeżyć kolumnę
const row = button.closest('tr');
if (row) {
row.remove();
}
} else {
button.disabled = false;
}
})
.catch(error => {
showToast('Błąd usuwania sugestii', 'danger');
button.disabled = false;
});
});
});
});
@@ -58,8 +98,8 @@ function showToast(message, type = 'success') {
`;
toastContainer.appendChild(toast);
// Automatyczne usunięcie po 3 sekundach
// Automatyczne usunięcie po 1.75 sekundy
setTimeout(() => {
toast.remove();
}, 1750);
}
}