fixed matrici with db cron

This commit is contained in:
2025-10-07 09:41:29 +02:00
parent 12c6cc5f95
commit 15b6f38e8b
3 changed files with 177 additions and 31 deletions
+62 -19
View File
@@ -143,7 +143,7 @@ $(document).ready(function () {
if (iddatadb) {
if (matrici.length === 0) {
$.ajax({
url: "get_matrice.php",
url: "get_matrici_db.php",
method: "GET",
dataType: "json",
success: function (data) {
@@ -157,6 +157,19 @@ $(document).ready(function () {
initializeGlobalSelect2();
loadPhoto(iddatadb, idquotations);
loadExistingParts(iddatadb, idquotations);
const errorMsg = $(
'<div class="alert alert-danger temp-alert" role="alert">Errore nel caricamento delle matrici: ' +
error +
" (" +
xhr.status +
")</div>",
);
$("#partsModal .modal-body").prepend(errorMsg);
setTimeout(function () {
errorMsg.fadeOut(500, function () {
$(this).remove();
});
}, 5000);
},
});
} else {
@@ -169,18 +182,39 @@ $(document).ready(function () {
loadExistingParts(iddatadb, idquotations);
}
const modal = new bootstrap.Modal(
document.getElementById("partsModal"),
);
modal.show();
const modalElement = document.getElementById("partsModal");
if (modalElement) {
// Verifica se il modale è già stato inizializzato
let modal = bootstrap.Modal.getInstance(modalElement);
if (!modal) {
modal = new bootstrap.Modal(modalElement, {
backdrop: true,
keyboard: true,
focus: true,
});
}
modal.show();
} else {
console.error("Elemento modale non trovato: #partsModal");
const errorMsg = $(
'<div class="alert alert-danger temp-alert" role="alert">Errore: Modale non trovato.</div>',
);
$("body").prepend(errorMsg);
setTimeout(function () {
errorMsg.fadeOut(500, function () {
$(this).remove();
});
}, 5000);
}
});
$("#partsModal .close-btn, #partsModal").on("click", function (event) {
if (event.target === this) {
const modal = bootstrap.Modal.getInstance(
document.getElementById("partsModal"),
);
modal.hide();
if (event.target === this || $(event.target).hasClass("close-btn")) {
const modalElement = document.getElementById("partsModal");
const modal = bootstrap.Modal.getInstance(modalElement);
if (modal) {
modal.hide();
}
}
});
@@ -194,7 +228,7 @@ $(document).ready(function () {
});
$("#partsModal").on("hidden.bs.modal", function () {
// Reset global state to initial values
// Resetta lo stato
photoData = {
naturalWidth: 0,
naturalHeight: 0,
@@ -208,20 +242,29 @@ $(document).ready(function () {
selectedPartNumber = null;
unsavedChanges = false;
if (fabricCanvas) {
fabricCanvas.off(); // Rimuove tutti gli eventi
fabricCanvas.off();
fabricCanvas.dispose();
fabricCanvas = null;
}
descriptionTextbox = null;
markerObjects = {};
matrici = [];
// Clear UI elements
$("#photoSelectorContainer").empty().hide();
$("#samplePhoto").attr("src", "");
$("#partsTableBody").empty();
$("#global-matrice").empty(); // Pulisci select globale se presente
// Remove any temporary messages
$("#global-matrice").empty();
$(".temp-alert").remove();
// Rimuovi manualmente il backdrop e ripristina il body
const modalElement = document.getElementById("partsModal");
const modal = bootstrap.Modal.getInstance(modalElement);
if (modal) {
modal.dispose(); // Distrugge l'istanza del modale
}
$(".modal-backdrop").remove();
$("body").removeClass("modal-open");
$("body").css("padding-right", "");
$(":focus").blur();
});
// ===================
@@ -792,7 +835,7 @@ $(document).ready(function () {
const options = matrici.map(function (matrice) {
return {
id: matrice.IdMatrice,
text: matrice.NomeMatriceTraduzione,
text: matrice.NomeMatrice, // Updated to use NomeMatrice
};
});
@@ -817,7 +860,7 @@ $(document).ready(function () {
const matrice = matrici.find((m) => m.IdMatrice == idmatrice);
if (matrice) {
const option = new Option(
matrice.NomeMatriceTraduzione,
matrice.NomeMatrice, // Updated to use NomeMatrice
matrice.IdMatrice,
true,
true,
@@ -843,7 +886,7 @@ $(document).ready(function () {
const idquotations = $("#partsModal").data("idquotations");
const endpoint = idquotations
? "save_matrice_quotation.php"
: "save_matrice.php"; // Assumendo esista per quotations, altrimenti adatta
: "save_matrice.php";
const data = idquotations
? { idquotations: idquotations }
: { iddatadb: iddatadb };
@@ -915,7 +958,7 @@ $(document).ready(function () {
const options = matrici.map(function (matrice) {
return {
id: matrice.IdMatrice,
text: matrice.NomeMatriceTraduzione,
text: matrice.NomeMatrice, // Updated to use NomeMatrice
};
});