2020-07-18 05:12:10 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<XModalWindow
|
|
|
|
ref="dialog"
|
|
|
|
:width="400"
|
|
|
|
:height="600"
|
|
|
|
:with-ok-button="true"
|
|
|
|
:ok-button-disabled="false"
|
|
|
|
:can-close="false"
|
|
|
|
@close="dialog.close()"
|
|
|
|
@closed="$emit('closed')"
|
|
|
|
@ok="ok()"
|
|
|
|
style="padding: 12px"
|
|
|
|
>
|
|
|
|
<template #header>{{ title || i18n.ts.generateAccessToken }}</template>
|
|
|
|
<div v-if="information" class="_section">
|
|
|
|
<MkInfo warn>{{ information }}</MkInfo>
|
|
|
|
</div>
|
|
|
|
<div class="_section">
|
|
|
|
<div style="margin-bottom: 16px">
|
|
|
|
<b>{{ i18n.ts.name }}</b>
|
|
|
|
</div>
|
|
|
|
<MkInput style="margin-bottom: 16px" v-model="name" />
|
|
|
|
</div>
|
|
|
|
<div class="_section">
|
|
|
|
<div style="margin-bottom: 16px">
|
|
|
|
<b>{{ i18n.ts.permission }}</b>
|
|
|
|
</div>
|
|
|
|
<MkButton inline @click="disableAll">{{
|
|
|
|
i18n.ts.disableAll
|
|
|
|
}}</MkButton>
|
|
|
|
<MkButton style="margin-bottom: 12px" inline @click="enableAll">{{
|
|
|
|
i18n.ts.enableAll
|
|
|
|
}}</MkButton>
|
|
|
|
<MkSwitch
|
|
|
|
style="margin-bottom: 6px"
|
|
|
|
v-for="kind in initialPermissions || kinds"
|
|
|
|
:key="kind"
|
|
|
|
v-model="permissions[kind]"
|
|
|
|
>{{ i18n.t(`_permissions.${kind}`) }}</MkSwitch
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</XModalWindow>
|
2020-07-18 05:12:10 +02:00
|
|
|
</template>
|
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import {} from "vue";
|
|
|
|
import { permissions as kinds } from "calckey-js";
|
|
|
|
import MkInput from "./form/input.vue";
|
|
|
|
import MkSwitch from "./form/switch.vue";
|
|
|
|
import MkButton from "./MkButton.vue";
|
|
|
|
import MkInfo from "./MkInfo.vue";
|
|
|
|
import XModalWindow from "@/components/MkModalWindow.vue";
|
|
|
|
import { i18n } from "@/i18n";
|
2020-07-18 05:12:10 +02:00
|
|
|
|
2023-04-08 02:01:42 +02: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-18 05:12:10 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
const emit = defineEmits<{
|
2023-04-08 02:01:42 +02:00
|
|
|
(ev: "closed"): void;
|
|
|
|
(ev: "done", result: { name: string | null; permissions: string[] }): void;
|
2022-09-05 11:34:59 +02:00
|
|
|
}>();
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
const dialog = $ref<InstanceType<typeof XModalWindow>>();
|
|
|
|
let name = $ref(props.initialName);
|
|
|
|
let permissions = $ref({});
|
2020-07-18 05:12:10 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
if (props.initialPermissions) {
|
|
|
|
for (const kind of props.initialPermissions) {
|
|
|
|
permissions[kind] = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const kind of kinds) {
|
|
|
|
permissions[kind] = false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 05:12:10 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
function ok(): void {
|
2023-04-08 02:01:42 +02:00
|
|
|
emit("done", {
|
2022-09-05 11:34:59 +02:00
|
|
|
name: name,
|
2023-04-08 02:01:42 +02:00
|
|
|
permissions: Object.keys(permissions).filter((p) => permissions[p]),
|
2022-09-05 11:34:59 +02:00
|
|
|
});
|
|
|
|
dialog.close();
|
|
|
|
}
|
2020-07-18 05:12:10 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
function disableAll(): void {
|
|
|
|
for (const p in permissions) {
|
|
|
|
permissions[p] = false;
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 05:12:10 +02:00
|
|
|
|
2022-09-05 11:34:59 +02:00
|
|
|
function enableAll(): void {
|
|
|
|
for (const p in permissions) {
|
|
|
|
permissions[p] = true;
|
2020-07-18 05:12:10 +02:00
|
|
|
}
|
2022-09-05 11:34:59 +02:00
|
|
|
}
|
2020-07-18 05:12:10 +02:00
|
|
|
</script>
|