diff --git a/inventory/templates/inventory.html b/inventory/templates/inventory.html index 77ff356..bc3c166 100644 --- a/inventory/templates/inventory.html +++ b/inventory/templates/inventory.html @@ -4,152 +4,170 @@ {% block title %}{{ title }}{% endblock %} {% block content %} -{{ breadcrumbs.breadcrumb_header( - breadcrumbs=[ - {'label': "Inventory", 'url': url_for('main.list_inventory')} - ], - title=title, - save_button=True, - delete_button= item.id != None -) }} + {{ breadcrumbs.breadcrumb_header( + breadcrumbs=[ + {'label': "Inventory", 'url': url_for('main.list_inventory')} + ], + title=title, + save_button=True, + delete_button= item.id != None + ) }} -{% if item.condition in ["Removed", "Disposed"] %} -
- This item is not available and cannot be edited. -
-{% endif %} + {% if item.condition in ["Removed", "Disposed"] %} +
+ This item is not available and cannot be edited. +
+ {% endif %} - -
-
-
- - -
-
- - -
-
- {{ images.render_image(item.id, item.image, enabled = item.condition not in ["Removed", "Disposed"]) }} -
-
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- - -
-
-
- - + +
+
+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
+
+ {% if item.image or item.condition not in ["Removed", "Disposed"] %} +
+ {{ images.render_image(item.id, item.image, enabled = item.condition not in ["Removed", "Disposed"]) }} +
+ {% endif %} +
+
+
+ {{ 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"] + ) }} +
+ {% if worklog %} +
+ {{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', + entry_route='worklog_entry', title='Work Log') }} +
+ {% endif %}
-
-
- {{ 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"] - ) }} -
- {% if worklog %} -
- {{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog', - entry_route='worklog_entry', title='Work Log') }} -
- {% 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 = { timestamp: document.querySelector("input[name='timestamp']").value, condition: document.querySelector("select[name='condition']").value, @@ -164,14 +182,14 @@ 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: { @@ -179,14 +197,14 @@ }, 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" }); @@ -197,33 +215,33 @@ } }); } - + if (deleteButton) { deleteButton.addEventListener("click", async () => { const id = document.querySelector("#inventoryId").value; - + if (!id || id === "None") { - renderToast({ message: "No item ID found to delete.", type: "danger"} ); + 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" });