Files
Wallos/scripts/dashboard.js
2026-03-18 15:27:08 +00:00

52 lines
1.6 KiB
JavaScript

document.addEventListener("DOMContentLoaded", function () {
function updateAiRecommendationNumbers() {
document.querySelectorAll(".ai-recommendation-item").forEach(function (item, index) {
const numberSpan = item.querySelector(".ai-recommendation-header h3 > span");
if (numberSpan) {
numberSpan.textContent = `${index + 1}. `;
}
});
}
document.querySelectorAll(".ai-recommendation-item").forEach(function (item) {
item.addEventListener("click", function () {
item.classList.toggle("expanded");
});
});
document.querySelectorAll(".delete-ai-recommendation").forEach(function (el) {
el.addEventListener("click", function (e) {
e.preventDefault();
e.stopPropagation();
const item = el.closest(".ai-recommendation-item");
const id = item.getAttribute("data-id");
fetch("endpoints/ai/delete_recommendation.php", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": window.csrfToken,
},
body: JSON.stringify({ id: id }),
})
.then(res => res.json())
.then(data => {
if (data.success) {
item.remove();
updateAiRecommendationNumbers();
showSuccessMessage(translate("success"));
} else {
showErrorMessage(data.message || translate("failed_delete_ai_recommendation"));
}
})
.catch(error => {
console.error(error);
showErrorMessage(translate("unknown_error"));
});
});
});
});