2020-06-14 21:13:35 +00:00
|
|
|
import Vue from 'vue'
|
2020-06-15 19:08:42 +00:00
|
|
|
import FtToastEvents from './ft-toast-events.js'
|
2020-06-14 21:13:35 +00:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
name: 'FtToast',
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
isOpen: false,
|
2020-06-15 19:08:42 +00:00
|
|
|
message: '',
|
|
|
|
action: () => {},
|
|
|
|
queue: [],
|
2020-06-14 21:13:35 +00:00
|
|
|
}
|
|
|
|
},
|
2020-06-15 19:08:42 +00:00
|
|
|
mounted: function () {
|
|
|
|
FtToastEvents.$on('toast.open', this.open)
|
|
|
|
},
|
2020-06-14 21:13:35 +00:00
|
|
|
methods: {
|
|
|
|
performAction: function () {
|
|
|
|
this.action()
|
|
|
|
this.close()
|
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
this.isOpen = false
|
2020-06-15 19:08:42 +00:00
|
|
|
if(this.queue.length !== 0) {
|
|
|
|
const toast = this.queue.shift()
|
|
|
|
this.open(toast.message, toast.action)
|
|
|
|
}
|
2020-06-14 21:13:35 +00:00
|
|
|
},
|
2020-06-15 19:08:42 +00:00
|
|
|
open: function (message, action) {
|
|
|
|
if (this.isOpen) {
|
|
|
|
this.queue.push({ message: message, action: action })
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.message = message
|
|
|
|
this.action = action || (() => {});
|
2020-06-14 21:13:35 +00:00
|
|
|
this.isOpen = true
|
|
|
|
setTimeout(this.close, 2000)
|
|
|
|
},
|
|
|
|
},
|
2020-06-15 19:08:42 +00:00
|
|
|
beforeDestroy: function () {
|
|
|
|
FtToastEvents.$off('toast.open', this.open)
|
|
|
|
},
|
2020-06-14 21:13:35 +00:00
|
|
|
})
|