|
|
@ -1,6 +1,7 @@ |
|
|
|
|
|
|
|
|
/** the confirm action opens the 'front-dialog' by default, customize if needed! */ |
|
|
/** the confirm action opens the 'front-dialog' by default, customize if needed! */ |
|
|
Turbo.config.forms.confirm_dialog_id = 'front-dialog' |
|
|
Turbo.config.forms.confirm_dialog_id = 'front-dialog' |
|
|
|
|
|
Turbo.config.forms.confirm_dialog_title_selector = '[data-dialog-title]' |
|
|
Turbo.config.forms.confirm_dialog_content_selector = '[data-dialog-content]' |
|
|
Turbo.config.forms.confirm_dialog_content_selector = '[data-dialog-content]' |
|
|
|
|
|
|
|
|
/** content might be either a String or a Boolean |
|
|
/** content might be either a String or a Boolean |
|
|
@ -27,14 +28,29 @@ Turbo.config.forms.confirm = (content) => { |
|
|
* |
|
|
* |
|
|
* in case of True: default dialog gets selected, (ie `Turbo.config.forms.confirm_dialog_id`) |
|
|
* in case of True: default dialog gets selected, (ie `Turbo.config.forms.confirm_dialog_id`) |
|
|
*/ |
|
|
*/ |
|
|
Turbo.config.forms.showModal = (dialogId) => { |
|
|
|
|
|
|
|
|
Turbo.config.forms.showModal = (dialogId, dialogTitle, dialogContent) => { |
|
|
if (dialogId.toString() == 'false') return |
|
|
if (dialogId.toString() == 'false') return |
|
|
if (dialogId.toString() == 'true') dialogId = Turbo.config.forms.confirm_dialog_id |
|
|
if (dialogId.toString() == 'true') dialogId = Turbo.config.forms.confirm_dialog_id |
|
|
|
|
|
if (dialogTitle == null) dialogTitle = dialogId |
|
|
|
|
|
|
|
|
const dialog = document.getElementById(dialogId) |
|
|
const dialog = document.getElementById(dialogId) |
|
|
if (dialog) dialog.showModal() |
|
|
|
|
|
|
|
|
if (dialog) { |
|
|
|
|
|
const dialogTitleElement = dialog.querySelector(Turbo.config.forms.confirm_dialog_title_selector) |
|
|
|
|
|
if (dialogTitleElement) dialogTitleElement.textContent = dialogTitle |
|
|
|
|
|
else console.warn(`dialogTitle element not found! missing selector='${Turbo.config.forms.confirm_dialog_title_selector}'`) |
|
|
|
|
|
|
|
|
|
|
|
if (dialogContent) { |
|
|
|
|
|
const dialogContentElement = dialog.querySelector(Turbo.config.forms.confirm_dialog_content_selector) |
|
|
|
|
|
if (dialogContentElement) dialogContentElement.replaceChildren(dialogContent) |
|
|
|
|
|
else console.warn(`dialogContent element not found! missing selector='${Turbo.config.forms.confirm_dialog_content_selector}'`) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dialog.showModal() |
|
|
|
|
|
} |
|
|
else console.warn(`dialog id=<${dialogId}> not found!`) |
|
|
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 |
|
|
if (dialogId) { |
|
|
if (dialogId) { |
|
|
|