inventory/inventory/templates/inventory.html

300 lines
14 KiB
HTML

<!-- templates/inventory.html -->
{% extends "layout.html" %}
{% block title %}{{ title }}{% endblock %}
{% block precontent %}
{% set saveLogic %}
e.preventDefault();
const payload = {
timestamp: document.querySelector("input[name='timestamp']").value,
condition: document.querySelector("select[name='condition']").value,
type_id: parseInt(document.querySelector("select[name='type']").value),
name: document.querySelector("input[name='name']").value || null,
serial: document.querySelector("input[name='serial']").value || null,
model: document.querySelector("input[name='model']").value || null,
notes: document.querySelector("textarea[name='editornotes']").value || null,
owner_id: parseInt(document.querySelector("select#userList").value) || null,
brand_id: parseInt(document.querySelector("select[name='brand']").value) || null,
location_id: parseInt(document.querySelector("select#room").value) || null,
barcode: document.querySelector("input[name='barcode']").value || null,
shared: document.querySelector("input[name='shared']").checked
};
try {
const id = document.querySelector("#inventoryId").value;
const isEdit = id && id !== "None";
const endpoint = isEdit ? `/api/inventory/${id}` : "/api/inventory";
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 ? "Inventory item updated!" : "Inventory item created!",
type: "success"
}));
window.location.href = `/inventory_item/${result.id}`;
} else {
renderToast({ message: `Error: ${result.error}`, type: "danger" });
}
} catch (err) {
console.error(err);
renderToast({ message: `Error: ${err}`, type: "danger" });
}
{% endset %}
{% set deleteLogic %}
const id = document.querySelector("#inventoryId").value;
if (!id || id === "None") {
renderToast({ message: "No item ID found to delete.", type: "danger" });
return;
}
if (!confirm("Are you sure you want to delete this inventory item? This action cannot be undone.")) {
return;
}
try {
const response = await fetch(`/api/inventory/${id}`, {
method: "DELETE"
});
const result = await response.json();
if (result.success) {
localStorage.setItem("toastMessage", JSON.stringify({
message: "Inventory item deleted.",
type: "success"
}));
window.location.href = "/inventory";
} else {
renderToast({ message: `Error: ${result.error}`, type: "danger" });
}
} catch (err) {
console.error(err);
renderToast({ message: `Error: ${err}`, type: "danger" });
}
{% endset %}
{% set buttonBar %}
<div class="btn-group">
{% if item.id != None %}
{{ buttons.render_button(
id='new',
icon='plus-lg',
style='outline-primary rounded-start',
logic="window.location.href = '" + url_for('main.new_inventory_item') + "';"
)}}
{% endif %}
{{ buttons.render_button(
id='save',
icon='floppy',
logic=saveLogic,
style="outline-primary" + (' rounded-end' if not item.id else '')
) }}
{% if item.id != None %}
{{ buttons.render_button(
id='delete',
icon='trash',
logic=deleteLogic,
style="outline-danger rounded-end"
) }}
{% endif %}
</div>
{% endset %}
{{ toolbars.render_toolbar(
id='inventory',
left=breadcrumbs.breadcrumb_header(
breadcrumbs=[
{'label': "Inventory", 'url': url_for('main.list_inventory')}
],
title=title
),
right=buttonBar
) }}
{% if item.condition in ["Removed", "Disposed"] %}
<div class="alert alert-danger rounded-0">
This item is not available and cannot be edited.
</div>
{% endif %}
{% endblock %}
{% block content %}
<input type="hidden" id="inventoryId" value="{{ item.id }}">
<div class="container">
<div class="row">
<div class="col-8">
<div class="row align-items-center">
<div class="col">
<label for="timestamp" class="form-label">Date Entered</label>
<input type="date" class="form-control-plaintext" name="timestamp"
value="{{ item.timestamp.date().isoformat() }}" readonly>
</div>
<div class="col">
<label for="identifier" class="form-label">Identifier</label>
<input type="text" class="form-control-plaintext" value="{{ item.identifier }}" readonly>
</div>
</div>
<div class="row">
<div class="col-4">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" name="name" placeholder="-" value="{{ item.name or '' }}" {%
if item.condition in ["Removed", "Disposed" ] %} disabled{% endif %}>
</div>
<div class="col-4">
<label for="serial" class="form-label">Serial Number</label>
<input type="text" class="form-control" name="serial" placeholder="-"
value="{{ item.serial if item.serial else '' }}" {% if item.condition in ["Removed", "Disposed"
] %} disabled{% endif %}>
</div>
<div class="col-4">
<label for="barcode" class="form-label">Bar Code</label>
<input type="text" class="form-control" name="barcode" placeholder="-"
value="{{ item.barcode if item.barcode else '' }}" {% if item.condition in
["Removed", "Disposed" ] %} disabled{% endif %}>
</div>
</div>
<div class="row">
<div class="col-4">
<label for="brand" class="form-label">Brand</label>
<select class="form-select" id="brand" name="brand" {% if item.condition in ["Removed", "Disposed" ]
%} disabled{% endif %}>
<option>-</option>
{% for brand in brands %}
<option value="{{ brand.id }}" {% if brand.id==item.brand_id %} selected{% endif %}>{{
brand.name }}
</option>
{% endfor %}
</select>
</div>
<div class="col-4">
<label for="model" class="form-label">Model</label>
<input type="text" class="form-control" name="model" placeholder="-"
value="{{ item.model if item.model else '' }}" {% if item.condition in ["Removed", "Disposed" ]
%} disabled{% endif %}>
</div>
<div class="col-4">
<label for="type" class="form-label">Category</label>
<select name="type" id="type" class="form-select" {% if item.condition in ["Removed", "Disposed" ]
%} disabled{% endif %}>
<option>-</option>
{% for t in types %}
<option value="{{ t.id }}" {% if t.id==item.type_id %} selected{% endif %}>{{ t.description }}
</option>
{% endfor %}
</select>
</div>
</div>
<div class="row">
<div class="col-4">
<label for="owner" class="form-label">
Contact
{% if item.owner %}
{{ links.entry_link('user', item.owner_id) }}
{% endif %}
</label>
<select class="form-select" id="userList" {% if item.condition in ["Removed", "Disposed" ] %}
disabled{% endif %}>
<option>-</option>
{% for user in users %}
<option value="{{ user.id }}" {% if user.id==item.owner_id %} selected{% endif %}>{{
user.full_name
}}</option>
{% endfor %}
</select>
</div>
<div class="col-4">
<label for="location" class="form-label">Location</label>
<select class="form-select" id="room" {% if item.condition in ["Removed", "Disposed" ] %} disabled{%
endif %}>
<option>-</option>
{% for room in rooms %}
<option value="{{ room.id }}" {% if room.id==item.location_id %} selected{% endif %}>{{
room.full_name }}</option>
{% endfor %}
</select>
</div>
<div class="col-2">
<label for="condition" class="form-label">Condition</label>
<select name="condition" id="condition" class="form-select">
<option>-</option>
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified",
"Removed", "Disposed"] %}
<option value="{{ condition }}" {% if item.condition==condition %} selected{% endif %}>{{
condition }}
</option>
{% endfor %}
</select>
</div>
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
<div class="form-check mb-0">
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared
%}checked{% endif %}{% if item.condition in ["Removed", "Disposed" ] %} disabled{% endif %}>
<label for="shared" class="form-check-label">Shared?</label>
</div>
</div>
</div>
</div>
{% if item.image or item.condition not in ["Removed", "Disposed"] %}
<div class="col">
{{ images.render_image(item.id, item.image, enabled = item.condition not in ["Removed", "Disposed"]) }}
</div>
{% endif %}
</div>
<div class="row">
<div class="col p-3">
{{ editor.render_editor(
id = "notes",
title = "Notes & Comments",
mode = 'view' if item.id else 'edit',
content = item.notes if item.notes else '',
enabled = item.condition not in ["Removed", "Disposed"]
) }}
</div>
{% if worklog %}
<div class="col" id="worklog">
<div class="row">
<div class="col form-label">
Work Log Entries
{% set id_list = worklog_rows | map(attribute='id') | list %}
{{ links.export_link(
id = (item.identifier | replace('Name: ', '')
| replace('ID:', '')
| replace('Serial: ', '')
| replace('Barcode: ', '')
| lower) + '_worklog',
endpoint = 'worklog',
ids = {'ids': id_list}
) }}
</div>
</div>
<div class="row border">
<div class="col overflow-auto" style="max-height: 300px;">
{% for note in notes %}
{% set title %}
{{ note.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{{ links.entry_link('worklog_entry', note.work_log_id) }}
{% endset %}
{{ editor.render_editor(
id = 'updates' + (note.id | string),
title = title,
content = note.content,
mode = 'view',
enabled = false
) }}
{% endfor %}
</div>
{% endif %}
</div>
</div>
{% endblock %}