2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header
|
|
|
|
><MkPageHeader
|
|
|
|
:actions="headerActions"
|
|
|
|
:tabs="headerTabs"
|
|
|
|
:display-back-button="true"
|
|
|
|
/></template>
|
|
|
|
<MkSpacer :content-max="900">
|
|
|
|
<div class="ztgjmzrw">
|
|
|
|
<section
|
|
|
|
v-for="announcement in announcements"
|
|
|
|
class="_card _gap announcements"
|
|
|
|
>
|
|
|
|
<div class="_content announcement">
|
|
|
|
<MkInput v-model="announcement.title">
|
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="announcement.text">
|
|
|
|
<template #label>{{ i18n.ts.text }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model="announcement.imageUrl">
|
|
|
|
<template #label>{{ i18n.ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">
|
|
|
|
{{
|
|
|
|
i18n.t("nUsersRead", { n: announcement.reads })
|
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
<div class="buttons">
|
|
|
|
<MkButton
|
|
|
|
class="button"
|
|
|
|
inline
|
|
|
|
primary
|
|
|
|
@click="save(announcement)"
|
|
|
|
><i
|
|
|
|
class="ph-floppy-disk-back ph-bold ph-lg"
|
|
|
|
></i>
|
|
|
|
{{ i18n.ts.save }}</MkButton
|
|
|
|
>
|
|
|
|
<MkButton
|
|
|
|
class="button"
|
|
|
|
inline
|
|
|
|
@click="remove(announcement)"
|
|
|
|
><i class="ph-trash ph-bold ph-lg"></i>
|
|
|
|
{{ i18n.ts.remove }}</MkButton
|
|
|
|
>
|
|
|
|
</div>
|
2022-06-20 10:38:49 +02:00
|
|
|
</div>
|
2023-04-08 02:01:42 +02:00
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 14:34:07 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import {} from "vue";
|
|
|
|
import MkButton from "@/components/MkButton.vue";
|
|
|
|
import MkInput from "@/components/form/input.vue";
|
|
|
|
import MkTextarea from "@/components/form/textarea.vue";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-14 14:34:07 +02:00
|
|
|
let announcements: any[] = $ref([]);
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("admin/announcements/list").then((announcementResponse) => {
|
2022-05-14 14:34:07 +02:00
|
|
|
announcements = announcementResponse;
|
|
|
|
});
|
2021-04-22 15:29:33 +02:00
|
|
|
|
2022-05-14 14:34:07 +02:00
|
|
|
function add() {
|
|
|
|
announcements.unshift({
|
|
|
|
id: null,
|
2023-04-08 02:01:42 +02:00
|
|
|
title: "",
|
|
|
|
text: "",
|
2022-06-20 10:38:49 +02:00
|
|
|
imageUrl: null,
|
2022-05-14 14:34:07 +02:00
|
|
|
});
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-14 14:34:07 +02:00
|
|
|
function remove(announcement) {
|
|
|
|
os.confirm({
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "warning",
|
|
|
|
text: i18n.t("removeAreYouSure", { x: announcement.title }),
|
2022-05-14 14:34:07 +02:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
2023-04-08 02:01:42 +02:00
|
|
|
announcements = announcements.filter((x) => x !== announcement);
|
|
|
|
os.api("admin/announcements/delete", announcement);
|
2022-05-14 14:34:07 +02:00
|
|
|
});
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-05-14 14:34:07 +02:00
|
|
|
function save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("admin/announcements/create", announcement)
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: "success",
|
|
|
|
text: i18n.ts.saved,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: err,
|
|
|
|
});
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
2022-05-14 14:34:07 +02:00
|
|
|
} else {
|
2023-04-08 02:01:42 +02:00
|
|
|
os.api("admin/announcements/update", announcement)
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: "success",
|
|
|
|
text: i18n.ts.saved,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
os.alert({
|
|
|
|
type: "error",
|
|
|
|
text: err,
|
|
|
|
});
|
2022-05-14 14:34:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const headerActions = $computed(() => [
|
|
|
|
{
|
|
|
|
asFullButton: true,
|
|
|
|
icon: "ph-plus ph-bold ph-lg",
|
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
},
|
|
|
|
]);
|
2022-06-20 10:38:49 +02:00
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2023-04-08 02:01:42 +02:00
|
|
|
icon: "ph-megaphone-simple ph-bold ph-lg",
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
2021-04-22 15:29:33 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ztgjmzrw {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
</style>
|