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

59 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-12-30 03:24:09 +00:00
import {ComponentOptions} from "vue";
import {Vue} from "vue/types/vue";
2018-12-30 21:41:24 +00:00
import {TranslateResult} from "vue-i18n";
2018-12-30 03:24:09 +00:00
export interface FlashInterface {
2018-12-30 21:41:24 +00:00
flash(message: string | TranslateResult, title: string, severity: string): void;
2018-12-30 03:24:09 +00:00
clear(): void,
2018-12-30 21:41:24 +00:00
success(message: string | TranslateResult): void,
2018-12-30 03:24:09 +00:00
2018-12-30 21:41:24 +00:00
info(message: string | TranslateResult): void,
2018-12-30 03:24:09 +00:00
2018-12-30 21:41:24 +00:00
warning(message: string | TranslateResult): void,
2018-12-30 03:24:09 +00:00
2018-12-30 21:41:24 +00:00
error(message: string | TranslateResult): void,
2018-12-30 03:24:09 +00:00
}
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> = {
computed: {
2018-12-30 03:24:09 +00:00
'$flash': function () {
return new Flash();
}
},
};