More nice adjustments to layout.
This commit is contained in:
parent
28f541fcb6
commit
5f7354c055
1 changed files with 15 additions and 15 deletions
|
@ -22,7 +22,7 @@
|
||||||
<input type="hidden" id="inventoryId" value="{{ item.id }}">
|
<input type="hidden" id="inventoryId" value="{{ item.id }}">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col-8">
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<label for="timestamp" class="form-label">Date Entered</label>
|
<label for="timestamp" class="form-label">Date Entered</label>
|
||||||
|
@ -163,11 +163,11 @@
|
||||||
{% block script %}
|
{% block script %}
|
||||||
const saveButton = document.getElementById("saveButton");
|
const saveButton = document.getElementById("saveButton");
|
||||||
const deleteButton = document.getElementById("deleteButton");
|
const deleteButton = document.getElementById("deleteButton");
|
||||||
|
|
||||||
if (saveButton) {
|
if (saveButton) {
|
||||||
saveButton.addEventListener("click", async (e) => {
|
saveButton.addEventListener("click", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
timestamp: document.querySelector("input[name='timestamp']").value,
|
timestamp: document.querySelector("input[name='timestamp']").value,
|
||||||
condition: document.querySelector("select[name='condition']").value,
|
condition: document.querySelector("select[name='condition']").value,
|
||||||
|
@ -182,14 +182,14 @@
|
||||||
barcode: document.querySelector("input[name='barcode']").value || null,
|
barcode: document.querySelector("input[name='barcode']").value || null,
|
||||||
shared: document.querySelector("input[name='shared']").checked
|
shared: document.querySelector("input[name='shared']").checked
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const id = document.querySelector("#inventoryId").value;
|
const id = document.querySelector("#inventoryId").value;
|
||||||
const isEdit = id && id !== "None";
|
const isEdit = id && id !== "None";
|
||||||
|
|
||||||
const endpoint = isEdit ? `/api/inventory/${id}` : "/api/inventory";
|
const endpoint = isEdit ? `/api/inventory/${id}` : "/api/inventory";
|
||||||
const method = isEdit ? "PUT" : "POST";
|
const method = isEdit ? "PUT" : "POST";
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
const response = await fetch(endpoint, {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -197,14 +197,14 @@
|
||||||
},
|
},
|
||||||
body: JSON.stringify(payload)
|
body: JSON.stringify(payload)
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
localStorage.setItem("toastMessage", JSON.stringify({
|
localStorage.setItem("toastMessage", JSON.stringify({
|
||||||
message: isEdit ? "Inventory item updated!" : "Inventory item created!",
|
message: isEdit ? "Inventory item updated!" : "Inventory item created!",
|
||||||
type: "success"
|
type: "success"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
window.location.href = `/inventory_item/${result.id}`;
|
window.location.href = `/inventory_item/${result.id}`;
|
||||||
} else {
|
} else {
|
||||||
renderToast({ message: `Error: ${result.error}`, type: "danger" });
|
renderToast({ message: `Error: ${result.error}`, type: "danger" });
|
||||||
|
@ -215,33 +215,33 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deleteButton) {
|
if (deleteButton) {
|
||||||
deleteButton.addEventListener("click", async () => {
|
deleteButton.addEventListener("click", async () => {
|
||||||
const id = document.querySelector("#inventoryId").value;
|
const id = document.querySelector("#inventoryId").value;
|
||||||
|
|
||||||
if (!id || id === "None") {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confirm("Are you sure you want to delete this inventory item? This action cannot be undone.")) {
|
if (!confirm("Are you sure you want to delete this inventory item? This action cannot be undone.")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/inventory/${id}`, {
|
const response = await fetch(`/api/inventory/${id}`, {
|
||||||
method: "DELETE"
|
method: "DELETE"
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
localStorage.setItem("toastMessage", JSON.stringify({
|
localStorage.setItem("toastMessage", JSON.stringify({
|
||||||
message: "Inventory item deleted.",
|
message: "Inventory item deleted.",
|
||||||
type: "success"
|
type: "success"
|
||||||
}));
|
}));
|
||||||
|
|
||||||
window.location.href = "/inventory";
|
window.location.href = "/inventory";
|
||||||
} else {
|
} else {
|
||||||
renderToast({ message: `Error: ${result.error}`, type: "danger" });
|
renderToast({ message: `Error: ${result.error}`, type: "danger" });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue