diff --git a/front/src/components/common/DangerousButton.vue b/front/src/components/common/DangerousButton.vue new file mode 100644 index 0000000000000000000000000000000000000000..03a579d29604e29ad170b61eff683ef7bf282fe2 --- /dev/null +++ b/front/src/components/common/DangerousButton.vue @@ -0,0 +1,44 @@ +<template> + <div @click="showModal = true" class="ui red button"> + <slot></slot> + + <modal class="small" :show.sync="showModal"> + <div class="header"> + <slot name="modal-header">Do you want to confirm this action?</slot> + </div> + <div class="scrolling content"> + <div class="description"> + <slot name="modal-content"></slot> + </div> + </div> + <div class="actions"> + <div class="ui cancel button">Cancel</div> + <div class="ui confirm red button" @click="confirm"> + <slot name="modal-confirm">Confirm</slot> + </div> + </div> + </modal> + </div> + +</template> +<script> +import Modal from '@/components/semantic/Modal' + +export default { + props: ['action'], + components: { + Modal + }, + data () { + return { + showModal: false + } + }, + methods: { + confirm () { + this.showModal = false + this.action() + } + } +} +</script> diff --git a/front/src/components/globals.js b/front/src/components/globals.js index b1d7d61041d31df9f9e47076e6ae273c8119c33b..79bbcf1b93a4a74ecf3c3b3d3d4e724870d7120c 100644 --- a/front/src/components/globals.js +++ b/front/src/components/globals.js @@ -8,4 +8,8 @@ import Username from '@/components/common/Username' Vue.component('username', Username) +import DangerousButton from '@/components/common/DangerousButton' + +Vue.component('dangerous-button', DangerousButton) + export default {} diff --git a/front/src/components/semantic/Modal.vue b/front/src/components/semantic/Modal.vue index ec7a5a0884262ac2437570cd6a360e231eaccaba..fec8fdd0595ffd8866d93e54bd2cffaedd2f52d5 100644 --- a/front/src/components/semantic/Modal.vue +++ b/front/src/components/semantic/Modal.vue @@ -2,7 +2,7 @@ <div :class="['ui', {'active': show}, 'modal']"> <i class="close icon"></i> <slot> - + </slot> </div> </template> @@ -19,26 +19,38 @@ export default { control: null } }, - mounted () { - this.control = $(this.$el).modal({ - onApprove: function () { - this.$emit('approved') - }.bind(this), - onDeny: function () { - this.$emit('deny') - }.bind(this), - onHidden: function () { - this.$emit('update:show', false) - }.bind(this) - }) + beforeDestroy () { + if (this.control) { + this.control.remove() + } + }, + methods: { + initModal () { + this.control = $(this.$el).modal({ + duration: 100, + onApprove: function () { + this.$emit('approved') + }.bind(this), + onDeny: function () { + this.$emit('deny') + }.bind(this), + onHidden: function () { + this.$emit('update:show', false) + }.bind(this) + }) + } }, watch: { show: { handler (newValue) { if (newValue) { + this.initModal() this.control.modal('show') } else { - this.control.modal('hide') + if (this.control) { + this.control.modal('hide') + this.control.remove() + } } } }