1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-25 22:02:58 +03:00
guide/front/client/helpers/ConfirmDecorator.ts
avele 5f0724eba8
confirmation decorator and confir for trait delete (#257)
* added helper promise

* confirmation decorator and confir for trait delete
2019-01-10 19:49:01 +04:00

28 lines
889 B
TypeScript

interface IConfirmDialogProps {
text: string,
confirmBtnText?: string,
cancelBtnText?: string
}
/**
* Use only for vue components methods.
* Executes '_confirm' function (see confirmDialogMixin.ts) with provided options before executing following method.
* If not confirmed method is not executed.
* @param {Object} options - options passed to _confirm function
* @param {String} options.text
* @param {String} options.confirmBtnText
* @param {String} options.cancelBtnText
*/
export default function (options: IConfirmDialogProps) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
const originalFunction = descriptor.value
descriptor.value = async function (...args) {
const isConfirmed = await this._confirm(options)
if (!isConfirmed) {
return
}
originalFunction.apply(this, args)
}
}
}