fixed import fogli di lavoro and disegni tecnici
This commit is contained in:
@@ -130,6 +130,116 @@
|
||||
});
|
||||
};
|
||||
|
||||
let wsDisegniList = [];
|
||||
|
||||
function wsFileExt(name) {
|
||||
const p = String(name || "").split(".");
|
||||
return p.length > 1 ? p.pop().toLowerCase() : "";
|
||||
}
|
||||
|
||||
function wsIsImage(ext) {
|
||||
return ["jpg", "jpeg", "png", "gif", "bmp", "webp"].includes(ext);
|
||||
}
|
||||
|
||||
function showWorksheetDisegno(index) {
|
||||
const f = wsDisegniList[index];
|
||||
if (!f) return;
|
||||
|
||||
$(".ws-disegno-item").removeClass("active");
|
||||
$(`.ws-disegno-item[data-index="${index}"]`).addClass("active");
|
||||
|
||||
const name = f.file_name || "";
|
||||
const path = f.file_url || f.file_path || "";
|
||||
const ext = wsFileExt(name);
|
||||
|
||||
let viewer;
|
||||
if (ext === "pdf") {
|
||||
viewer = `<iframe src="${escapeHtml(path)}#zoom=page-width"></iframe>`;
|
||||
} else if (wsIsImage(ext)) {
|
||||
viewer = `<div class="img-wrap"><img src="${escapeHtml(path)}" alt="${escapeHtml(name)}"></div>`;
|
||||
} else {
|
||||
viewer = `<div class="h-100 d-flex justify-content-center align-items-center text-muted">Anteprima non disponibile per questo formato: usa "Apri in nuova scheda"</div>`;
|
||||
}
|
||||
|
||||
$("#wsDisegnoToolbar").html(`
|
||||
<div>
|
||||
<div class="fw-bold">${escapeHtml(name)}</div>
|
||||
${f.description ? `<div class="small text-muted">${escapeHtml(f.description)}</div>` : ""}
|
||||
</div>
|
||||
<a href="${escapeHtml(path)}" target="_blank" class="worksheet-open-link">
|
||||
<i class="fa-solid fa-arrow-up-right-from-square"></i> Apri in nuova scheda
|
||||
</a>
|
||||
`);
|
||||
$("#wsDisegnoViewer").html(viewer);
|
||||
}
|
||||
|
||||
function loadWorksheetDisegni(idmatrice) {
|
||||
wsDisegniList = [];
|
||||
const $c = $("#wsDisegniContainer");
|
||||
|
||||
if (!idmatrice) {
|
||||
$("#wsDisegniCount").text("0");
|
||||
$c.html(
|
||||
'<div class="text-muted">Nessun profilo collegato a questo foglio.</div>',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
fetch("get_matrice_attachments.php?id=" + encodeURIComponent(idmatrice))
|
||||
.then((r) => r.json())
|
||||
.then((data) => {
|
||||
if (!data.success)
|
||||
throw new Error(
|
||||
data.message || "Errore caricamento allegati",
|
||||
);
|
||||
|
||||
wsDisegniList = (data.attachments || []).filter(
|
||||
(a) => parseInt(a.is_disegno, 10) === 1,
|
||||
);
|
||||
$("#wsDisegniCount").text(wsDisegniList.length);
|
||||
|
||||
if (!wsDisegniList.length) {
|
||||
$c.html(
|
||||
'<div class="text-muted p-3">Nessun disegno tecnico per questo profilo. ' +
|
||||
"Si possono segnare dalla gestione matrici (graffetta → pulsante compasso).</div>",
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
let listHtml = "";
|
||||
if (wsDisegniList.length > 1) {
|
||||
listHtml =
|
||||
'<div class="ws-disegni-list">' +
|
||||
wsDisegniList
|
||||
.map(
|
||||
(f, i) =>
|
||||
`<button type="button" class="ws-disegno-item" data-index="${i}">📐 ${escapeHtml(f.file_name || "Disegno " + (i + 1))}</button>`,
|
||||
)
|
||||
.join("") +
|
||||
"</div>";
|
||||
}
|
||||
|
||||
$c.html(`
|
||||
${listHtml}
|
||||
<div class="ws-disegno-toolbar" id="wsDisegnoToolbar"></div>
|
||||
<div class="ws-disegno-viewer" id="wsDisegnoViewer"></div>
|
||||
`);
|
||||
|
||||
// Se l'utente ha già aperto il tab mentre caricava, mostro subito il primo
|
||||
if ($('.ws-tab[data-tab="disegni"]').hasClass("active")) {
|
||||
showWorksheetDisegno(0);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
$("#wsDisegniCount").text("!");
|
||||
$c.html(
|
||||
'<div class="text-danger">Errore nel caricamento dei disegni: ' +
|
||||
escapeHtml(err.message || "") +
|
||||
"</div>",
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
window.loadWorksheetDetail = function (worksheetId, endpoint) {
|
||||
endpoint = endpoint || "ajax/worksheet-linked-data.php";
|
||||
|
||||
@@ -215,8 +325,8 @@
|
||||
`;
|
||||
}
|
||||
|
||||
const html = `
|
||||
<div class="worksheet-title-box mb-4">
|
||||
const headerHtml = `
|
||||
<div class="worksheet-title-box mb-3">
|
||||
<div class="d-flex justify-content-between align-items-start gap-3 flex-wrap">
|
||||
<div>
|
||||
<h4 class="mb-1">${escapeHtml(ws.worksheet_number_label || "—")} / Rev. ${escapeHtml(ws.revision_label || "0")}</h4>
|
||||
@@ -237,6 +347,9 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
`;
|
||||
|
||||
const html = `
|
||||
<div class="row g-3">
|
||||
<div class="col-lg-6">
|
||||
<div class="readonly-card">
|
||||
@@ -324,7 +437,31 @@
|
||||
</div>
|
||||
`;
|
||||
|
||||
$("#worksheetDetailContainer").html(html);
|
||||
const fullHtml = `
|
||||
${headerHtml}
|
||||
|
||||
<div class="ws-tabs">
|
||||
<button type="button" class="ws-tab active" data-tab="dati">
|
||||
<i class="fa-solid fa-file-lines me-1"></i> Dati foglio
|
||||
</button>
|
||||
<button type="button" class="ws-tab" data-tab="disegni">
|
||||
📐 Disegni tecnici <span class="ws-tab-count" id="wsDisegniCount">…</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="ws-tab-pane active" data-pane="dati">
|
||||
${html}
|
||||
</div>
|
||||
|
||||
<div class="ws-tab-pane" data-pane="disegni">
|
||||
<div id="wsDisegniContainer">
|
||||
<div class="text-muted">Caricamento disegni tecnici...</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
$("#worksheetDetailContainer").html(fullHtml);
|
||||
loadWorksheetDisegni(ws.idmatrice);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Catch loadMatriceWorksheets:", err);
|
||||
@@ -349,6 +486,29 @@
|
||||
).show();
|
||||
});
|
||||
|
||||
$(document).on("click", ".ws-tab", function () {
|
||||
const tab = $(this).data("tab");
|
||||
|
||||
$(".ws-tab").removeClass("active");
|
||||
$(this).addClass("active");
|
||||
|
||||
$(".ws-tab-pane").removeClass("active");
|
||||
$(`.ws-tab-pane[data-pane="${tab}"]`).addClass("active");
|
||||
|
||||
// Carico il PDF solo la prima volta che si apre il tab
|
||||
if (
|
||||
tab === "disegni" &&
|
||||
wsDisegniList.length &&
|
||||
$("#wsDisegnoViewer").is(":empty")
|
||||
) {
|
||||
showWorksheetDisegno(0);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("click", ".ws-disegno-item", function () {
|
||||
showWorksheetDisegno(parseInt($(this).data("index"), 10));
|
||||
});
|
||||
|
||||
$(document).on("click", ".open-worksheet-detail", function () {
|
||||
const worksheetId = $(this).data("id");
|
||||
const endpoint =
|
||||
|
||||
Reference in New Issue
Block a user