koel/resources/assets/js/utils/alerts.ts

30 lines
747 B
TypeScript
Raw Normal View History

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, '&lt;')
.replace(/>/g, '&gt;')
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
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)
},
success (msg: string, cb?: Closure) {
2022-04-15 14:24:30 +00:00
this.log(msg, 'success', cb)
},
error (msg: string, cb?: Closure) {
2022-04-15 14:24:30 +00:00
this.log(msg, 'error', cb)
}
}