Spaces:
Running
Running
File size: 987 Bytes
0760113 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
function init_sub_page(slug) {
console.log(`init_sub_page ${slug}`);
document.addEventListener("htmx:configRequest", (event) => {
if (!event.detail.path.startsWith(`/${slug}`)) {
event.detail.path = `/${slug}${event.detail.path}`;
}
});
document.addEventListener("htmx:afterRequest", (event) => {
let req = event.detail.requestConfig;
let detail = {
verb: req.verb,
path: req.path.slice(slug.length + 1),
parameters: Object.fromEntries(req.formData),
headers: req.headers,
response: event.detail.xhr.response,
};
window.parent.document.dispatchEvent(
new CustomEvent("SubappAfterRequest", { detail })
);
});
}
function init_main_page() {
console.log("init_main_page");
window.document.addEventListener(
"SubappAfterRequest",
(e) => {
htmx.ajax("PUT", "/requests", {
target: "#request-list",
values: e.detail,
swap: "afterbegin",
});
},
false
);
}
|