2023-08-13 13:12:29 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-08-13 13:12:29 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<MkModalWindow
|
|
|
|
ref="dialog"
|
|
|
|
:width="400"
|
2024-01-30 11:53:53 +01:00
|
|
|
@close="dialog?.close()"
|
2023-08-13 13:12:29 +02:00
|
|
|
@closed="$emit('closed')"
|
|
|
|
>
|
|
|
|
<template v-if="announcement" #header>:{{ announcement.title }}:</template>
|
|
|
|
<template v-else #header>New announcement</template>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<MkSpacer :marginMin="20" :marginMax="28">
|
|
|
|
<div class="_gaps_m">
|
|
|
|
<MkInput v-model="title">
|
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="text">
|
|
|
|
<template #label>{{ i18n.ts.text }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkRadios v-model="icon">
|
|
|
|
<template #label>{{ i18n.ts.icon }}</template>
|
2024-06-21 17:27:36 +02:00
|
|
|
<option value="info"><i class="ti ti-info-circle"></i></option>
|
2024-06-21 16:31:32 +02:00
|
|
|
<option value="warning"><i class="ti ti-alert-triangle" style="color: var(--warn);"></i></option>
|
2024-06-21 13:38:50 +02:00
|
|
|
<option value="error"><i class="ti ti-circle-x" style="color: var(--error);"></i></option>
|
2024-06-21 14:09:24 +02:00
|
|
|
<option value="success"><i class="ti ti-check" style="color: var(--success);"></i></option>
|
2023-08-13 13:12:29 +02:00
|
|
|
</MkRadios>
|
|
|
|
<MkRadios v-model="display">
|
|
|
|
<template #label>{{ i18n.ts.display }}</template>
|
|
|
|
<option value="normal">{{ i18n.ts.normal }}</option>
|
|
|
|
<option value="banner">{{ i18n.ts.banner }}</option>
|
|
|
|
<option value="dialog">{{ i18n.ts.dialog }}</option>
|
|
|
|
</MkRadios>
|
|
|
|
<MkSwitch v-model="needConfirmationToRead">
|
|
|
|
{{ i18n.ts._announcement.needConfirmationToRead }}
|
|
|
|
<template #caption>{{ i18n.ts._announcement.needConfirmationToReadDescription }}</template>
|
|
|
|
</MkSwitch>
|
2023-09-30 21:53:52 +02:00
|
|
|
<MkButton v-if="announcement" danger @click="del()"><i class="ph-trash ph-bold ph-lg"></i> {{ i18n.ts.delete }}</MkButton>
|
2023-08-13 13:12:29 +02:00
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
<div :class="$style.footer">
|
2024-06-21 14:09:24 +02:00
|
|
|
<MkButton primary rounded style="margin: 0 auto;" @click="done"><i class="ti ti-check"></i> {{ props.announcement ? i18n.ts.update : i18n.ts.create }}</MkButton>
|
2023-08-13 13:12:29 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkModalWindow>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2023-12-07 06:42:09 +01:00
|
|
|
import { ref } from 'vue';
|
2023-09-04 06:33:38 +02:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-08-13 13:12:29 +02:00
|
|
|
import MkModalWindow from '@/components/MkModalWindow.vue';
|
|
|
|
import MkButton from '@/components/MkButton.vue';
|
|
|
|
import MkInput from '@/components/MkInput.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
2023-08-13 13:12:29 +02:00
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
|
|
|
import MkSwitch from '@/components/MkSwitch.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
|
|
|
|
|
|
|
const props = defineProps<{
|
2023-09-04 06:33:38 +02:00
|
|
|
user: Misskey.entities.User,
|
2024-01-30 11:53:53 +01:00
|
|
|
announcement?: Misskey.entities.Announcement,
|
2023-08-13 13:12:29 +02:00
|
|
|
}>();
|
|
|
|
|
2023-12-26 06:19:35 +01:00
|
|
|
const dialog = ref<InstanceType<typeof MkModalWindow> | null>(null);
|
2024-01-30 11:53:53 +01:00
|
|
|
const title = ref(props.announcement ? props.announcement.title : '');
|
|
|
|
const text = ref(props.announcement ? props.announcement.text : '');
|
|
|
|
const icon = ref(props.announcement ? props.announcement.icon : 'info');
|
|
|
|
const display = ref(props.announcement ? props.announcement.display : 'dialog');
|
2023-12-07 06:42:09 +01:00
|
|
|
const needConfirmationToRead = ref(props.announcement ? props.announcement.needConfirmationToRead : false);
|
2023-08-13 13:12:29 +02:00
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'done', v: { deleted?: boolean; updated?: any; created?: any }): void,
|
|
|
|
(ev: 'closed'): void
|
|
|
|
}>();
|
|
|
|
|
|
|
|
async function done() {
|
|
|
|
const params = {
|
2023-12-07 06:42:09 +01:00
|
|
|
title: title.value,
|
|
|
|
text: text.value,
|
|
|
|
icon: icon.value,
|
2023-08-13 13:12:29 +02:00
|
|
|
imageUrl: null,
|
2023-12-07 06:42:09 +01:00
|
|
|
display: display.value,
|
|
|
|
needConfirmationToRead: needConfirmationToRead.value,
|
2023-08-13 13:12:29 +02:00
|
|
|
userId: props.user.id,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (props.announcement) {
|
|
|
|
await os.apiWithDialog('admin/announcements/update', {
|
|
|
|
...params,
|
2024-01-30 11:53:53 +01:00
|
|
|
id: props.announcement.id,
|
2023-08-13 13:12:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
emit('done', {
|
|
|
|
updated: {
|
|
|
|
...params,
|
2024-01-30 11:53:53 +01:00
|
|
|
id: props.announcement.id,
|
2023-08-13 13:12:29 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
dialog.value?.close();
|
2023-08-13 13:12:29 +02:00
|
|
|
} else {
|
|
|
|
const created = await os.apiWithDialog('admin/announcements/create', params);
|
|
|
|
|
|
|
|
emit('done', {
|
|
|
|
created: created,
|
|
|
|
});
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
dialog.value?.close();
|
2023-08-13 13:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function del() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2024-01-20 00:11:59 +01:00
|
|
|
text: i18n.tsx.removeAreYouSure({ x: title.value }),
|
2023-08-13 13:12:29 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2024-01-30 11:53:53 +01:00
|
|
|
if (props.announcement) {
|
|
|
|
await misskeyApi('admin/announcements/delete', {
|
|
|
|
id: props.announcement.id,
|
2023-08-13 13:12:29 +02:00
|
|
|
});
|
2024-01-30 11:53:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
emit('done', {
|
|
|
|
deleted: true,
|
2023-08-13 13:12:29 +02:00
|
|
|
});
|
2024-01-30 11:53:53 +01:00
|
|
|
dialog.value?.close();
|
2023-08-13 13:12:29 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.footer {
|
|
|
|
position: sticky;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
padding: 12px;
|
|
|
|
border-top: solid 0.5px var(--divider);
|
|
|
|
-webkit-backdrop-filter: var(--blur, blur(15px));
|
|
|
|
backdrop-filter: var(--blur, blur(15px));
|
|
|
|
}
|
|
|
|
</style>
|