BZModalDialog

This commit is contained in:
STEINNI
2026-04-07 16:10:42 +00:00
parent 158e9c4044
commit 0cc03cf512
7 changed files with 156 additions and 5 deletions

View File

@@ -11,6 +11,48 @@
* as long as the copyright notice and license are kept.
*/
function BZModalDialog(title, message) {
const getFields = (dlg) => {
const form = dlg.querySelector('form')
if (!form) return {}
const fd = new FormData(form)
const out = {}
for (const [key, value] of fd.entries()) {
if (Object.prototype.hasOwnProperty.call(out, key)) {
out[key] = Array.isArray(out[key]) ? [...out[key], value] : [out[key], value]
} else {
out[key] = value
}
}
return out
}
return new Promise(resolve => {
const dlg = document.createElement('dialog')
dlg.classList.add('bz-modal-dialog')
dlg.innerHTML = `
<form method="dialog">
<header>${title}</header>
<section>${message}</section>
<footer>
<button value="cancel">Cancel</button>
<button value="ok">OK</button>
</footer>
</form>
`
dlg.addEventListener('close', () => {
const ok = dlg.returnValue.toLowerCase() === 'ok'
if(ok) {
resolve(getFields(dlg))
} else {
resolve(ok)
}
dlg.remove()
})
document.body.appendChild(dlg)
dlg.showModal()
})
}
class Buildoz extends HTMLElement {
// static is evaluated when the class is defined, therefore while buildoz.js is executing.
@@ -386,4 +428,3 @@ class BZslidePane extends Buildoz {
}
}
Buildoz.define('slidepane', BZslidePane)