diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 21:09:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 21:09:21 +0000 |
commit | 06bb4eba7828ce59fde366734828458c037059b4 (patch) | |
tree | 44b95a53123d91684cc1c67716ef87cc1c0964fb /app/assets/javascripts/vue_shared/components/confirm_modal.vue | |
parent | 219eead23f9feb5da9ec378c451d773aea2dfe61 (diff) | |
download | gitlab-ce-06bb4eba7828ce59fde366734828458c037059b4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vue_shared/components/confirm_modal.vue')
-rw-r--r-- | app/assets/javascripts/vue_shared/components/confirm_modal.vue | 58 |
1 files changed, 27 insertions, 31 deletions
diff --git a/app/assets/javascripts/vue_shared/components/confirm_modal.vue b/app/assets/javascripts/vue_shared/components/confirm_modal.vue index c77827205d6..52ff906ccec 100644 --- a/app/assets/javascripts/vue_shared/components/confirm_modal.vue +++ b/app/assets/javascripts/vue_shared/components/confirm_modal.vue @@ -1,49 +1,45 @@ <script> import { GlModal } from '@gitlab/ui'; import csrf from '~/lib/utils/csrf'; +import { uniqueId } from 'lodash'; export default { components: { GlModal, }, props: { - modalAttributes: { - type: Object, - required: false, - default: () => { - return {}; - }, - }, - path: { - type: String, - required: false, - default: '', - }, - method: { + selector: { type: String, - required: false, - default: '', - }, - showModal: { - type: Boolean, - required: false, - default: false, + required: true, }, }, - watch: { - showModal(val) { - if (val) { - // Wait for v-if to render - this.$nextTick(() => { - this.openModal(); - }); - } - }, + data() { + return { + modalId: uniqueId('confirm-modal-'), + path: '', + method: '', + modalAttributes: {}, + }; + }, + mounted() { + document.querySelectorAll(this.selector).forEach(button => { + button.addEventListener('click', e => { + e.preventDefault(); + + this.path = button.dataset.path; + this.method = button.dataset.method; + this.modalAttributes = JSON.parse(button.dataset.modalAttributes); + this.openModal(); + }); + }); }, methods: { openModal() { this.$refs.modal.show(); }, + closeModal() { + this.$refs.modal.hide(); + }, submitModal() { this.$refs.form.submit(); }, @@ -54,11 +50,11 @@ export default { <template> <gl-modal - v-if="showModal" ref="modal" + :modal-id="modalId" v-bind="modalAttributes" @primary="submitModal" - @canceled="$emit('dismiss')" + @cancel="closeModal" > <form ref="form" :action="path" method="post"> <!-- Rails workaround for <form method="delete" /> |