2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2020-10-17 11:12:00 +00:00
|
|
|
<MkModal ref="modal" @click="done(true)" @closed="$emit('closed')">
|
|
|
|
<div class="mk-dialog">
|
|
|
|
<div class="icon" v-if="icon">
|
|
|
|
<Fa :icon="icon"/>
|
|
|
|
</div>
|
2020-10-25 02:29:10 +00:00
|
|
|
<div class="icon" v-else-if="!input && !select" :class="type">
|
2020-10-17 11:12:00 +00:00
|
|
|
<Fa :icon="faCheck" v-if="type === 'success'"/>
|
|
|
|
<Fa :icon="faTimesCircle" v-if="type === 'error'"/>
|
|
|
|
<Fa :icon="faExclamationTriangle" v-if="type === 'warning'"/>
|
|
|
|
<Fa :icon="faInfoCircle" v-if="type === 'info'"/>
|
|
|
|
<Fa :icon="faQuestionCircle" v-if="type === 'question'"/>
|
|
|
|
<Fa :icon="faSpinner" pulse v-if="type === 'waiting'"/>
|
|
|
|
</div>
|
2020-10-25 03:25:13 +00:00
|
|
|
<header v-if="title"><Mfm :text="title"/></header>
|
|
|
|
<div class="body" v-if="text"><Mfm :text="text"/></div>
|
2020-10-17 11:12:00 +00:00
|
|
|
<MkInput v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></MkInput>
|
|
|
|
<MkSelect v-if="select" v-model:value="selectedValue" autofocus>
|
|
|
|
<template v-if="select.items">
|
|
|
|
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-10-17 11:12:00 +00:00
|
|
|
<optgroup v-for="groupedItem in select.groupedItems" :label="groupedItem.label">
|
|
|
|
<option v-for="item in groupedItem.items" :value="item.value">{{ item.text }}</option>
|
|
|
|
</optgroup>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
2020-10-17 11:12:00 +00:00
|
|
|
</MkSelect>
|
|
|
|
<div class="buttons" v-if="(showOkButton || showCancelButton) && !actions">
|
2020-10-25 02:29:10 +00:00
|
|
|
<MkButton inline @click="ok" v-if="showOkButton" primary :autofocus="!input && !select">{{ (showCancelButton || input || select) ? $t('ok') : $t('gotIt') }}</MkButton>
|
|
|
|
<MkButton inline @click="cancel" v-if="showCancelButton || input || select">{{ $t('cancel') }}</MkButton>
|
2020-10-17 11:12:00 +00:00
|
|
|
</div>
|
|
|
|
<div class="buttons" v-if="actions">
|
|
|
|
<MkButton v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</MkButton>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
2020-10-17 11:12:00 +00:00
|
|
|
</div>
|
|
|
|
</MkModal>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 11:12:00 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-29 19:37:25 +00:00
|
|
|
import { faSpinner, faInfoCircle, faExclamationTriangle, faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faTimesCircle, faQuestionCircle } from '@fortawesome/free-regular-svg-icons';
|
2020-10-17 11:12:00 +00:00
|
|
|
import MkModal from '@/components/ui/modal.vue';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/ui/input.vue';
|
|
|
|
import MkSelect from '@/components/ui/select.vue';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
export default defineComponent({
|
2020-01-29 19:37:25 +00:00
|
|
|
components: {
|
2020-10-17 11:12:00 +00:00
|
|
|
MkModal,
|
2020-01-29 19:37:25 +00:00
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkSelect,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: 'info'
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
text: {
|
|
|
|
type: String,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
input: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
showOkButton: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
showCancelButton: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
cancelableByBgClick: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
emits: ['done', 'closed'],
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inputValue: this.input && this.input.default ? this.input.default : null,
|
|
|
|
selectedValue: this.select ? this.select.default ? this.select.default : this.select.items ? this.select.items[0].value : this.select.groupedItems[0].items[0].value : null,
|
|
|
|
faTimesCircle, faQuestionCircle, faSpinner, faInfoCircle, faExclamationTriangle, faCheck
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
document.addEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
beforeUnmount() {
|
2020-01-29 19:37:25 +00:00
|
|
|
document.removeEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 11:12:00 +00:00
|
|
|
done(canceled, result?) {
|
|
|
|
this.$emit('done', { canceled, result });
|
|
|
|
this.$refs.modal.close();
|
|
|
|
},
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
async ok() {
|
|
|
|
if (!this.showOkButton) return;
|
|
|
|
|
2020-10-25 02:29:10 +00:00
|
|
|
const result =
|
|
|
|
this.input ? this.inputValue :
|
|
|
|
this.select ? this.selectedValue :
|
|
|
|
true;
|
|
|
|
this.done(false, result);
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2020-10-17 11:12:00 +00:00
|
|
|
this.done(true);
|
2020-01-29 19:37:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onBgClick() {
|
|
|
|
if (this.cancelableByBgClick) {
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onKeydown(e) {
|
|
|
|
if (e.which === 27) { // ESC
|
|
|
|
this.cancel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onInputKeydown(e) {
|
|
|
|
if (e.which === 13) { // Enter
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
this.ok();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-dialog {
|
2020-10-17 11:12:00 +00:00
|
|
|
position: relative;
|
|
|
|
padding: 32px;
|
|
|
|
min-width: 320px;
|
|
|
|
max-width: 480px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
text-align: center;
|
|
|
|
background: var(--panel);
|
|
|
|
border-radius: var(--radius);
|
|
|
|
|
|
|
|
> .icon {
|
|
|
|
font-size: 32px;
|
|
|
|
|
|
|
|
&.success {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
&.error {
|
|
|
|
color: #ec4137;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
&.warning {
|
|
|
|
color: #ecb637;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> * {
|
|
|
|
display: block;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
& + header {
|
|
|
|
margin-top: 16px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> header {
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 20px;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
& + .body {
|
|
|
|
margin-top: 8px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> .body {
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> .buttons {
|
|
|
|
margin-top: 16px;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2020-10-17 11:12:00 +00:00
|
|
|
> * {
|
|
|
|
margin: 0 8px;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|