function createPrinter() { const {nameInput, priceInput, buildVolumeInput, maxSpeedInput} = getCreateModalValues(); clearCreateModalValues(); fetch('/printer', {method: 'POST', body: JSON.stringify({ name: nameInput, price: Number(priceInput), build_volume: buildVolumeInput, max_speed: Number(maxSpeedInput), })}).then(response => { if (response.ok) { const tableBody = document.getElementById('table-body'); response.json().then(printer => { addPrinterToTable(tableBody, printer); }); } }); } function editPrinter(printerId) { const {nameInput, priceInput, buildVolumeInput, maxSpeedInput} = getEditModalValues(); fetch(`/printer/${printerId}`, {method: 'PUT', body: JSON.stringify({ name: nameInput, price: Number(priceInput), build_volume: buildVolumeInput, max_speed: Number(maxSpeedInput), })}).then(response => { if (response.ok) { response.json().then(printer => { document.getElementById(`printer${printer.id}:name`).textContent = printer.name; document.getElementById(`printer${printer.id}:price`).textContent = printer.price; document.getElementById(`printer${printer.id}:build_volume`).textContent = printer.build_volume; document.getElementById(`printer${printer.id}:max_speed`).textContent = printer.max_speed; const editButton = document.getElementById(`printer${printer.id}:editButton`); setEditButtonOnClick(editButton, printer); const viewButton = document.getElementById(`printer${printer.id}:viewButton`); setViewButtonOnClick(viewButton, printer); }); } }); } function deletePrinter(printerId) { fetch(`/printer/${printerId}`, {method: 'DELETE'}).then(response => { if (response.ok) { removePrinterFromTable(printerId); } }); }