-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDialogHelper.js
More file actions
72 lines (61 loc) · 1.42 KB
/
DialogHelper.js
File metadata and controls
72 lines (61 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import Translation from 'src/structures/constants/translation.ts';
import eventEmitter from './eventEmitter.js';
export default class DialogHelper {
#instance;
#events = eventEmitter();
isOpen() {
return !!this.#instance;
}
open({
buttons = [],
cssClass = 'underscript-dialog',
message,
title,
...options
} = BootstrapDialog.defaultOptions) {
if (this.isOpen() || !message || !title) return;
BootstrapDialog.show({
...options,
title,
message,
buttons: [
...buttons,
{
cssClass: 'btn-primary',
label: `${Translation.CLOSE}`,
action: () => this.close(),
},
],
cssClass: `mono ${cssClass}`,
onshown: (diag) => {
this.#instance = diag;
this.#events.emit('open', diag);
},
onhidden: () => {
this.#instance = null;
this.#events.emit('close');
},
});
}
close() {
this.#instance?.close();
}
onClose(callback) {
this.#events.on('close', callback);
}
onOpen(callback) {
this.#events.on('open', callback);
}
appendButton(...buttons) {
const diag = this.#instance;
if (!diag) return;
diag.options.buttons.push(...buttons);
diag.updateButtons();
}
prependButton(...buttons) {
const diag = this.#instance;
if (!diag) return;
diag.options.buttons.unshift(...buttons);
diag.updateButtons();
}
}