{% extends "layout.html" %} {% block title %}{{ title }}{% endblock %} {% block content %} {{ breadcrumbs.breadcrumb_header( title=title, breadcrumbs=[ {'label': 'Users', 'url': url_for('main.list_users')} ], save_button = True ) }} {% if not user.active %}
This user is inactive. You will not be able to make any changes to this record.
{% endif %}
{% if inventory_rows %}
{{ tables.render_table(headers=inventory_headers, rows=inventory_rows, id='assets', entry_route='inventory_item', title='Assets', per_page=8) }}
{% endif %} {% if worklog_rows %}
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', entry_route='worklog_entry', title='Work Done', per_page=8) }}
{% endif %}
{% endblock %} {% block script %} const saveButton = document.getElementById("saveButton"); const deleteButton = document.getElementById("deleteButton"); if (saveButton) { saveButton.addEventListener("click", async (e) => { e.preventDefault(); const payload = { staff: document.querySelector("input[name='staffCheck']").checked, active: document.querySelector("input[name='activeCheck']").checked, last_name: document.querySelector("input[name='lastName']").value, first_name: document.querySelector("input[name='firstName']").value, supervisor_id: parseInt(document.querySelector("select[name='supervisor']").value) || null, location_id: parseInt(document.querySelector("select[name='location']").value) || null }; try { const id = document.querySelector("#userId").value; const isEdit = id && id !== "None"; const endpoint = isEdit ? `/api/user/${id}` : "/api/user"; const method = isEdit ? "PUT" : "POST"; const response = await fetch(endpoint, { method, headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); const result = await response.json(); if (result.success) { localStorage.setItem("toastMessage", JSON.stringify({ message: isEdit ? "User updated!" : "User created!", type: "success" })); window.location.href = `/user/${result.id}`; } else { renderToast({ message: `Error: ${result.error}`, type: "danger" }); } } catch (err) { console.error(err); } }); } {% endblock %}