added flag to photos
This commit is contained in:
@@ -349,6 +349,69 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
});
|
||||
});
|
||||
|
||||
document
|
||||
.querySelectorAll(".photo-flag-checkbox")
|
||||
.forEach((checkbox) => {
|
||||
checkbox.addEventListener("change", async function () {
|
||||
const photoId = this.getAttribute("data-photo-id");
|
||||
const field = this.getAttribute("data-field");
|
||||
const value = this.checked ? 1 : 0;
|
||||
const currentCheckbox = this;
|
||||
|
||||
// Only one PrimaPagina visually in the current popup
|
||||
if (field === "PrimaPagina" && value === 1) {
|
||||
document
|
||||
.querySelectorAll(
|
||||
".photo-flag-checkbox[data-field='PrimaPagina']",
|
||||
)
|
||||
.forEach((cb) => {
|
||||
if (cb !== currentCheckbox) {
|
||||
cb.checked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = new URLSearchParams();
|
||||
formData.append("photo_id", photoId);
|
||||
formData.append("field", field);
|
||||
formData.append("value", value);
|
||||
|
||||
const response = await fetch("update_photo_flags.php", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type":
|
||||
"application/x-www-form-urlencoded",
|
||||
},
|
||||
body: formData.toString(),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error(
|
||||
result.message || "Errore salvataggio flag",
|
||||
);
|
||||
}
|
||||
|
||||
// Safety refresh for PrimaPagina to ensure UI matches DB
|
||||
if (field === "PrimaPagina") {
|
||||
loadPopupContent(iddatadb, idquotations);
|
||||
}
|
||||
} catch (error) {
|
||||
alert(
|
||||
"Errore durante il salvataggio del flag: " +
|
||||
error.message,
|
||||
);
|
||||
|
||||
// rollback current checkbox
|
||||
currentCheckbox.checked = !currentCheckbox.checked;
|
||||
|
||||
// reload popup to restore coherent state
|
||||
loadPopupContent(iddatadb, idquotations);
|
||||
}
|
||||
});
|
||||
});
|
||||
document.querySelectorAll(".thumbnail").forEach((img) => {
|
||||
img.addEventListener("click", function () {
|
||||
const enlargedImage = document.getElementById("enlargedImage");
|
||||
|
||||
Reference in New Issue
Block a user