scinote-web/app/javascript/vue/shared/confirmation_modal.vue

81 lines
2.1 KiB
Vue
Raw Normal View History

<template>
<div ref="modal" @keydown.esc="cancel" class="modal" tabindex="-1" role="dialog">
2024-05-23 19:12:05 +08:00
<div class="modal-dialog" role="document" :data-e2e="e2eAttributes.modalName">
<div class="modal-content">
<div class="modal-header">
2024-05-23 19:12:05 +08:00
<button type="button" class="close" data-dismiss="modal" aria-label="Close" :data-e2e="e2eAttributes.close"><i class="sn-icon sn-icon-close"></i></button>
<h4 class="modal-title" :data-e2e="e2eAttributes.title">
{{ title }}
</h4>
</div>
<div class="modal-body" v-html="description"></div>
<div class="modal-footer">
2024-05-23 19:12:05 +08:00
<button :class="cancelClass" @click="cancel" :data-e2e="e2eAttributes.cancel">{{ cancelText || i18n.t('general.cancel') }}</button>
<button :class="confirmClass" @click="confirm" :data-e2e="e2eAttributes.confirm">{{ confirmText || i18n.t('general.confirm') }}</button>
</div>
</div>
</div>
</div>
</template>
2024-05-24 19:26:58 +08:00
<script>
export default {
name: 'confirmationModal',
props: {
title: {
type: String,
required: true
},
2024-05-24 19:26:58 +08:00
description: {
type: String,
required: true
},
cancelText: {
type: String
},
cancelClass: {
type: String,
default: 'btn btn-secondary'
},
confirmText: {
type: String
},
confirmClass: {
type: String,
default: 'btn btn-primary'
},
e2eAttributes: {
type: Object,
default: () => ({})
}
},
mounted() {
$(this.$refs.modal).on('hidden.bs.modal', () => {
this.resolvePromise(false);
});
},
data() {
return {
resolvePromise: null,
rejectPromise: null
}
},
methods: {
show: function() {
$(this.$refs.modal).modal('show');
return new Promise((resolve, reject) => {
this.resolvePromise = resolve
this.rejectPromise = reject
})
},
2024-05-24 19:26:58 +08:00
confirm() {
this.resolvePromise(true)
$(this.$refs.modal).modal('hide');
},
2024-05-24 19:26:58 +08:00
cancel() {
this.resolvePromise(false)
$(this.$refs.modal).modal('hide');
}
}
2024-05-24 19:26:58 +08:00
};
</script>