2018-06-27 14:38:27 +00:00
|
|
|
import Observable from 'frappejs/utils/observable';
|
|
|
|
|
|
|
|
const Bus = new Observable();
|
|
|
|
|
|
|
|
export default {
|
|
|
|
// enable use of this.$modal in every component
|
|
|
|
// this also keeps only one modal in the DOM at any time
|
|
|
|
// which is the recommended way by bootstrap
|
|
|
|
install (Vue) {
|
|
|
|
Vue.prototype.$modal = {
|
|
|
|
show(options) {
|
|
|
|
Bus.trigger('showModal', options);
|
|
|
|
},
|
|
|
|
|
|
|
|
hide() {
|
|
|
|
Bus.trigger('hideModal');
|
2018-07-09 10:18:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
observable() {
|
|
|
|
return Bus;
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.mixin({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
registered: false,
|
|
|
|
modalVisible: false,
|
2018-07-09 10:18:09 +00:00
|
|
|
modalOptions: {},
|
|
|
|
modalListeners: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
modalVisible(value) {
|
|
|
|
if (value === true) {
|
|
|
|
Bus.trigger('modal.show');
|
|
|
|
} else {
|
|
|
|
Bus.trigger('modal.hide');
|
|
|
|
}
|
2018-06-27 14:38:27 +00:00
|
|
|
}
|
|
|
|
},
|
2018-07-09 10:18:09 +00:00
|
|
|
|
2018-06-27 14:38:27 +00:00
|
|
|
created: function () {
|
|
|
|
if (this.registered) return;
|
|
|
|
|
|
|
|
Bus.on('showModal', (options = {}) => {
|
|
|
|
this.modalVisible = true;
|
|
|
|
this.modalOptions = options;
|
|
|
|
});
|
|
|
|
|
|
|
|
Bus.on('hideModal', () => {
|
|
|
|
this.modalVisible = false;
|
2018-07-09 10:18:09 +00:00
|
|
|
this.modalOptions = {};
|
2018-06-27 14:38:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.registered = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|