mix part and loader
This commit is contained in:
+87
-14
@@ -28,8 +28,8 @@ $(document).ready(function () {
|
||||
loadExistingParts(iddatadb);
|
||||
|
||||
if (partsModal) {
|
||||
const modal = new bootstrap.Modal(partsModal); // Create a new instance
|
||||
modal.show(); // Show the modal
|
||||
const modal = new bootstrap.Modal(partsModal);
|
||||
modal.show();
|
||||
} else {
|
||||
console.error("Modal Parts non trovato");
|
||||
}
|
||||
@@ -40,8 +40,8 @@ $(document).ready(function () {
|
||||
if (closeBtn) {
|
||||
closeBtn.addEventListener("click", function () {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none"; // Nascondi overlay
|
||||
document.body.style.pointerEvents = "auto"; // Riattiva la pagina
|
||||
overlay.style.display = "none";
|
||||
document.body.style.pointerEvents = "auto";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ $(document).ready(function () {
|
||||
window.addEventListener("click", function (event) {
|
||||
if (event.target === partsModal) {
|
||||
partsModal.style.display = "none";
|
||||
overlay.style.display = "none"; // Nascondi overlay
|
||||
document.body.style.pointerEvents = "auto"; // Riattiva la pagina
|
||||
overlay.style.display = "none";
|
||||
document.body.style.pointerEvents = "auto";
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -98,13 +98,15 @@ $(document).ready(function () {
|
||||
});
|
||||
}
|
||||
|
||||
function addNewRow(nextPartNumber) {
|
||||
function addNewRow(nextPartNumber, isMix = false) {
|
||||
const description = isMix ? "Mix" : "";
|
||||
const newRow = `
|
||||
<tr data-part-id="new">
|
||||
<td><input type="number" class="form-control form-control-sm part-number" value="${nextPartNumber || 1}" style="width: 80px;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||
<td><input type="text" class="form-control form-control-sm part-description" value="${description}" placeholder="Inserisci descrizione" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-primary btn-sm add-mix-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;">M</button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem; display: none;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
@@ -141,6 +143,20 @@ $(document).ready(function () {
|
||||
updatePartsList();
|
||||
});
|
||||
|
||||
$(document).on("click", ".add-mix-row", function (e) {
|
||||
e.preventDefault();
|
||||
console.log("Pulsante Aggiungi Mix cliccato");
|
||||
const maxPartNumber = Math.max(
|
||||
...$("#partsTableBody tr")
|
||||
.map(function () {
|
||||
return parseInt($(this).find(".part-number").val()) || 0;
|
||||
})
|
||||
.get(),
|
||||
);
|
||||
addNewRow(maxPartNumber + 1, true);
|
||||
updatePartsList();
|
||||
});
|
||||
|
||||
$(document).on("click", ".remove-row", function (e) {
|
||||
e.preventDefault();
|
||||
console.log("Pulsante Rimuovi riga cliccato");
|
||||
@@ -202,8 +218,13 @@ $(document).ready(function () {
|
||||
const $saveStatus = $row.find(".save-status");
|
||||
const $saveLoading = $row.find(".save-loading");
|
||||
const iddatadb = $("#partsModal").data("iddatadb");
|
||||
const isMix = partDescription.startsWith("Mix") ? "Y" : "N";
|
||||
|
||||
console.log("Evento blur su input:", { partNumber, partDescription });
|
||||
console.log("Evento blur su input:", {
|
||||
partNumber,
|
||||
partDescription,
|
||||
isMix,
|
||||
});
|
||||
|
||||
if (partDescription && iddatadb) {
|
||||
$saveLoading.show();
|
||||
@@ -218,6 +239,7 @@ $(document).ready(function () {
|
||||
{
|
||||
part_number: partNumber,
|
||||
part_description: partDescription,
|
||||
mix: isMix,
|
||||
},
|
||||
],
|
||||
}),
|
||||
@@ -264,6 +286,7 @@ $(document).ready(function () {
|
||||
<td><input type="text" class="form-control form-control-sm part-description" value="${part.part_description}" style="width: 100%;"></td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-success btn-sm add-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
<button type="button" class="btn btn-primary btn-sm add-mix-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;">M</button>
|
||||
<button type="button" class="btn btn-danger btn-sm remove-row" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-trash fa-xs"></i></button>
|
||||
<span class="save-status text-success" style="display: none; margin-left: 5px;"><i class="fas fa-check fa-xs"></i></span>
|
||||
<span class="save-loading text-warning" style="display: none; margin-left: 5px;"><i class="fas fa-spinner fa-spin fa-xs"></i></span>
|
||||
@@ -297,19 +320,61 @@ $(document).ready(function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
const listItem = `<li class="list-group-item" data-part-number="${partNumber}">${partNumber} - ${partDescription}</li>`;
|
||||
if (
|
||||
partNumber &&
|
||||
partDescription &&
|
||||
!partDescription.startsWith("Mix")
|
||||
) {
|
||||
const listItem = `
|
||||
<li class="list-group-item" data-part-number="${partNumber}">
|
||||
${partNumber} - ${partDescription}
|
||||
<button type="button" class="btn btn-success btn-sm add-to-mix-btn" style="padding: 0.1rem 0.3rem; font-size: 0.8rem;"><i class="fas fa-plus fa-xs"></i></button>
|
||||
</li>`;
|
||||
$("#partsList").append(listItem);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on("click", ".add-to-mix-btn", function () {
|
||||
const $listItem = $(this).closest("li");
|
||||
const partDescription = $listItem.text().split(" - ")[1].trim(); // Prende tutta la descrizione dopo il trattino
|
||||
const $mixRow = $("#partsTableBody tr")
|
||||
.filter(function () {
|
||||
return $(this)
|
||||
.find(".part-description")
|
||||
.val()
|
||||
.startsWith("Mix");
|
||||
})
|
||||
.last();
|
||||
|
||||
if ($mixRow.length === 0) {
|
||||
alert("Crea prima una riga Mix usando il pulsante 'M'.");
|
||||
return;
|
||||
}
|
||||
|
||||
const $descriptionInput = $mixRow.find(".part-description");
|
||||
let currentDescription = $descriptionInput.val().trim();
|
||||
|
||||
if (currentDescription === "Mix") {
|
||||
currentDescription = `Mix ${partDescription}`;
|
||||
} else if (!currentDescription.includes(partDescription)) {
|
||||
currentDescription += ` + ${partDescription}`;
|
||||
} else {
|
||||
return; // Parte già presente, non aggiungerla
|
||||
}
|
||||
|
||||
$descriptionInput.val(currentDescription);
|
||||
$descriptionInput.trigger("blur"); // Attiva il salvataggio
|
||||
updatePartsList();
|
||||
});
|
||||
|
||||
let selectedPartNumber = null;
|
||||
let markers = [];
|
||||
let descriptionPosition = { x: 10, y: 10 };
|
||||
let hasDescriptions = false;
|
||||
|
||||
$("#partsList").on("click", "li", function () {
|
||||
$("#partsList").on("click", "li", function (e) {
|
||||
if ($(e.target).hasClass("add-to-mix-btn")) return;
|
||||
selectedPartNumber = $(this).data("part-number");
|
||||
console.log("Part number selezionato:", selectedPartNumber);
|
||||
$(this).addClass("active").siblings().removeClass("active");
|
||||
@@ -451,7 +516,11 @@ $(document).ready(function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
if (
|
||||
partNumber &&
|
||||
partDescription &&
|
||||
!partDescription.startsWith("Mix")
|
||||
) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
@@ -525,7 +594,11 @@ $(document).ready(function () {
|
||||
$("#partsTableBody tr").each(function () {
|
||||
const partNumber = $(this).find(".part-number").val();
|
||||
const partDescription = $(this).find(".part-description").val();
|
||||
if (partNumber && partDescription) {
|
||||
if (
|
||||
partNumber &&
|
||||
partDescription &&
|
||||
!partDescription.startsWith("Mix")
|
||||
) {
|
||||
partsList.push(`${partNumber} ${partDescription}`);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user