fixed tested components
This commit is contained in:
parent
9fe9243e60
commit
78154e43a9
52
public/userarea/add_part_quick.php
Normal file
52
public/userarea/add_part_quick.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
require_once(__DIR__ . '/include/headscript.php'); // così hai Auth + $iduserlogin + DBHandlerSelect
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||||
|
throw new Exception('Invalid request method');
|
||||||
|
}
|
||||||
|
|
||||||
|
$iddatadb = isset($_POST['iddatadb']) ? (int)$_POST['iddatadb'] : 0;
|
||||||
|
$part_description = isset($_POST['part_description']) ? trim($_POST['part_description']) : '';
|
||||||
|
|
||||||
|
if ($iddatadb <= 0) {
|
||||||
|
throw new Exception('Missing iddatadb');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($part_description === '') {
|
||||||
|
throw new Exception('Part description is empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
// (opzionale ma consigliato) limita lunghezza come da DB varchar(255)
|
||||||
|
if (mb_strlen($part_description) > 255) {
|
||||||
|
$part_description = mb_substr($part_description, 0, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = DBHandlerSelect::getInstance();
|
||||||
|
$pdo = $db->getConnection();
|
||||||
|
|
||||||
|
// Insert minimal
|
||||||
|
$stmt = $pdo->prepare("
|
||||||
|
INSERT INTO identification_parts (iddatadb, part_number, part_description)
|
||||||
|
VALUES (?, 1, ?)
|
||||||
|
");
|
||||||
|
$ok = $stmt->execute([$iddatadb, $part_description]);
|
||||||
|
|
||||||
|
if (!$ok) {
|
||||||
|
throw new Exception('Insert failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Part added',
|
||||||
|
'id' => $pdo->lastInsertId()
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
@ -1608,7 +1608,9 @@ function fixedDefaultValue(array $f): string
|
|||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
const changeEvent = new Event('change', { bubbles: true });
|
const changeEvent = new Event('change', {
|
||||||
|
bubbles: true
|
||||||
|
});
|
||||||
input.dispatchEvent(changeEvent);
|
input.dispatchEvent(changeEvent);
|
||||||
} else if (element.tagName === 'INPUT' && element.type === 'text') {
|
} else if (element.tagName === 'INPUT' && element.type === 'text') {
|
||||||
const cell = element.closest('.grid-cell');
|
const cell = element.closest('.grid-cell');
|
||||||
@ -1952,6 +1954,80 @@ function fixedDefaultValue(array $f): string
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Quick add part from "Tested Component" (+ button)
|
||||||
|
$(document).on('click', '.add-part-btn', async function() {
|
||||||
|
const rowIndex = $(this).data('row');
|
||||||
|
const $row = $(this).closest('.grid-row');
|
||||||
|
const iddatadb = $row.data('id');
|
||||||
|
|
||||||
|
// Input inside the same cell
|
||||||
|
const $cell = $(this).closest('.grid-cell');
|
||||||
|
const $input = $cell.find('input[name^="rows["][name$="[tested_component]"]');
|
||||||
|
|
||||||
|
const partDescription = ($input.val() || '').trim();
|
||||||
|
|
||||||
|
if (!iddatadb) {
|
||||||
|
alert('❌ iddatadb not found on row');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!partDescription) {
|
||||||
|
alert('⚠️ Inserisci prima una descrizione nel campo Tested Component.');
|
||||||
|
$input.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('iddatadb', iddatadb);
|
||||||
|
formData.append('part_description', partDescription);
|
||||||
|
|
||||||
|
const resp = await fetch('add_part_quick.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await resp.json();
|
||||||
|
|
||||||
|
if (!resp.ok || !data.success) {
|
||||||
|
throw new Error(data.message || ('HTTP ' + resp.status));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ✅ Do NOT clear tested_component: keep it as a warning/notice
|
||||||
|
$input.addClass('cell-changed');
|
||||||
|
setTimeout(() => $input.removeClass('cell-changed'), 1200);
|
||||||
|
|
||||||
|
// opzionale: se vuoi comunque “registrare” il cambiamento nel tracker unsaved
|
||||||
|
$input.trigger('change');
|
||||||
|
|
||||||
|
|
||||||
|
showQuickPartModal('✅ Parte aggiunta con successo!');
|
||||||
|
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
alert('❌ Errore aggiunta parte: ' + err.message);
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function showQuickPartModal(message) {
|
||||||
|
const modalEl = document.getElementById('quickPartModal');
|
||||||
|
if (!modalEl) {
|
||||||
|
alert(message); // fallback se il modal non esiste
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('quickPartModalMessage').textContent = message;
|
||||||
|
|
||||||
|
let modal = bootstrap.Modal.getInstance(modalEl);
|
||||||
|
if (!modal) modal = new bootstrap.Modal(modalEl, {
|
||||||
|
backdrop: true,
|
||||||
|
keyboard: true
|
||||||
|
});
|
||||||
|
modal.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).on('click', '.parts-btn', function() {
|
$(document).on('click', '.parts-btn', function() {
|
||||||
const iddatadb = $(this).data('iddatadb') || null;
|
const iddatadb = $(this).data('iddatadb') || null;
|
||||||
const idquotations = $(this).data('idquotations') || null;
|
const idquotations = $(this).data('idquotations') || null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user