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

27 lines
796 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-05-14 15:54:26 +00:00
alert: (message: string) => alertify.alert(encodeEntities(message)),
confirm: (message: string, onOk: Closure, onCancel?: Closure) => alertify.confirm(message, onOk, onCancel),
2022-04-15 14:24:30 +00:00
2022-05-14 15:54:26 +00:00
log: (message: string, type: LogType, callback?: Closure) => {
2022-04-15 14:24:30 +00:00
alertify.logPosition('top right')
alertify.closeLogOnClick(true)
2022-05-14 15:54:26 +00:00
alertify[type](encodeEntities(message), callback)
2022-04-15 14:24:30 +00:00
},
2022-05-14 15:54:26 +00:00
success (message: string, callback?: Closure) {
this.log(message, 'success', callback)
2022-04-15 14:24:30 +00:00
},
2022-05-14 15:54:26 +00:00
error (message: string, callback?: Closure) {
this.log(message, 'error', callback)
2022-04-15 14:24:30 +00:00
}
}