2022-04-15 14:24:30 +00:00
|
|
|
import alertify from 'alertify.js'
|
|
|
|
|
2022-05-14 15:13:29 +00:00
|
|
|
type LogType = 'success' | 'error' | 'log'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
const encodeEntities = (str: string) => str.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
|
|
|
|
export const alerts = {
|
2022-04-21 22:20:21 +00:00
|
|
|
alert: (msg: string) => alertify.alert(encodeEntities(msg)),
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-05-05 15:30:10 +00:00
|
|
|
confirm: (msg: string, okFunc: Closure, cancelFunc?: Closure) => {
|
2022-04-15 14:24:30 +00:00
|
|
|
alertify.confirm(msg, okFunc, cancelFunc)
|
|
|
|
},
|
|
|
|
|
2022-05-14 15:13:29 +00:00
|
|
|
log: (msg: string, type: LogType = 'log', cb?: Closure) => {
|
2022-04-15 14:24:30 +00:00
|
|
|
alertify.logPosition('top right')
|
|
|
|
alertify.closeLogOnClick(true)
|
|
|
|
alertify[type](encodeEntities(msg), cb)
|
|
|
|
},
|
|
|
|
|
2022-05-05 15:30:10 +00:00
|
|
|
success (msg: string, cb?: Closure) {
|
2022-04-15 14:24:30 +00:00
|
|
|
this.log(msg, 'success', cb)
|
|
|
|
},
|
|
|
|
|
2022-05-05 15:30:10 +00:00
|
|
|
error (msg: string, cb?: Closure) {
|
2022-04-15 14:24:30 +00:00
|
|
|
this.log(msg, 'error', cb)
|
|
|
|
}
|
|
|
|
}
|