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

53 lines
1.5 KiB
TypeScript
Raw Normal View History

export const flash = {
methods: {
/**
* Flash a message to the event stream in the browser.
*/
2018-12-17 02:57:34 +00:00
flash: function (message: string, title: string, severity: string = 'info'): void {
severity = severity || 'info';
if (['danger', 'fatal', 'error'].includes(severity)) {
severity = 'error';
}
2018-12-17 02:57:34 +00:00
// @ts-ignore
window.events.$emit('flash', { message, title, severity });
},
/**
* Clear all of the flash messages from the screen.
*/
2018-12-17 02:57:34 +00:00
clearFlashes: function (): void {
// @ts-ignore
window.events.$emit('clear-flashes');
},
/**
* Helper function to flash a normal success message to the user.
*/
2018-12-17 02:57:34 +00:00
success: function (message: string): void {
this.flash(message, 'Success', 'success');
},
/**
* Helper function to flash a normal info message to the user.
*/
2018-12-17 02:57:34 +00:00
info: function (message: string): void {
this.flash(message, 'Info', 'info');
},
/**
* Helper function to flash a normal warning message to the user.
*/
2018-12-17 02:57:34 +00:00
warning: function (message: string): void {
this.flash(message, 'Warning', 'warning');
},
/**
* Helper function to flash a normal error message to the user.
*/
2018-12-17 02:57:34 +00:00
error: function (message: string): void {
this.flash(message, 'Error', 'danger');
},
}
};