1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-24 21:35:06 +03:00
guide/front/client/mixins/confirmDialogMixin.ts
avele 199e55d435
Front/feat/duplicate category creation warning (#300)
* Confirm Dialog extended

* Confirmation for duplicate name dialog creation
2019-06-26 17:44:07 +04:00

41 lines
1.0 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
}
@Mixin
export default class ConfirmDialogMixin extends Vue {
async _confirm ({ text, fullText, confirmBtnText, cancelBtnText }: IConfirmDialogProps): Promise<boolean> {
const instance = new ComponentClass({
propsData: {
value: true,
text,
fullText,
confirmBtnText,
cancelBtnText
}
})
instance.$mount()
const deferredPromise = new DeferredPromise()
this.$el.appendChild(instance.$el)
instance.$on('confirmed', () => {
instance.$destroy()
deferredPromise.resolve(true)
})
instance.$on('canceled', () => {
instance.$destroy()
deferredPromise.resolve(false)
})
return deferredPromise
}
}