|
|
@ -1,14 +1,22 @@ |
|
|
Turbo.config.forms.confirm = (title) => { |
|
|
|
|
|
console.log('confirm called') |
|
|
|
|
|
const dialog = document.getElementById("front-dialog") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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() |
|
|
dialog.showModal() |
|
|
return new Promise((resolve) => { |
|
|
return new Promise((resolve) => { |
|
|
dialog.addEventListener("close", () => { resolve(dialog.returnValue == "confirm") }, { once: true }) |
|
|
|
|
|
|
|
|
dialog.addEventListener( |
|
|
|
|
|
'close', |
|
|
|
|
|
() => { resolve(dialog.returnValue == 'confirm') }, |
|
|
|
|
|
{ once: true }) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Turbo.config.forms.showModal = (dialogId) => { |
|
|
Turbo.config.forms.showModal = (dialogId) => { |
|
|
console.log('showModal called', dialogId) |
|
|
|
|
|
|
|
|
const dialog = document.getElementById(dialogId) |
|
|
|
|
|
if (dialog) dialog.showModal() |
|
|
|
|
|
else console.warn(`dialog id=<${dialogId}> not found!`) |
|
|
} |
|
|
} |
|
|
document.addEventListener('turbo:submit-start', (e) => { |
|
|
document.addEventListener('turbo:submit-start', (e) => { |
|
|
const dialogId = e.explicitOriginalTarget.dataset.turboShowModal |
|
|
const dialogId = e.explicitOriginalTarget.dataset.turboShowModal |
|
|
|