V2 #36

Merged
danieljsummers merged 17 commits from v2-out-the-door into main 2023-02-26 18:01:21 +00:00
2 changed files with 21 additions and 13 deletions
Showing only changes of commit 1963d226ae - Show all commits

View File

@ -122,7 +122,6 @@ module ViewContext =
let WebLog = "web_log" let WebLog = "web_log"
/// The HTTP item key for loading the session /// The HTTP item key for loading the session
let private sessionLoadedKey = "session-loaded" let private sessionLoadedKey = "session-loaded"

View File

@ -334,16 +334,12 @@ this.Admin = {
const theToast = new bootstrap.Toast(toast, options) const theToast = new bootstrap.Toast(toast, options)
theToast.show() theToast.show()
}) })
} },
}
htmx.on("htmx:afterOnLoad", function (evt) { /**
const hdrs = evt.detail.xhr.getAllResponseHeaders() * Initialize any toasts that were pre-rendered from the server
// Show messages if there were any in the response */
if (hdrs.indexOf("x-message") >= 0) { showPreRenderedMessages() {
Admin.showMessage(evt.detail.xhr.getResponseHeader("x-message"))
}
// Initialize any toasts that were pre-rendered from the server
[...document.querySelectorAll(".toast")].forEach(el => { [...document.querySelectorAll(".toast")].forEach(el => {
if (el.getAttribute("data-mwl-shown") === "true" && el.className.indexOf("hide") >= 0) { if (el.getAttribute("data-mwl-shown") === "true" && el.className.indexOf("hide") >= 0) {
document.removeChild(el) document.removeChild(el)
@ -355,6 +351,17 @@ htmx.on("htmx:afterOnLoad", function (evt) {
el.setAttribute("data-mwl-shown", "true") el.setAttribute("data-mwl-shown", "true")
} }
}) })
}
}
htmx.on("htmx:afterOnLoad", function (evt) {
const hdrs = evt.detail.xhr.getAllResponseHeaders()
// Initialize any toasts that were pre-rendered from the server
Admin.showPreRenderedMessages()
// Show messages if there were any in the response
if (hdrs.indexOf("x-message") >= 0) {
Admin.showMessage(evt.detail.xhr.getResponseHeader("x-message"))
}
}) })
htmx.on("htmx:responseError", function (evt) { htmx.on("htmx:responseError", function (evt) {
@ -365,3 +372,5 @@ htmx.on("htmx:responseError", function (evt) {
Admin.showMessage(`danger|||${xhr.status}: ${xhr.statusText}`) Admin.showMessage(`danger|||${xhr.status}: ${xhr.statusText}`)
} }
}) })
document.addEventListener("DOMContentLoaded", Admin.showPreRenderedMessages, { once: true})