2018-05-26 21:50:38 +00:00
|
|
|
<template>
|
2018-05-28 23:28:36 +00:00
|
|
|
<div v-if="notifications.length > 0" :class="this.container">
|
|
|
|
<transition-group tag="div" name="fade">
|
2018-08-23 05:29:20 +00:00
|
|
|
<div v-for="(item, index) in notifications" :key="index">
|
|
|
|
<message-box
|
|
|
|
:class="[item.class, {'mb-2': index < notifications.length - 1}]"
|
|
|
|
:title="item.title"
|
|
|
|
:message="item.message"
|
|
|
|
/>
|
2018-05-26 21:50:38 +00:00
|
|
|
</div>
|
|
|
|
</transition-group>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2018-12-30 01:00:50 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import MessageBox from './MessageBox.vue';
|
|
|
|
|
2018-05-26 21:50:38 +00:00
|
|
|
export default {
|
|
|
|
name: 'flash',
|
2018-08-23 05:29:20 +00:00
|
|
|
components: {MessageBox},
|
2018-05-26 21:50:38 +00:00
|
|
|
props: {
|
2018-05-28 23:28:36 +00:00
|
|
|
container: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2018-05-26 21:50:38 +00:00
|
|
|
timeout: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
|
|
|
types: {
|
|
|
|
type: Object,
|
|
|
|
default: function () {
|
|
|
|
return {
|
|
|
|
base: 'alert',
|
|
|
|
success: 'alert success',
|
|
|
|
info: 'alert info',
|
|
|
|
warning: 'alert warning',
|
|
|
|
error: 'alert error',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
notifications: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen for flash events.
|
|
|
|
*/
|
|
|
|
created: function () {
|
|
|
|
const self = this;
|
|
|
|
window.events.$on('flash', function (data) {
|
|
|
|
self.flash(data.message, data.title, data.severity);
|
|
|
|
});
|
|
|
|
|
|
|
|
window.events.$on('clear-flashes', function () {
|
|
|
|
self.clear();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Flash a message to the screen when a flash event is emitted over
|
|
|
|
* the global event stream.
|
|
|
|
*
|
|
|
|
* @param {string} message
|
|
|
|
* @param {string} title
|
|
|
|
* @param {string} severity
|
|
|
|
*/
|
|
|
|
flash: function (message, title, severity) {
|
|
|
|
this.notifications.push({
|
|
|
|
message, severity, title, class: this.types[severity] || this.types.base,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.timeout > 0) {
|
|
|
|
setTimeout(this.hide, this.timeout);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all of the flash messages from the screen.
|
|
|
|
*/
|
|
|
|
clear: function () {
|
|
|
|
this.notifications = [];
|
|
|
|
window.events.$emit('flashes-cleared');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide a notification after a given amount of time.
|
|
|
|
*
|
|
|
|
* @param {int} item
|
|
|
|
*/
|
|
|
|
hide: function (item = this.notifications[0]) {
|
|
|
|
let key = this.notifications.indexOf(item);
|
|
|
|
this.notifications.splice(key, 1);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|