1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * ConfirmDialog.js
- *
- * @author realor
- */
- import { Dialog } from './Dialog.js'
- import { I18N } from '../i18n/I18N.js'
- class ConfirmDialog extends Dialog {
- action = null
- constructor(title, message, ...args) {
- super(title)
- if (typeof message !== 'string') {
- message = String(message)
- }
- this.addTextWithArgs(message, args)
- this.acceptButton = this.addButton('confirm_accept', 'button.accept', () => this.onAccept())
- this.cancelButton = this.addButton('confirm_cancel', 'button.cancel', () => this.onCancel())
- this.setClassName('confirm')
- }
- static create(title, message, ...args) {
- return new ConfirmDialog(title, message, ...args)
- }
- setAction(action) {
- this.action = action
- return this
- }
- setAcceptLabel(label) {
- I18N.set(this.acceptButton, 'innerHTML', label)
- return this
- }
- setCancelLabel(label) {
- I18N.set(this.cancelButton, 'innerHTML', label)
- return this
- }
- onShow() {
- this.cancelButton.focus()
- }
- onAccept() {
- this.action()
- this.hide()
- }
- onCancel() {
- this.hide()
- }
- }
- export { ConfirmDialog }
|