Add custom flash library that works as expected

This commit is contained in:
Dane Everitt 2018-05-26 14:50:38 -07:00
parent bab20812a0
commit 0a706d1b45
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
13 changed files with 233 additions and 37 deletions

View file

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