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

30 lines
772 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
2022-04-21 22:20:21 +00:00
confirm: (msg: string, okFunc: TAnyFunction, cancelFunc?: TAnyFunction) => {
2022-04-15 14:24:30 +00:00
alertify.confirm(msg, okFunc, cancelFunc)
},
2022-04-21 22:20:21 +00:00
log: (msg: string, type: logType = 'log', cb?: TAnyFunction) => {
2022-04-15 14:24:30 +00:00
alertify.logPosition('top right')
alertify.closeLogOnClick(true)
alertify[type](encodeEntities(msg), cb)
},
2022-04-21 22:20:21 +00:00
success (msg: string, cb?: TAnyFunction) {
2022-04-15 14:24:30 +00:00
this.log(msg, 'success', cb)
},
2022-04-21 22:20:21 +00:00
error (msg: string, cb?: TAnyFunction) {
2022-04-15 14:24:30 +00:00
this.log(msg, 'error', cb)
}
}