Change how flashed messages are processed

This commit is contained in:
Patrick Jentsch 2020-03-27 10:11:19 +01:00
parent 4af7d8d4ba
commit ca8d438e79
2 changed files with 9 additions and 15 deletions

View File

@ -22,7 +22,7 @@ nopaque.user.isAuthenticated = undefined;
nopaque.user.settings = {}
nopaque.user.settings.darkMode = undefined;
nopaque.flashedMessages = []
nopaque.flashedMessages = undefined;
// nopaque functions
nopaque.socket = {};
@ -82,14 +82,6 @@ nopaque.socket.init = function() {
});
}
nopaque.Workarounds = {};
nopaque.Workarounds.apply = function() {
// Disable all option elements with no value
for (let optionElement of document.querySelectorAll('option[value=""]')) {
optionElement.disabled = true;
}
}
nopaque.Forms = {};
nopaque.Forms.init = function() {
var abortRequestElement, parentElement, progressElement, progressModal,
@ -174,7 +166,7 @@ nopaque.Navigation.init = function() {
}
nopaque.toast = function(message, color="") {
nopaque.flash = function(message, color="") {
var toast, toastActionElement;
toast = M.toast({classes: color,
@ -189,10 +181,14 @@ nopaque.toast = function(message, color="") {
});
}
}
nopaque.toast = nopaque.flash
document.addEventListener("DOMContentLoaded", function() {
nopaque.Workarounds.apply();
// Disable all option elements with no value
for (let optionElement of document.querySelectorAll('option[value=""]')) {
optionElement.disabled = true;
}
M.AutoInit();
M.CharacterCounter.init(document.querySelectorAll('input[data-length][type="text"]'));
M.Dropdown.init(document.querySelectorAll("#nav-notifications, #nav-account"),
@ -200,7 +196,7 @@ document.addEventListener("DOMContentLoaded", function() {
nopaque.Forms.init();
nopaque.Navigation.init();
while (nopaque.flashedMessages.length) {
nopaque.toast(nopaque.flashedMessages.shift().message);
nopaque.flash(nopaque.flashedMessages.shift()[1]);
}
if (nopaque.user.isAuthenticated) {
if (nopaque.user.settings.darkMode) {

View File

@ -51,9 +51,7 @@
<script>
nopaque.user.isAuthenticated = {{ current_user.is_authenticated|tojson }};
nopaque.user.settings.darkMode = {{ (current_user.is_authenticated and current_user.is_dark)|tojson }};
{% for category, message in get_flashed_messages(with_categories=true) %}
nopaque.flashedMessages.push({category: {{ category|tojson }}, message: {{ message|tojson }}});
{% endfor %}
nopaque.flashedMessages = {{ get_flashed_messages(with_categories=true)|tojson }};
</script>
</head>
<body>