diff --git a/inventory/templates/settings.html b/inventory/templates/settings.html index e159e51..25460aa 100644 --- a/inventory/templates/settings.html +++ b/inventory/templates/settings.html @@ -25,32 +25,32 @@ }; }); } - + function sanitizeFk(val) { if (val && val !== "null" && val !== "" && val !== "None") { return /^\d+$/.test(val) ? parseInt(val, 10) : val; } return null; } - + const roomOptions = Array.from(document.getElementById('room-list').options); - + const rooms = roomOptions.map(opt => { const id = opt.value?.trim(); const name = opt.textContent.trim(); const sectionId = sanitizeFk(opt.dataset.sectionId); const functionId = sanitizeFk(opt.dataset.functionId); - + const result = { name, ...(id ? { id } : {}), section_id: sectionId, function_id: functionId }; - + return result; }); - + return { brands: extractOptions("brand"), types: extractOptions("type"), @@ -76,9 +76,9 @@ headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(state) }); - + const contentType = response.headers.get("content-type"); - + if (!response.ok) { if (contentType && contentType.includes("application/json")) { const data = await response.json(); @@ -88,11 +88,11 @@ throw new Error("Unexpected response:\n" + text.slice(0, 200)); } } - + const data = await response.json(); console.log("Sync result:", data); renderToast({ message: 'Settings updated successfully.', type: 'success' }); - + } catch (err) { console.error("Submission error:", err); renderToast({ message: `Failed to update settings, ${err}`, type: 'danger' }); @@ -112,13 +112,19 @@ {% endblock %} {% block content %} -