fixed import fogli di lavoro and disegni tecnici

This commit is contained in:
2026-10-02 11:24:51 +02:00
parent 63674ea6be
commit c2212f7022
11 changed files with 802 additions and 87 deletions
+159 -11
View File
@@ -547,6 +547,36 @@ function revisionLabel($rev)
color: #fff;
opacity: .95;
}
.attachments-existing-list .attachment-existing-row.is-disegno {
border: 2px solid #6f42c1;
background: #f7f3ff;
}
.badge-disegno {
display: inline-flex;
align-items: center;
gap: 5px;
background: #6f42c1;
color: #fff;
font-size: .78rem;
font-weight: 700;
padding: 4px 9px;
border-radius: 999px;
margin-left: 6px;
vertical-align: middle;
}
.btn-toggle-disegno {
border-color: #6f42c1;
color: #6f42c1;
}
.btn-toggle-disegno:hover,
.btn-toggle-disegno.active {
background: #6f42c1;
color: #fff;
}
</style>
</head>
@@ -713,6 +743,7 @@ function revisionLabel($rev)
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
data-cliente='" . htmlspecialchars($row['cliente'], ENT_QUOTES) . "'
data-data='{$dataIT}'
data-photo='" . htmlspecialchars($hasPhoto ? $thumb : '', ENT_QUOTES) . "'
data-bs-toggle='tooltip' data-bs-title='Modifica'>
<i class='fa-solid fa-pen-to-square'></i>
</button>
@@ -797,6 +828,19 @@ function revisionLabel($rev)
<input type="text" class="form-control" id="dataMatrice" placeholder="dd/mm/yyyy">
</div>
<div class="mb-3">
<label class="fw-semibold">Foto</label>
<input type="file" class="form-control" id="fotoMatrice" accept=".jpg,.jpeg,.png,.gif,.webp,image/*">
<input type="hidden" id="removeFotoMatrice" value="0">
<div id="fotoMatricePreviewWrap" class="mt-2 text-center" style="display:none;">
<img id="fotoMatricePreview" src="" style="max-width:100%; max-height:200px; border-radius:10px; border:1px solid #dee2e6;">
<div class="mt-2">
<button type="button" class="btn btn-sm btn-outline-danger" id="btnRimuoviFoto">🗑️ Rimuovi foto</button>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" class="btn btn-add">💾 Salva</button>
</div>
@@ -1131,7 +1175,9 @@ function revisionLabel($rev)
return;
}
const list = data.attachments || [];
const list = (data.attachments || []).sort((a, b) =>
(parseInt(b.is_disegno, 10) || 0) - (parseInt(a.is_disegno, 10) || 0)
);
const container = $("#existingAttachmentsList");
container.empty();
@@ -1149,6 +1195,7 @@ function revisionLabel($rev)
const badge = getFileTypeBadge(ext);
const createdAt = item.created_at || '';
const id = item.id || 0;
const isDisegno = (parseInt(item.is_disegno, 10) || 0) === 1;
const previewHtml = isImageExt(ext) && filePath ?
`<img src="${escapeHtml(filePath)}" class="attachment-preview-thumb" alt="">` :
@@ -1174,19 +1221,29 @@ function revisionLabel($rev)
}
const html = `
<div class="attachment-existing-row">
<div class="attachment-existing-row ${isDisegno ? 'is-disegno' : ''}">
<div class="d-flex gap-3 align-items-start">
<div>${previewHtml}</div>
<div class="flex-grow-1">
<div class="d-flex justify-content-between align-items-start gap-2">
<div>
<div class="attachment-meta-title">${escapeHtml(fileName)}</div>
<div class="attachment-meta-title">
${escapeHtml(fileName)}
${isDisegno ? '<span class="badge-disegno"><i class="fa-solid fa-compass-drafting"></i> Disegno tecnico</span>' : ''}
</div>
<div class="attachment-meta-sub">${badge} ${createdAt ? ' • ' + escapeHtml(createdAt) : ''}</div>
</div>
<div class="d-flex gap-1">
${openButtonHtml}
<button type="button"
class="btn btn-sm btn-toggle-disegno toggle-disegno ${isDisegno ? 'active' : ''}"
data-id="${id}"
data-value="${isDisegno ? 1 : 0}"
title="${isDisegno ? 'Togli da disegni tecnici' : 'Segna come disegno tecnico'}">
<i class="fa-solid fa-compass-drafting"></i>
</button>
<button type="button" class="btn btn-sm btn-outline-danger delete-existing-file" data-id="${id}">Elimina</button>
</div>
</div>
@@ -1272,12 +1329,49 @@ function revisionLabel($rev)
.attr('placeholder', 'Nome matrice, cliente…')
.addClass('form-control');
function resetFotoMatrice(photoUrl) {
$("#fotoMatrice").val('');
$("#removeFotoMatrice").val('0');
if (photoUrl) {
$("#fotoMatricePreview").attr("src", photoUrl);
$("#fotoMatricePreviewWrap").show();
} else {
$("#fotoMatricePreview").attr("src", "");
$("#fotoMatricePreviewWrap").hide();
}
}
$(document).on("click", ".edit", function() {
$("#idMatriceEdit").val($(this).data("id"));
$("#nomeMatrice").val($(this).data("nome"));
$("#clienteMatrice").val($(this).data("cliente"));
$("#dataMatrice").val($(this).data("data"));
new bootstrap.Modal(document.getElementById('addMatriceModal')).show();
resetFotoMatrice($(this).data("photo") || "");
bootstrap.Modal.getOrCreateInstance(document.getElementById('addMatriceModal')).show();
});
// Anteprima quando si sceglie un file
$("#fotoMatrice").on("change", function() {
const file = this.files && this.files[0];
if (!file) return;
$("#removeFotoMatrice").val('0');
$("#fotoMatricePreview").attr("src", URL.createObjectURL(file));
$("#fotoMatricePreviewWrap").show();
});
// Rimuovi foto
$("#btnRimuoviFoto").on("click", function() {
$("#fotoMatrice").val('');
$("#removeFotoMatrice").val('1');
$("#fotoMatricePreview").attr("src", "");
$("#fotoMatricePreviewWrap").hide();
});
// Alla chiusura del modale svuota tutto (così "Aggiungi" parte pulito)
document.getElementById('addMatriceModal').addEventListener('hidden.bs.modal', function() {
$("#addMatriceForm")[0].reset();
$("#idMatriceEdit").val('');
resetFotoMatrice('');
});
$("#addMatriceForm").on("submit", function(e) {
@@ -1289,15 +1383,21 @@ function revisionLabel($rev)
let dataIT = $("#dataMatrice").val().trim();
let dataSQL = convertToMySQLDate(dataIT);
const formData = new FormData();
formData.append("id", id);
formData.append("nome", nome);
formData.append("cliente", cliente);
formData.append("data", dataSQL);
formData.append("remove_photo", $("#removeFotoMatrice").val());
const fotoFile = $("#fotoMatrice")[0].files[0];
if (fotoFile) {
formData.append("photo", fotoFile);
}
fetch("save_matrice.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "id=" + encodeURIComponent(id) +
"&nome=" + encodeURIComponent(nome) +
"&cliente=" + encodeURIComponent(cliente) +
"&data=" + encodeURIComponent(dataSQL)
body: formData
})
.then(r => r.json())
.then(data => {
@@ -1672,6 +1772,54 @@ function revisionLabel($rev)
});
});
$(document).on("click", ".toggle-disegno", function() {
const $btn = $(this);
const id = $btn.data("id");
const newValue = parseInt($btn.data("value"), 10) === 1 ? 0 : 1;
const idmatrice = $("#mf_idmatrice").val();
$btn.prop("disabled", true);
fetch("toggle_matrice_attachment_disegno.php", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
body: "id=" + encodeURIComponent(id) + "&is_disegno=" + newValue
})
.then(r => r.json())
.then(data => {
if (!data.success) {
Swal.fire({
icon: "error",
title: "Errore",
text: data.message || ""
});
$btn.prop("disabled", false);
return;
}
Swal.fire({
toast: true,
position: "top-end",
icon: "success",
title: data.message,
showConfirmButton: false,
timer: 1500
});
loadExistingAttachments(idmatrice);
})
.catch(() => {
Swal.fire({
icon: "error",
title: "Errore",
text: "Errore di comunicazione con il server"
});
$btn.prop("disabled", false);
});
});
$(document).on("click", ".preview-existing-file", function() {
const file = $(this).data("file") || "";
const name = $(this).data("name") || "Anteprima file";