analysis
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
let analysisMatriciMap = {};
|
||||
|
||||
function loadAnalysisMatrixNames() {
|
||||
return $.ajax({
|
||||
url: "get_matrici_db.php",
|
||||
method: "GET",
|
||||
dataType: "json",
|
||||
})
|
||||
.done(function (data) {
|
||||
analysisMatriciMap = {};
|
||||
|
||||
(data.value || []).forEach(function (matrice) {
|
||||
analysisMatriciMap[String(matrice.IdMatrice)] =
|
||||
matrice.NomeMatrice || "#" + matrice.IdMatrice;
|
||||
});
|
||||
|
||||
applyAnalysisMatrixNames();
|
||||
})
|
||||
.fail(function () {
|
||||
analysisMatriciMap = {};
|
||||
applyAnalysisMatrixNames();
|
||||
});
|
||||
}
|
||||
|
||||
function applyAnalysisMatrixNames() {
|
||||
const modal = document.getElementById("analysisModal");
|
||||
if (!modal) return;
|
||||
|
||||
modal.querySelectorAll(".analysis-matrix-item").forEach((item) => {
|
||||
const matrixId = item.getAttribute("data-matrix-id");
|
||||
const nameEl = item.querySelector(".analysis-matrix-name");
|
||||
|
||||
let matrixName = "No Matrix";
|
||||
if (matrixId && matrixId !== "NO_MATRIX") {
|
||||
matrixName =
|
||||
analysisMatriciMap[String(matrixId)] || "#" + matrixId;
|
||||
}
|
||||
|
||||
item.setAttribute("data-matrix-name", matrixName);
|
||||
|
||||
if (nameEl) {
|
||||
nameEl.textContent = matrixName;
|
||||
}
|
||||
});
|
||||
|
||||
modal.querySelectorAll(".analysis-part-matrix-name").forEach((el) => {
|
||||
const matrixId = el.getAttribute("data-matrix-id");
|
||||
|
||||
if (!matrixId || matrixId === "NO_MATRIX") {
|
||||
el.textContent = "No Matrix";
|
||||
return;
|
||||
}
|
||||
|
||||
el.textContent =
|
||||
analysisMatriciMap[String(matrixId)] || "#" + matrixId;
|
||||
});
|
||||
}
|
||||
|
||||
function updateSelectedPartsInfo() {
|
||||
const modal = document.getElementById("analysisModal");
|
||||
if (!modal) return;
|
||||
|
||||
const checked = modal.querySelectorAll(
|
||||
".analysis-part-checkbox:checked",
|
||||
);
|
||||
const ids = Array.from(checked).map((el) => el.value);
|
||||
|
||||
const countEl = modal.querySelector("#analysisSelectedPartsCount");
|
||||
const idsEl = modal.querySelector("#analysisSelectedPartsIds");
|
||||
|
||||
if (countEl) {
|
||||
countEl.textContent = `${ids.length} selected`;
|
||||
}
|
||||
|
||||
if (idsEl) {
|
||||
idsEl.textContent = ids.length ? ids.join(", ") : "-";
|
||||
}
|
||||
|
||||
modal.querySelectorAll(".analysis-part-item").forEach((item) => {
|
||||
const checkbox = item.querySelector(".analysis-part-checkbox");
|
||||
if (checkbox && checkbox.checked) {
|
||||
item.classList.add("part-checked");
|
||||
} else {
|
||||
item.classList.remove("part-checked");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function selectPartsByMatrix(matrixId, matrixLabel) {
|
||||
const modal = document.getElementById("analysisModal");
|
||||
if (!modal) return;
|
||||
|
||||
const partItems = modal.querySelectorAll(".analysis-part-item");
|
||||
const matrixLabelEl = modal.querySelector("#analysisCurrentMatrix");
|
||||
|
||||
partItems.forEach((item) => {
|
||||
const itemMatrixId = item.getAttribute("data-matrix-id");
|
||||
const checkbox = item.querySelector(".analysis-part-checkbox");
|
||||
|
||||
item.classList.remove("matrix-active");
|
||||
|
||||
if (itemMatrixId === String(matrixId)) {
|
||||
item.classList.add("matrix-active");
|
||||
if (checkbox) checkbox.checked = true;
|
||||
} else {
|
||||
if (checkbox) checkbox.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
if (matrixLabelEl) {
|
||||
matrixLabelEl.textContent = matrixLabel || "-";
|
||||
}
|
||||
|
||||
updateSelectedPartsInfo();
|
||||
}
|
||||
|
||||
function clearAnalysisSelection() {
|
||||
const modal = document.getElementById("analysisModal");
|
||||
if (!modal) return;
|
||||
|
||||
modal.querySelectorAll(".analysis-matrix-item").forEach((item) => {
|
||||
item.classList.remove("active");
|
||||
});
|
||||
|
||||
modal.querySelectorAll(".analysis-part-item").forEach((item) => {
|
||||
item.classList.remove("matrix-active", "part-checked");
|
||||
});
|
||||
|
||||
modal.querySelectorAll(".analysis-part-checkbox").forEach((cb) => {
|
||||
cb.checked = false;
|
||||
});
|
||||
|
||||
const matrixLabelEl = modal.querySelector("#analysisCurrentMatrix");
|
||||
if (matrixLabelEl) matrixLabelEl.textContent = "-";
|
||||
|
||||
updateSelectedPartsInfo();
|
||||
}
|
||||
|
||||
function initAnalysisModal() {
|
||||
const modal = document.getElementById("analysisModal");
|
||||
if (!modal) return;
|
||||
|
||||
modal.querySelectorAll(".analysis-matrix-item").forEach((btn) => {
|
||||
btn.addEventListener("click", function () {
|
||||
modal
|
||||
.querySelectorAll(".analysis-matrix-item")
|
||||
.forEach((x) => x.classList.remove("active"));
|
||||
this.classList.add("active");
|
||||
|
||||
const matrixId = this.getAttribute("data-matrix-id");
|
||||
const matrixLabel =
|
||||
this.getAttribute("data-matrix-name") ||
|
||||
this.textContent.trim();
|
||||
|
||||
selectPartsByMatrix(matrixId, matrixLabel);
|
||||
});
|
||||
});
|
||||
|
||||
modal.querySelectorAll(".analysis-part-checkbox").forEach((cb) => {
|
||||
cb.addEventListener("change", function () {
|
||||
updateSelectedPartsInfo();
|
||||
});
|
||||
});
|
||||
|
||||
const clearBtn = modal.querySelector("#analysisClearSelectionBtn");
|
||||
if (clearBtn) {
|
||||
clearBtn.addEventListener("click", function () {
|
||||
clearAnalysisSelection();
|
||||
});
|
||||
}
|
||||
|
||||
const firstActiveMatrix = modal.querySelector(
|
||||
".analysis-matrix-item.active",
|
||||
);
|
||||
if (firstActiveMatrix) {
|
||||
const matrixId = firstActiveMatrix.getAttribute("data-matrix-id");
|
||||
const matrixLabel =
|
||||
firstActiveMatrix.getAttribute("data-matrix-name") ||
|
||||
firstActiveMatrix.textContent.trim();
|
||||
|
||||
selectPartsByMatrix(matrixId, matrixLabel);
|
||||
} else {
|
||||
updateSelectedPartsInfo();
|
||||
}
|
||||
}
|
||||
|
||||
// OPEN ANALYSIS MODAL FROM PARTS MODAL BUTTON
|
||||
$(document).on("click", ".open-analysis-modal-btn", function () {
|
||||
const partsModal = document.getElementById("partsModal");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
|
||||
if (!iddatadb) {
|
||||
console.error("iddatadb not found on #partsModal");
|
||||
alert("iddatadb not found");
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: "modal_analysis.php",
|
||||
method: "GET",
|
||||
data: { iddatadb: iddatadb },
|
||||
success: function (response) {
|
||||
$("#analysisModalContainer").html(response);
|
||||
|
||||
const modalElement = document.getElementById("analysisModal");
|
||||
if (!modalElement) {
|
||||
console.error("Analysis modal not found: #analysisModal");
|
||||
return;
|
||||
}
|
||||
|
||||
let modal = bootstrap.Modal.getInstance(modalElement);
|
||||
if (!modal) {
|
||||
modal = new bootstrap.Modal(modalElement, {
|
||||
backdrop: true,
|
||||
keyboard: true,
|
||||
focus: true,
|
||||
});
|
||||
}
|
||||
|
||||
loadAnalysisMatrixNames().always(function () {
|
||||
initAnalysisModal();
|
||||
modal.show();
|
||||
});
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
console.error("Error loading analysis modal:", error);
|
||||
alert("Error loading analysis modal: " + error);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// CLEANUP ON CLOSE
|
||||
$(document).on("hidden.bs.modal", "#analysisModal", function () {
|
||||
const modalElement = document.getElementById("analysisModal");
|
||||
if (modalElement) {
|
||||
const modal = bootstrap.Modal.getInstance(modalElement);
|
||||
if (modal) modal.dispose();
|
||||
}
|
||||
|
||||
$("#analysisModalContainer").empty();
|
||||
|
||||
// keep parts modal alive, but remove extra backdrop leftovers
|
||||
$(".modal-backdrop").last().remove();
|
||||
|
||||
if ($("#partsModal").hasClass("show")) {
|
||||
$("body").addClass("modal-open");
|
||||
} else {
|
||||
$("body").removeClass("modal-open").css("padding-right", "");
|
||||
}
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user