2020-02-25 09:16:05 +00:00
|
|
|
<template>
|
2022-06-19 00:25:21 +00:00
|
|
|
<div id="confirm-dialog-overlay" :class="{opened: !!data}">
|
2020-02-25 09:16:05 +00:00
|
|
|
<div v-if="data !== null" id="confirm-dialog">
|
|
|
|
<div class="confirm-text">
|
2022-06-19 00:25:21 +00:00
|
|
|
<div class="confirm-text-title">{{ data?.title }}</div>
|
|
|
|
<p>{{ data?.text }}</p>
|
2020-02-25 09:16:05 +00:00
|
|
|
</div>
|
|
|
|
<div class="confirm-buttons">
|
|
|
|
<button class="btn btn-cancel" @click="close(false)">Cancel</button>
|
2022-06-19 00:25:21 +00:00
|
|
|
<button class="btn btn-danger" @click="close(true)">{{ data?.button }}</button>
|
2020-02-25 09:16:05 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#confirm-dialog {
|
|
|
|
background: var(--body-bg-color);
|
|
|
|
color: #fff;
|
|
|
|
margin: 10px;
|
|
|
|
border-radius: 5px;
|
|
|
|
max-width: 500px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#confirm-dialog .confirm-text {
|
|
|
|
padding: 15px;
|
|
|
|
user-select: text;
|
|
|
|
}
|
|
|
|
|
|
|
|
#confirm-dialog .confirm-text-title {
|
|
|
|
font-size: 20px;
|
|
|
|
font-weight: 700;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#confirm-dialog .confirm-buttons {
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
padding: 15px;
|
|
|
|
background: rgba(0, 0, 0, 0.3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#confirm-dialog .confirm-buttons .btn {
|
|
|
|
margin-bottom: 0;
|
|
|
|
margin-left: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#confirm-dialog .confirm-buttons .btn-cancel {
|
|
|
|
border-color: transparent;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
<script lang="ts">
|
2020-03-16 17:58:40 +00:00
|
|
|
import eventbus from "../js/eventbus";
|
2022-06-19 00:25:21 +00:00
|
|
|
import {defineComponent, onMounted, onUnmounted, ref} from "vue";
|
2020-03-16 17:58:40 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
type ConfirmDialogData = {
|
|
|
|
title: string;
|
|
|
|
text: string;
|
|
|
|
button: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ConfirmDialogCallback = {
|
|
|
|
(confirmed: boolean): void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default defineComponent({
|
2020-02-25 09:16:05 +00:00
|
|
|
name: "ConfirmDialog",
|
2022-06-19 00:25:21 +00:00
|
|
|
setup() {
|
|
|
|
const data = ref<ConfirmDialogData>();
|
|
|
|
const callback = ref<ConfirmDialogCallback>();
|
|
|
|
|
|
|
|
const open = (incoming: ConfirmDialogData, cb: ConfirmDialogCallback) => {
|
|
|
|
data.value = incoming;
|
|
|
|
callback.value = cb;
|
2020-02-25 09:16:05 +00:00
|
|
|
};
|
2022-06-19 00:25:21 +00:00
|
|
|
|
|
|
|
const close = (result: boolean) => {
|
|
|
|
data.value = undefined;
|
|
|
|
|
|
|
|
if (callback.value) {
|
|
|
|
callback.value(!!result);
|
2020-02-25 09:16:05 +00:00
|
|
|
}
|
2022-06-19 00:25:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
eventbus.on("escapekey", close);
|
|
|
|
eventbus.on("confirm-dialog", open);
|
|
|
|
});
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
eventbus.off("escapekey", close);
|
|
|
|
eventbus.off("confirm-dialog", open);
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data,
|
|
|
|
close,
|
|
|
|
};
|
2020-02-25 09:16:05 +00:00
|
|
|
},
|
2022-06-19 00:25:21 +00:00
|
|
|
});
|
2020-02-25 09:16:05 +00:00
|
|
|
</script>
|