misc_pterodactyl-panel/resources/assets/scripts/mixins/flash.ts

58 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-12-30 03:24:09 +00:00
import {ComponentOptions} from "vue";
import {Vue} from "vue/types/vue";
export interface FlashInterface {
flash(message: string, title: string, severity: string): void;
clear(): void,
success(message: string): void,
info(message: string): void,
warning(message: string): void,
error(message: string): void,
}
class Flash implements FlashInterface {
flash(message: string, title: string, severity: string = 'info'): void {
severity = severity || 'info';
if (['danger', 'fatal', 'error'].includes(severity)) {
severity = 'error';
}
// @ts-ignore
window.events.$emit('flash', {message, title, severity});
}
clear(): void {
// @ts-ignore
window.events.$emit('clear-flashes');
}
2018-12-30 03:24:09 +00:00
success(message: string): void {
this.flash(message, 'Success', 'success');
}
info(message: string): void {
this.flash(message, 'Info', 'info');
}
warning(message: string): void {
this.flash(message, 'Warning', 'warning');
}
error(message: string): void {
this.flash(message, 'Error', 'error');
}
}
export const FlashMixin: ComponentOptions<Vue> = {
methods: {
'$flash': function () {
return new Flash();
}
},
};