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'
type logType = 'success' | 'error' | 'log'
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)
},
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)
}
}