You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
|
|
// the confirm action opens front-dialog
|
|
Turbo.config.forms.confirm = (content) => {
|
|
const dialog = document.getElementById('front-dialog')
|
|
const dialogContent = dialog.querySelector('[data-dialog-content]')
|
|
dialogContent.innerHTML = content
|
|
dialog.showModal()
|
|
return new Promise((resolve) => {
|
|
dialog.addEventListener(
|
|
'close',
|
|
() => { resolve(dialog.returnValue == 'confirm') },
|
|
{ once: true })
|
|
})
|
|
}
|
|
|
|
Turbo.config.forms.showModal = (dialogId) => {
|
|
const dialog = document.getElementById(dialogId)
|
|
if (dialog) dialog.showModal()
|
|
else console.warn(`dialog id=<${dialogId}> not found!`)
|
|
}
|
|
document.addEventListener('turbo:submit-start', (e) => {
|
|
const dialogId = e.explicitOriginalTarget.dataset.turboShowModal
|
|
if (dialogId) {
|
|
e.detail.formSubmission.stop()
|
|
Turbo.config.forms.showModal(dialogId)
|
|
}
|
|
})
|
|
|
|
Turbo.config.forms.closeModal = (dialogId) => {
|
|
console.log('closeModal called', dialogId)
|
|
}
|
|
document.addEventListener('turbo:submit-start', (e) => {
|
|
const dialogId = e.explicitOriginalTarget.dataset.turboCloseModal
|
|
if (dialogId) {
|
|
e.detail.formSubmission.stop()
|
|
Turbo.config.forms.closeModal(dialogId)
|
|
}
|
|
})
|
|
|
|
|