-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdialog.js
More file actions
84 lines (77 loc) · 1.86 KB
/
dialog.js
File metadata and controls
84 lines (77 loc) · 1.86 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
73
74
75
76
77
78
79
80
81
82
83
84
import { Dialog } from 'quasar'
import $lang from './Lang'
/**
* @param {string} message
* @param {Object} options
* @returns {Promise}
*/
export function alert (message, options = { title: '' }) {
if (!options.title) {
options.title = $lang('agnostic.dialog.alert.title')
}
const _options = {
message: $lang(message, message),
...options
}
return Dialog.create(_options)
.onOk(() => undefined)
.onCancel(() => undefined)
.onDismiss(() => undefined)
}
/**
* @param {string} message
* @param {Object} options
* @returns {Promise}
*/
export function confirm (message, options = { title: '' }) {
if (!options.title) {
options.title = $lang('agnostic.dialog.confirm.title')
}
const _options = {
persistent: true,
ok: {
label: $lang('agnostic.options.yesNo.yes'),
flat: true
},
cancel: {
label: $lang('agnostic.options.yesNo.no'),
flat: true
},
message: $lang(message, message),
...options
}
return new Promise((resolve, reject) => {
Dialog.create(_options)
.onOk(() => resolve(true))
.onCancel(() => reject({ type: 'cancel' }))
.onDismiss(() => reject({ type: 'dismiss' }))
})
}
/**
* @param {string} message
* @param {Object} options
* @returns {Promise}
*/
export function prompt (message, options = { title: '', isValid: undefined }) {
const { title, isValid } = options
if (!title) {
options.title = $lang('agnostic.dialog.prompt.title')
}
const _options = {
cancel: true,
persistent: true,
prompt: {
model: '',
type: 'text',
isValid
},
message: $lang(message, message),
...options
}
return new Promise((resolve, reject) => {
Dialog.create(_options)
.onOk((data) => resolve(data))
.onCancel(() => reject({ type: 'cancel' }))
.onDismiss(() => reject({ type: 'dismiss' }))
})
}