Better toast behavior.
This commit is contained in:
parent
eff6da0a3b
commit
0dbf246bdb
2 changed files with 58 additions and 20 deletions
|
|
@ -56,7 +56,7 @@
|
|||
{% block postmain %}
|
||||
{% endblock %}
|
||||
|
||||
<div class="toast-container position-fixed bottom-0 end p-3" id="toastContainer"></div>
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3" id="toastContainer"></div>
|
||||
|
||||
<footer class="bg-body-tertiary border border-bottom-0 position-fixed bottom-0 w-100 pb-1">
|
||||
<small>
|
||||
|
|
@ -77,8 +77,11 @@
|
|||
{% endblock %}
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
searchText = document.getElementById('searchText');
|
||||
searchButton = document.getElementById('searchButton');
|
||||
const searchText = document.getElementById('searchText');
|
||||
const searchButton = document.getElementById('searchButton');
|
||||
|
||||
if (searchText && searchButton) {
|
||||
searchButton.disabled = (searchText.value === "");
|
||||
|
||||
searchText.addEventListener('input', () => {
|
||||
searchButton.disabled = searchText.value == "";
|
||||
|
|
@ -86,15 +89,16 @@
|
|||
|
||||
searchText.addEventListener('keypress', (event) => {
|
||||
if (event.key === "Enter") {
|
||||
location.href = `{{ url_for('search.search') }}?q=${searchText.value}`;
|
||||
location.href = `{{ url_for('search.search') }}?q=${encodeURIComponent(searchText.value)}`;
|
||||
}
|
||||
});
|
||||
|
||||
searchButton.addEventListener('click', () => {
|
||||
location.href = `{{ url_for('search.search') }}?q=${searchText.value}`;
|
||||
location.href = `{{ url_for('search.search') }}?q=${encodeURIComponent(searchText.value)}`;
|
||||
});
|
||||
}
|
||||
|
||||
toastNumber = 0;
|
||||
window.toastNumber = 0;
|
||||
|
||||
window.toastMessage = function (message, type = 'info') {
|
||||
const container = document.getElementById('toastContainer');
|
||||
|
|
@ -114,9 +118,29 @@
|
|||
toast.show();
|
||||
};
|
||||
|
||||
window.queueToast = function (message, type = 'info') {
|
||||
try {
|
||||
const key = 'flashToasts';
|
||||
const list = JSON.parse(sessionStorage.getItem(key) || '[]');
|
||||
list.push({ message, type });
|
||||
sessionStorage.setItem(key, JSON.stringify(list));
|
||||
} catch {}
|
||||
};
|
||||
|
||||
{% block script %}
|
||||
{% endblock %}
|
||||
})
|
||||
|
||||
try {
|
||||
const key = 'flashToasts';
|
||||
const raw = sessionStorage.getItem(key);
|
||||
if (!raw) return;
|
||||
const list = JSON.parse(raw) || [];
|
||||
sessionStorage.removeItem(key);
|
||||
for (const t of list) {
|
||||
window.toastMessage(t.message, t.type || 'info');
|
||||
}
|
||||
} catch {}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
|
|
|||
|
|
@ -88,12 +88,26 @@
|
|||
});
|
||||
const reply = await res.json();
|
||||
if (reply.status === 'success') {
|
||||
toastMessage('This entry has been successfully saved!', 'success');
|
||||
if (!hasId && reply.id) {
|
||||
window.queueToast('Created successfully.', 'success');
|
||||
window.location.href - `/entry/${model}/${reply.id}`;
|
||||
return;
|
||||
} else {
|
||||
window.queueToast('Updated successfully.', 'success');
|
||||
|
||||
if (model === 'worklog') {
|
||||
for (const id of collectDeletedIds()) {
|
||||
const li = document.getElementById(`note-${id}`);
|
||||
if (li) li.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.newDrafts = [];
|
||||
window.deletedIds = [];
|
||||
if (!hasId && reply.id) {
|
||||
window.location.href = `/entry/${model}/${reply.id}`;
|
||||
}
|
||||
|
||||
window.location.replace(window.location.href);
|
||||
return;
|
||||
} else {
|
||||
toastMessage(`Unable to save entry: ${reply.error}`, 'danger');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue