2023-01-12 21:02:26 +09:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<MkStickyContainer>
|
2023-03-02 20:47:24 +09:00
|
|
|
<template #header><XHeader :tabs="headerTabs"/></template>
|
2023-05-19 20:52:15 +09:00
|
|
|
<MkSpacer :contentMax="600" :marginMin="16" :marginMax="32">
|
2023-03-02 20:47:24 +09:00
|
|
|
<XEditor v-if="data" v-model="data"/>
|
2023-01-12 21:02:26 +09:00
|
|
|
</MkSpacer>
|
2023-03-02 20:47:24 +09:00
|
|
|
<template #footer>
|
|
|
|
<div :class="$style.footer">
|
2023-05-19 20:52:15 +09:00
|
|
|
<MkSpacer :contentMax="600" :marginMin="16" :marginMax="16">
|
2023-03-02 20:47:24 +09:00
|
|
|
<MkButton primary rounded @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
|
|
|
|
</MkSpacer>
|
|
|
|
</div>
|
|
|
|
</template>
|
2023-01-12 21:02:26 +09:00
|
|
|
</MkStickyContainer>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed } from 'vue';
|
2023-03-02 20:47:24 +09:00
|
|
|
import { v4 as uuid } from 'uuid';
|
2023-01-12 21:02:26 +09:00
|
|
|
import XHeader from './_header_.vue';
|
|
|
|
import XEditor from './roles.editor.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
|
|
|
import { useRouter } from '@/router';
|
2023-03-02 20:47:24 +09:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-03-24 16:54:37 +09:00
|
|
|
import { rolesCache } from '@/cache';
|
2023-01-12 21:02:26 +09:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
id?: string;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
let role = $ref(null);
|
2023-03-02 20:47:24 +09:00
|
|
|
let data = $ref(null);
|
2023-01-12 21:02:26 +09:00
|
|
|
|
|
|
|
if (props.id) {
|
|
|
|
role = await os.api('admin/roles/show', {
|
|
|
|
roleId: props.id,
|
|
|
|
});
|
|
|
|
|
2023-03-02 20:47:24 +09:00
|
|
|
data = role;
|
|
|
|
} else {
|
|
|
|
data = {
|
|
|
|
name: 'New Role',
|
|
|
|
description: '',
|
2023-03-05 10:48:04 +09:00
|
|
|
isAdministrator: false,
|
|
|
|
isModerator: false,
|
2023-03-02 20:47:24 +09:00
|
|
|
color: null,
|
|
|
|
iconUrl: null,
|
|
|
|
target: 'manual',
|
|
|
|
condFormula: { id: uuid(), type: 'isRemote' },
|
|
|
|
isPublic: false,
|
2023-04-20 20:02:50 +09:00
|
|
|
isExplorable: false,
|
2023-03-02 20:47:24 +09:00
|
|
|
asBadge: false,
|
|
|
|
canEditMembersByModerator: false,
|
2023-03-12 16:38:08 +09:00
|
|
|
displayOrder: 0,
|
2023-03-02 20:47:24 +09:00
|
|
|
policies: {},
|
|
|
|
};
|
2023-01-12 21:02:26 +09:00
|
|
|
}
|
|
|
|
|
2023-03-02 20:47:24 +09:00
|
|
|
async function save() {
|
2023-03-24 16:54:37 +09:00
|
|
|
rolesCache.delete();
|
2023-03-02 20:47:24 +09:00
|
|
|
if (role) {
|
|
|
|
os.apiWithDialog('admin/roles/update', {
|
|
|
|
roleId: role.id,
|
|
|
|
...data,
|
|
|
|
});
|
|
|
|
router.push('/admin/roles/' + role.id);
|
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('admin/roles/create', {
|
|
|
|
...data,
|
|
|
|
});
|
|
|
|
router.push('/admin/roles/' + created.id);
|
|
|
|
}
|
2023-01-12 21:02:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => role ? {
|
|
|
|
title: i18n.ts._role.edit + ': ' + role.name,
|
|
|
|
icon: 'ti ti-badge',
|
|
|
|
} : {
|
|
|
|
title: i18n.ts._role.new,
|
|
|
|
icon: 'ti ti-badge',
|
|
|
|
}));
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2023-03-02 20:47:24 +09:00
|
|
|
.footer {
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
|
|
|
}
|
2023-01-12 21:02:26 +09:00
|
|
|
</style>
|