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 {
|
||||
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: {
|
||||
|
@ -36,14 +36,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" });
|
||||
|
@ -69,15 +69,15 @@
|
|||
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" });
|
||||
|
@ -89,11 +89,19 @@
|
|||
{% 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-start"
|
||||
style="outline-primary" + (' rounded-end' if not item.id else '')
|
||||
) }}
|
||||
{% if item.id != None %}
|
||||
{{ buttons.render_button(
|
||||
|
|
|
@ -46,6 +46,24 @@
|
|||
console.error(err);
|
||||
}
|
||||
{% 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(
|
||||
id = 'newUser',
|
||||
left = breadcrumbs.breadcrumb_header(
|
||||
|
@ -54,12 +72,7 @@
|
|||
{'label': 'Users', 'url': url_for('main.list_users')}
|
||||
]
|
||||
),
|
||||
right = buttons.render_button(
|
||||
id = 'save',
|
||||
icon = 'floppy',
|
||||
logic = saveLogic,
|
||||
style = 'outline-primary'
|
||||
)
|
||||
right = iconBar
|
||||
) }}
|
||||
{% 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>
|
||||
|
|
|
@ -95,11 +95,19 @@
|
|||
{% endset %}
|
||||
{% set iconBar %}
|
||||
<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(
|
||||
id='save',
|
||||
icon='floppy',
|
||||
logic=saveLogic,
|
||||
style='outline-primary rounded-start'
|
||||
style='outline-primary'
|
||||
) }}
|
||||
{% if log.id != None %}
|
||||
{{ buttons.render_button(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue