Enhance button functionality in inventory, user, and worklog templates to include dynamic 'new' buttons and improve save button styling for better UI consistency
This commit is contained in:
parent
dab23009c1
commit
a4bfb9838c
3 changed files with 44 additions and 15 deletions
|
@ -25,10 +25,10 @@
|
||||||
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: {
|
||||||
|
@ -36,14 +36,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" });
|
||||||
|
@ -69,15 +69,15 @@
|
||||||
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" });
|
||||||
|
@ -89,11 +89,19 @@
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{% set buttonBar %}
|
{% set buttonBar %}
|
||||||
<div class="btn-group">
|
<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(
|
{{ buttons.render_button(
|
||||||
id='save',
|
id='save',
|
||||||
icon='floppy',
|
icon='floppy',
|
||||||
logic=saveLogic,
|
logic=saveLogic,
|
||||||
style="outline-primary rounded-start"
|
style="outline-primary" + (' rounded-end' if not item.id else '')
|
||||||
) }}
|
) }}
|
||||||
{% if item.id != None %}
|
{% if item.id != None %}
|
||||||
{{ buttons.render_button(
|
{{ buttons.render_button(
|
||||||
|
|
|
@ -46,6 +46,24 @@
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
{% endset %}
|
{% endset %}
|
||||||
|
{% set iconBar %}
|
||||||
|
<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(
|
{{ toolbars.render_toolbar(
|
||||||
id = 'newUser',
|
id = 'newUser',
|
||||||
left = breadcrumbs.breadcrumb_header(
|
left = breadcrumbs.breadcrumb_header(
|
||||||
|
@ -54,12 +72,7 @@
|
||||||
{'label': 'Users', 'url': url_for('main.list_users')}
|
{'label': 'Users', 'url': url_for('main.list_users')}
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
right = buttons.render_button(
|
right = iconBar
|
||||||
id = 'save',
|
|
||||||
icon = 'floppy',
|
|
||||||
logic = saveLogic,
|
|
||||||
style = 'outline-primary'
|
|
||||||
)
|
|
||||||
) }}
|
) }}
|
||||||
{% if not user.active %}
|
{% if not user.active %}
|
||||||
<div class="alert alert-danger">This user is inactive. You will not be able to make any changes to this record.</div>
|
<div class="alert alert-danger">This user is inactive. You will not be able to make any changes to this record.</div>
|
||||||
|
|
|
@ -95,11 +95,19 @@
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{% set iconBar %}
|
{% set iconBar %}
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
{% if log.id != None %}
|
||||||
|
{{ buttons.render_button(
|
||||||
|
id='new',
|
||||||
|
icon='plus-lg',
|
||||||
|
style='outline-primary rounded-start',
|
||||||
|
logic="window.location.href = '" + url_for('main.new_worklog') + "';"
|
||||||
|
) }}
|
||||||
|
{% endif %}
|
||||||
{{ buttons.render_button(
|
{{ buttons.render_button(
|
||||||
id='save',
|
id='save',
|
||||||
icon='floppy',
|
icon='floppy',
|
||||||
logic=saveLogic,
|
logic=saveLogic,
|
||||||
style='outline-primary rounded-start'
|
style='outline-primary'
|
||||||
) }}
|
) }}
|
||||||
{% if log.id != None %}
|
{% if log.id != None %}
|
||||||
{{ buttons.render_button(
|
{{ buttons.render_button(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue