This commit is contained in:
syuilo 2020-10-25 11:29:10 +09:00
parent d9be9c958f
commit 1b30d7d47a

View file

@ -4,7 +4,7 @@
<div class="icon" v-if="icon"> <div class="icon" v-if="icon">
<Fa :icon="icon"/> <Fa :icon="icon"/>
</div> </div>
<div class="icon" v-else-if="!input && !select && !user" :class="type"> <div class="icon" v-else-if="!input && !select" :class="type">
<Fa :icon="faCheck" v-if="type === 'success'"/> <Fa :icon="faCheck" v-if="type === 'success'"/>
<Fa :icon="faTimesCircle" v-if="type === 'error'"/> <Fa :icon="faTimesCircle" v-if="type === 'error'"/>
<Fa :icon="faExclamationTriangle" v-if="type === 'warning'"/> <Fa :icon="faExclamationTriangle" v-if="type === 'warning'"/>
@ -13,10 +13,8 @@
<Fa :icon="faSpinner" pulse v-if="type === 'waiting'"/> <Fa :icon="faSpinner" pulse v-if="type === 'waiting'"/>
</div> </div>
<header v-if="title" v-html="title"></header> <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> <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="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> <MkSelect v-if="select" v-model:value="selectedValue" autofocus>
<template v-if="select.items"> <template v-if="select.items">
<option v-for="item in select.items" :value="item.value">{{ item.text }}</option> <option v-for="item in select.items" :value="item.value">{{ item.text }}</option>
@ -28,8 +26,8 @@
</template> </template>
</MkSelect> </MkSelect>
<div class="buttons" v-if="(showOkButton || showCancelButton) && !actions"> <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="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 || user">{{ $t('cancel') }}</MkButton> <MkButton inline @click="cancel" v-if="showCancelButton || input || select">{{ $t('cancel') }}</MkButton>
</div> </div>
<div class="buttons" v-if="actions"> <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> <MkButton v-for="action in actions" inline @click="() => { action.callback(); close(); }" :primary="action.primary" :key="action.text">{{ action.text }}</MkButton>
@ -46,8 +44,6 @@ import MkModal from '@/components/ui/modal.vue';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/ui/input.vue'; import MkInput from '@/components/ui/input.vue';
import MkSelect from '@/components/ui/select.vue'; import MkSelect from '@/components/ui/select.vue';
import parseAcct from '../../misc/acct/parse';
import * as os from '@/os';
export default defineComponent({ export default defineComponent({
components: { components: {
@ -77,9 +73,6 @@ export default defineComponent({
select: { select: {
required: false required: false
}, },
user: {
required: false
},
icon: { icon: {
required: false required: false
}, },
@ -105,28 +98,12 @@ export default defineComponent({
data() { data() {
return { return {
inputValue: this.input && this.input.default ? this.input.default : null, 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, 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 faTimesCircle, faQuestionCircle, faSpinner, faInfoCircle, faExclamationTriangle, faCheck
}; };
}, },
watch: {
userInputValue() {
if (this.user) {
os.api('users/show', parseAcct(this.userInputValue)).then(u => {
this.canOk = u != null;
}).catch(() => {
this.canOk = false;
});
}
},
},
mounted() { mounted() {
if (this.user) this.canOk = false;
document.addEventListener('keydown', this.onKeydown); document.addEventListener('keydown', this.onKeydown);
}, },
@ -141,21 +118,13 @@ export default defineComponent({
}, },
async ok() { async ok() {
if (!this.canOk) return;
if (!this.showOkButton) return; if (!this.showOkButton) return;
if (this.user) {
const user = await os.api('users/show', parseAcct(this.userInputValue));
if (user) {
this.done(false, user);
}
} else {
const result = const result =
this.input ? this.inputValue : this.input ? this.inputValue :
this.select ? this.selectedValue : this.select ? this.selectedValue :
true; true;
this.done(false, result); this.done(false, result);
}
}, },
cancel() { cancel() {