2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkModal ref="modal" @click="done(true)" @closed="$emit('closed')">
|
|
|
|
<div class="mk-dialog">
|
|
|
|
<div class="icon" v-if="icon">
|
|
|
|
<Fa :icon="icon"/>
|
|
|
|
</div>
|
|
|
|
<div class="icon" v-else-if="!input && !select && !user" :class="type">
|
|
|
|
<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>
|
|
|
|
<header v-if="title" v-html="title"></header>
|
|
|
|
<header v-if="title == null && user">{{ $t('enterUsername') }}</header>
|
|
|
|
<div class="body" v-if="text" v-html="text"></div>
|
|
|
|
<MkInput v-if="input" v-model:value="inputValue" autofocus :type="input.type || 'text'" :placeholder="input.placeholder" @keydown="onInputKeydown"></MkInput>
|
|
|
|
<MkInput v-if="user" v-model:value="userInputValue" autofocus @keydown="onInputKeydown"><template #prefix>@</template></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-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
2020-10-17 20:12:00 +09: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-30 04:37:25 +09:00
|
|
|
</template>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkSelect>
|
|
|
|
<div class="buttons" v-if="(showOkButton || showCancelButton) && !actions">
|
|
|
|
<MkButton inline @click="ok" v-if="showOkButton" primary :autofocus="!input && !select && !user" :disabled="!canOk">{{ (showCancelButton || input || select || user) ? $t('ok') : $t('gotIt') }}</MkButton>
|
|
|
|
<MkButton inline @click="cancel" v-if="showCancelButton || input || select || user">{{ $t('cancel') }}</MkButton>
|
|
|
|
</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-30 04:37:25 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</div>
|
|
|
|
</MkModal>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 20:12:00 +09:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-30 04:37:25 +09:00
|
|
|
import { faSpinner, faInfoCircle, faExclamationTriangle, faCheck } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faTimesCircle, faQuestionCircle } from '@fortawesome/free-regular-svg-icons';
|
2020-10-17 20:12:00 +09: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-30 04:37:25 +09:00
|
|
|
import parseAcct from '../../misc/acct/parse';
|
2020-10-17 20:12:00 +09:00
|
|
|
import * as os from '@/os';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
export default defineComponent({
|
2020-01-30 04:37:25 +09:00
|
|
|
components: {
|
2020-10-17 20:12:00 +09:00
|
|
|
MkModal,
|
2020-01-30 04:37:25 +09: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
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
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 20:12:00 +09:00
|
|
|
emits: ['done', 'closed'],
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
inputValue: this.input && this.input.default ? this.input.default : null,
|
|
|
|
userInputValue: 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,
|
|
|
|
canOk: true,
|
|
|
|
faTimesCircle, faQuestionCircle, faSpinner, faInfoCircle, faExclamationTriangle, faCheck
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
userInputValue() {
|
|
|
|
if (this.user) {
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('users/show', parseAcct(this.userInputValue)).then(u => {
|
2020-01-30 04:37:25 +09:00
|
|
|
this.canOk = u != null;
|
|
|
|
}).catch(() => {
|
|
|
|
this.canOk = false;
|
|
|
|
});
|
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
},
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
if (this.user) this.canOk = false;
|
|
|
|
|
|
|
|
document.addEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
beforeUnmount() {
|
2020-01-30 04:37:25 +09:00
|
|
|
document.removeEventListener('keydown', this.onKeydown);
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-17 20:12:00 +09:00
|
|
|
done(canceled, result?) {
|
|
|
|
this.$emit('done', { canceled, result });
|
|
|
|
this.$refs.modal.close();
|
|
|
|
},
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
async ok() {
|
|
|
|
if (!this.canOk) return;
|
|
|
|
if (!this.showOkButton) return;
|
|
|
|
|
|
|
|
if (this.user) {
|
2020-10-17 20:12:00 +09:00
|
|
|
const user = await os.api('users/show', parseAcct(this.userInputValue));
|
2020-01-30 04:37:25 +09:00
|
|
|
if (user) {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.done(false, user);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const result =
|
|
|
|
this.input ? this.inputValue :
|
|
|
|
this.select ? this.selectedValue :
|
|
|
|
true;
|
2020-10-17 20:12:00 +09:00
|
|
|
this.done(false, result);
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2020-10-17 20:12:00 +09:00
|
|
|
this.done(true);
|
2020-01-30 04:37:25 +09: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 20:12:00 +09: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-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.error {
|
|
|
|
color: #ec4137;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.warning {
|
|
|
|
color: #ecb637;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
display: block;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
& + header {
|
|
|
|
margin-top: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> header {
|
|
|
|
margin: 0 0 8px 0;
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 20px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
& + .body {
|
|
|
|
margin-top: 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
2020-10-17 20:12:00 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> .body {
|
|
|
|
margin: 16px 0 0 0;
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> .buttons {
|
|
|
|
margin-top: 16px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
margin: 0 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|