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

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