cloneparts
This commit is contained in:
@@ -1595,7 +1595,11 @@ $(document).ready(function () {
|
||||
dataType: "json",
|
||||
delay: 150,
|
||||
data: function (params) {
|
||||
return { q: params.term || "", limit: 20, macro: selectedMacro || "" };
|
||||
return {
|
||||
q: params.term || "",
|
||||
limit: 20,
|
||||
macro: selectedMacro || "",
|
||||
};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return { results: data.results || [] };
|
||||
@@ -1654,7 +1658,11 @@ $(document).ready(function () {
|
||||
dataType: "json",
|
||||
delay: 150,
|
||||
data: function (params) {
|
||||
return { q: params.term || "", limit: 20, macro: selectedMacro || "" };
|
||||
return {
|
||||
q: params.term || "",
|
||||
limit: 20,
|
||||
macro: selectedMacro || "",
|
||||
};
|
||||
},
|
||||
processResults: function (data) {
|
||||
return { results: data.results || [] };
|
||||
@@ -1800,7 +1808,9 @@ $(document).ready(function () {
|
||||
$("#partsTableBody .part-matrice").each(function () {
|
||||
const $target = $(this);
|
||||
if (!$target.find(`option[value="${globalVal}"]`).length) {
|
||||
$target.append(new Option(globalText, globalVal, true, true));
|
||||
$target.append(
|
||||
new Option(globalText, globalVal, true, true),
|
||||
);
|
||||
}
|
||||
$target.val(globalVal).trigger("change");
|
||||
});
|
||||
@@ -1969,7 +1979,109 @@ $(document).ready(function () {
|
||||
".add-row-global, .add-mix-global, .add-mix-row, .remove-row, .propagate-matrice-btn, .propagate-all-btn, .note-btn",
|
||||
markUnsaved,
|
||||
);
|
||||
$(document).on("click", "#clonePartsBtn", function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const sourceIddatadb =
|
||||
parseInt($("#partsModal").data("iddatadb"), 10) || null;
|
||||
const visibleListRaw =
|
||||
$("#partsModal").data("visible-iddatadb-list") || [];
|
||||
|
||||
if (!sourceIddatadb) {
|
||||
const errorMsg = $(
|
||||
'<div class="alert alert-danger temp-alert" role="alert">Source record not found.</div>',
|
||||
);
|
||||
$("#partsModal .modal-body").prepend(errorMsg);
|
||||
setTimeout(() => {
|
||||
errorMsg.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
const targetIds = (Array.isArray(visibleListRaw) ? visibleListRaw : [])
|
||||
.map((v) => parseInt(v, 10))
|
||||
.filter((v) => !isNaN(v) && v > 0 && v !== sourceIddatadb);
|
||||
|
||||
if (!targetIds.length) {
|
||||
const errorMsg = $(
|
||||
'<div class="alert alert-warning temp-alert" role="alert">No other visible records available for clone.</div>',
|
||||
);
|
||||
$("#partsModal .modal-body").prepend(errorMsg);
|
||||
setTimeout(() => {
|
||||
errorMsg.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!confirm(
|
||||
`Confermi il clone delle parti del record ${sourceIddatadb} negli altri ${targetIds.length} record visibili?`,
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $btn = $(this);
|
||||
const originalHtml = $btn.html();
|
||||
$btn.prop("disabled", true).html(
|
||||
'<i class="fas fa-spinner fa-spin"></i> Clonazione...',
|
||||
);
|
||||
|
||||
$.ajax({
|
||||
url: "clone_parts_to_visible.php",
|
||||
method: "POST",
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
data: JSON.stringify({
|
||||
source_iddatadb: sourceIddatadb,
|
||||
target_iddatadb_list: targetIds,
|
||||
}),
|
||||
success: function (response) {
|
||||
$btn.prop("disabled", false).html(originalHtml);
|
||||
|
||||
if (response.success) {
|
||||
const successMsg = $(
|
||||
`<div class="alert alert-success temp-alert" role="alert">
|
||||
Clone completed. Source parts copied to ${response.cloned_targets || 0} record(s), total cloned parts: ${response.total_cloned_parts || 0}.
|
||||
</div>`,
|
||||
);
|
||||
$("#partsModal .modal-body").prepend(successMsg);
|
||||
setTimeout(() => {
|
||||
successMsg.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
} else {
|
||||
const errorMsg = $(
|
||||
`<div class="alert alert-danger temp-alert" role="alert">Clone error: ${response.message || "Unknown error"}</div>`,
|
||||
);
|
||||
$("#partsModal .modal-body").prepend(errorMsg);
|
||||
setTimeout(() => {
|
||||
errorMsg.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
}
|
||||
},
|
||||
error: function (xhr, status, error) {
|
||||
$btn.prop("disabled", false).html(originalHtml);
|
||||
|
||||
const errorMsg = $(
|
||||
`<div class="alert alert-danger temp-alert" role="alert">Clone error: ${error} (${xhr.status})</div>`,
|
||||
);
|
||||
$("#partsModal .modal-body").prepend(errorMsg);
|
||||
setTimeout(() => {
|
||||
errorMsg.fadeOut(500, function () {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 5000);
|
||||
},
|
||||
});
|
||||
});
|
||||
// Esporta la funzione loadParts per essere usata da import_Edit2.php
|
||||
window.loadParts = loadParts;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user