fixed saving and modifying parts
This commit is contained in:
parent
a87423d879
commit
1bda30e957
@ -179,7 +179,7 @@ $(document).ready(function () {
|
|||||||
function addNewRow(nextPartNumber, isMix = false) {
|
function addNewRow(nextPartNumber, isMix = false) {
|
||||||
const description = isMix ? "Mix" : "";
|
const description = isMix ? "Mix" : "";
|
||||||
const newRow = `
|
const newRow = `
|
||||||
<tr data-part-id="new">
|
<tr data-part-id="">
|
||||||
<td><input type="number" class="form-control form-control-sm part-number" value="${nextPartNumber || 1}" style="width: 80px;"></td>
|
<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" value="${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>
|
<td>
|
||||||
@ -290,13 +290,14 @@ $(document).ready(function () {
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
// თუ ახალია, backend-მა მოგვცა ახალი ID
|
|
||||||
if (response.part_id) {
|
|
||||||
$row.data("part-id", response.part_id);
|
|
||||||
}
|
|
||||||
$saveLoading.hide();
|
$saveLoading.hide();
|
||||||
$saveStatus.show();
|
$saveStatus.show();
|
||||||
updatePartsList();
|
updatePartsList();
|
||||||
|
// თუ ახალია, backend-მა მოგვცა ახალი ID
|
||||||
|
if (response.part_id) {
|
||||||
|
$row.attr("data-part-id", response.part_id);
|
||||||
|
$row.data("part-id", response.part_id);
|
||||||
|
}
|
||||||
setTimeout(() => $saveStatus.hide(), 2000);
|
setTimeout(() => $saveStatus.hide(), 2000);
|
||||||
} else {
|
} else {
|
||||||
alert("Errore nel salvataggio: " + response.message);
|
alert("Errore nel salvataggio: " + response.message);
|
||||||
|
|||||||
@ -37,7 +37,7 @@ if ($partDescription) {
|
|||||||
':part_description' => $partDescription,
|
':part_description' => $partDescription,
|
||||||
':mix' => $mix
|
':mix' => $mix
|
||||||
]);
|
]);
|
||||||
echo json_encode(['success' => true, 'message' => 'Parte aggiornata con successo']);
|
echo json_encode(['success' => true, 'part_id' => $partId, 'part_number'=>$partNumber, 'message' => 'Parte aggiornata con successo']);
|
||||||
} else {
|
} else {
|
||||||
// INSERT თუ ახალია
|
// INSERT თუ ახალია
|
||||||
$stmt = $pdo->prepare("INSERT INTO identification_parts
|
$stmt = $pdo->prepare("INSERT INTO identification_parts
|
||||||
@ -50,7 +50,7 @@ if ($partDescription) {
|
|||||||
':mix' => $mix
|
':mix' => $mix
|
||||||
]);
|
]);
|
||||||
$newId = $pdo->lastInsertId();
|
$newId = $pdo->lastInsertId();
|
||||||
echo json_encode(['success' => true, 'message' => 'Parte salvata con successo', 'part_id' => $newId]);
|
echo json_encode(['success' => true, 'part_id' => $newId, 'part_number'=>$partNumber, 'message' => 'Parte salvata con successo']);
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
echo json_encode(['success' => false, 'message' => 'Errore nel salvataggio: ' . $e->getMessage()]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user