2020-07-17 21:12:10 -06:00
|
|
|
<template>
|
2022-09-05 03:34:59 -06:00
|
|
|
<XModalWindow
|
|
|
|
ref="dialog"
|
2020-10-17 05:12:00 -06:00
|
|
|
:width="400"
|
|
|
|
:height="450"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="false"
|
|
|
|
:can-close="false"
|
2022-09-05 03:34:59 -06:00
|
|
|
@close="dialog.close()"
|
2020-10-17 05:12:00 -06:00
|
|
|
@closed="$emit('closed')"
|
|
|
|
@ok="ok()"
|
|
|
|
>
|
2022-11-10 15:12:44 -07:00
|
|
|
<template #header>{{ title || i18n.ts.generateAccessToken }}</template>
|
2020-10-17 05:12:00 -06:00
|
|
|
<div v-if="information" class="_section">
|
|
|
|
<MkInfo warn>{{ information }}</MkInfo>
|
2020-07-17 21:12:10 -06:00
|
|
|
</div>
|
2020-10-17 05:12:00 -06:00
|
|
|
<div class="_section">
|
2021-08-06 07:29:19 -06:00
|
|
|
<MkInput v-model="name">
|
2022-11-10 15:12:44 -07:00
|
|
|
<template #label>{{ i18n.ts.name }}</template>
|
2021-08-06 07:29:19 -06:00
|
|
|
</MkInput>
|
2020-10-17 05:12:00 -06:00
|
|
|
</div>
|
|
|
|
<div class="_section">
|
2022-11-10 15:12:44 -07:00
|
|
|
<div style="margin-bottom: 16px;"><b>{{ i18n.ts.permission }}</b></div>
|
|
|
|
<MkButton inline @click="disableAll">{{ i18n.ts.disableAll }}</MkButton>
|
|
|
|
<MkButton inline @click="enableAll">{{ i18n.ts.enableAll }}</MkButton>
|
2021-08-06 07:29:19 -06:00
|
|
|
<MkSwitch v-for="kind in (initialPermissions || kinds)" :key="kind" v-model="permissions[kind]">{{ $t(`_permissions.${kind}`) }}</MkSwitch>
|
2020-10-17 05:12:00 -06:00
|
|
|
</div>
|
|
|
|
</XModalWindow>
|
2020-07-17 21:12:10 -06:00
|
|
|
</template>
|
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
|
|
|
import { permissions as kinds } from 'misskey-js';
|
2021-09-29 09:50:45 -06:00
|
|
|
import MkInput from './form/input.vue';
|
|
|
|
import MkSwitch from './form/switch.vue';
|
2022-09-06 03:21:49 -06:00
|
|
|
import MkButton from './MkButton.vue';
|
|
|
|
import MkInfo from './MkInfo.vue';
|
|
|
|
import XModalWindow from '@/components/MkModalWindow.vue';
|
2022-11-10 15:12:44 -07:00
|
|
|
import { i18n } from '@/i18n';
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
title?: string | null;
|
|
|
|
information?: string | null;
|
|
|
|
initialName?: string | null;
|
|
|
|
initialPermissions?: string[] | null;
|
|
|
|
}>(), {
|
|
|
|
title: null,
|
|
|
|
information: null,
|
|
|
|
initialName: null,
|
|
|
|
initialPermissions: null,
|
|
|
|
});
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'closed'): void;
|
|
|
|
(ev: 'done', result: { name: string | null, permissions: string[] }): void;
|
|
|
|
}>();
|
2020-10-17 05:12:00 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
const dialog = $ref<InstanceType<typeof XModalWindow>>();
|
|
|
|
let name = $ref(props.initialName);
|
|
|
|
let permissions = $ref({});
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
if (props.initialPermissions) {
|
|
|
|
for (const kind of props.initialPermissions) {
|
|
|
|
permissions[kind] = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const kind of kinds) {
|
|
|
|
permissions[kind] = false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
function ok(): void {
|
|
|
|
emit('done', {
|
|
|
|
name: name,
|
|
|
|
permissions: Object.keys(permissions).filter(p => permissions[p]),
|
|
|
|
});
|
|
|
|
dialog.close();
|
|
|
|
}
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
function disableAll(): void {
|
|
|
|
for (const p in permissions) {
|
|
|
|
permissions[p] = false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-17 21:12:10 -06:00
|
|
|
|
2022-09-05 03:34:59 -06:00
|
|
|
function enableAll(): void {
|
|
|
|
for (const p in permissions) {
|
|
|
|
permissions[p] = true;
|
2020-07-17 21:12:10 -06:00
|
|
|
}
|
2022-09-05 03:34:59 -06:00
|
|
|
}
|
2020-07-17 21:12:10 -06:00
|
|
|
</script>
|