zmiany w produktach i sugestoach / panel

This commit is contained in:
Mateusz Gruszczyński
2025-07-10 17:23:18 +02:00
parent 59d505d955
commit 29bcc304b7
4 changed files with 123 additions and 59 deletions

View File

@@ -1,5 +1,5 @@
document.addEventListener("DOMContentLoaded", function() {
// Usuń stare eventy
// Odśwież eventy
document.querySelectorAll('.sync-btn').forEach(btn => {
btn.replaceWith(btn.cloneNode(true));
});
@@ -8,14 +8,12 @@ document.addEventListener("DOMContentLoaded", function() {
});
// Synchronizacja sugestii
const buttons = document.querySelectorAll('.sync-btn');
buttons.forEach(btn => {
document.querySelectorAll('.sync-btn').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/${itemId}`, {
@@ -36,7 +34,7 @@ document.addEventListener("DOMContentLoaded", function() {
button.disabled = false;
}
})
.catch(error => {
.catch(() => {
showToast('Błąd synchronizacji', 'danger');
button.disabled = false;
});
@@ -44,14 +42,12 @@ document.addEventListener("DOMContentLoaded", function() {
});
// Usuwanie sugestii
const deleteButtons = document.querySelectorAll('.delete-suggestion-btn');
deleteButtons.forEach(btn => {
document.querySelectorAll('.delete-suggestion-btn').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}`, {
@@ -65,41 +61,16 @@ document.addEventListener("DOMContentLoaded", function() {
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();
}
if (row) row.remove();
} else {
button.disabled = false;
}
})
.catch(error => {
.catch(() => {
showToast('Błąd usuwania sugestii', '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 1.75 sekundy
setTimeout(() => {
toast.remove();
}, 1750);
}