inventory/inventory/templates/user.html
2025-07-29 10:18:34 -05:00

175 lines
7 KiB
HTML

<!-- templates/user.html -->
{% extends "layout.html" %}
{% block title %}{{ title }}{% endblock %}
{% block precontent %}
{% set saveLogic %}
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,
title: document.querySelector("input[name='title']").value,
supervisor_id: parseInt(document.querySelector("input[name='supervisor']").value) || null,
location_id: parseInt(document.querySelector("input[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 {
Toast.renderToast({ message: `Error: ${result.error}`, type: "danger" });
}
} catch (err) {
console.error(err);
}
{% endset %}
{% set iconBar %}
{% if user.id != None %}
{{ buttons.render_button(
id = 'org_chart',
icon = 'diagram-3',
logic = "window.location.href = '" + url_for('main.user_org', id=user.id) + "';",
style = 'outline-secondary'
) }}
{% endif %}
<div class="btn-group">
{% if user.id != None %}
{{ buttons.render_button(
id = 'new',
icon = 'plus-lg',
style = 'outline-secondary rounded-start',
logic = "window.location.href = '" + url_for('main.new_user') + "';"
)}}
{% endif %}
{{ buttons.render_button(
id = 'save',
icon = 'floppy',
logic = saveLogic,
style = 'outline-primary rounded-end'
) }}
</div>
{% endset %}
{{ toolbars.render_toolbar(
id = 'newUser',
left = breadcrumb_macro.render_breadcrumb(breadcrumbs=breadcrumbs),
right = iconBar
) }}
{% if not user.active %}
<div class="alert alert-danger rounded-0">This user is inactive. You will not be able to make any changes to this record.</div>
{% endif %}
{% endblock %}
{% block content %}
<input type="hidden" id="userId" value="{{ user.id }}">
<div class="container">
<form action="POST">
<div class="row">
<div class="col">
<label for="lastName" class="form-label">Last Name</label>
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Doe" value="{{ user.last_name if user.last_name else '' }}"{% if not user.active %} disabled readonly{% endif %}>
</div>
<div class="col">
<label for="firstName" class="form-label">First Name</label>
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="John" value="{{ user.first_name if user.first_name else '' }}"{% if not user.active %} disabled readonly{% endif %}>
</div>
<div class="col">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" placeholder="President" value="{{ user.title if user.title else '' }}"{% if not user.active %} disabled readonly{% endif %}>
</div>
</div>
<div class="row mt-2">
<div class="col-6">
{{ dropdowns.render_dropdown(
id='supervisor',
list=users,
label='Supervisor',
current_item=user.supervisor if user.supervisor else None,
entry_link='user',
enabled=user.active
) }}
</div>
<div class="col-6">
{{ dropdowns.render_dropdown(
id='location',
list=rooms,
label='Location',
current_item=user.location if user.location else None,
enabled=user.active
) }}
</div>
</div>
<div class="row mt-4">
<div class="col-6">
<input type="checkbox" class="form-check-input" id="activeCheck" name="activeCheck"{% if user.active %} checked{% endif %}>
<label for="activeCheck" class="form-check-label">Active</label>
</div>
<div class="col-6">
<input type="checkbox" class="form-check-input" id="staffCheck" name="staffCheck"{% if user.staff %} checked{% endif %}{% if not user.active %} disabled readonly{% endif %}>
<label for="staffCheck" class="form-check-label">Staff</label>
</div>
</div>
</form>
<div class="row mt-3">
{% if inventory_rows %}
<div class="col">
{% set id_list = inventory_rows | map(attribute='id') | list %}
{% set inventory_title %}
Assets
{{ links.export_link(
(user.identifier | lower | replace(' ', '_')) + '_user_inventory',
'inventory',
{'ids': id_list}
) }}
{% endset %}
<div class="row">
{{ tables.render_table(headers=inventory_headers, rows=inventory_rows, id='assets', entry_route='inventory_item', title=inventory_title, per_page=8) }}
</div>
</div>
{% endif %}
{% if worklog_rows %}
{% set id_list = worklog_rows | map(attribute='id') | list %}
{% set worklog_title %}
Work Done
{{ links.export_link(
(user.identifier | lower | replace(' ', '_')) + '_user_worklog',
'worklog',
{'ids': id_list}
) }}
{% endset %}
<div class="col">
<div class="row">
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', entry_route='worklog_entry', title=worklog_title, per_page=8) }}
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}