1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-02 07:53:57 +03:00
guide/front/client/mixins/confirmDialogMixin.ts
avele 9e4146b5bc
Front/chore/migrate to vuetify 2.0 (#348)
* Vuetify updated

* Correct component creation in dialog mixins

* Vuetify 2.0 migration

* Conflict dialog content style fixed

* Removed duplicate attribute
2019-08-03 06:18:26 +04:00

54 lines
1.2 KiB
TypeScript

import Vue from 'vue'
import { Mixin } from 'vue-mixin-decorator'
import ConfirmDialog from 'client/components/ConfirmDialog.vue'
import DeferredPromise from 'utils/DeferredPromise'
const ComponentClass = Vue.extend(ConfirmDialog)
interface IConfirmDialogProps {
fullText?: string
text?: string
confirmBtnText?: string
cancelBtnText?: string,
confirmBtnProps?: object,
cancelBtnProps?: object
}
@Mixin
export default class ConfirmDialogMixin extends Vue {
async _confirm ({
text,
fullText,
confirmBtnText,
cancelBtnText,
confirmBtnProps,
cancelBtnProps
}: IConfirmDialogProps): Promise<boolean> {
const instance = new ComponentClass({
propsData: {
value: true,
text,
fullText,
confirmBtnText,
cancelBtnText,
confirmBtnProps,
cancelBtnProps
},
parent: this
})
instance.$mount()
const deferredPromise = new DeferredPromise()
instance.$on('confirmed', () => {
instance.$destroy()
deferredPromise.resolve(true)
})
instance.$on('canceled', () => {
instance.$destroy()
deferredPromise.resolve(false)
})
this.$el.appendChild(instance.$el)
return deferredPromise
}
}