2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2021-10-23 21:03:07 +02:00
|
|
|
<div class="ztgjmzrw">
|
2021-11-19 11:36:12 +01:00
|
|
|
<section v-for="announcement in announcements" class="_card _gap announcements">
|
2021-10-23 21:03:07 +02:00
|
|
|
<div class="_content announcement">
|
|
|
|
<MkInput v-model="announcement.title">
|
|
|
|
<template #label>{{ $ts.title }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="announcement.text">
|
|
|
|
<template #label>{{ $ts.text }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model="announcement.imageUrl">
|
|
|
|
<template #label>{{ $ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">{{ $t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
2021-11-19 11:36:12 +01:00
|
|
|
<MkButton class="button" inline primary @click="save(announcement)"><i class="fas fa-save"></i> {{ $ts.save }}</MkButton>
|
2021-10-23 21:03:07 +02:00
|
|
|
<MkButton class="button" inline @click="remove(announcement)"><i class="fas fa-trash-alt"></i> {{ $ts.remove }}</MkButton>
|
2021-04-22 15:29:33 +02:00
|
|
|
</div>
|
2021-10-23 21:03:07 +02:00
|
|
|
</div>
|
|
|
|
</section>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { defineComponent } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkTextarea from '@/components/form/textarea.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-01-29 20:37:25 +01:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkTextarea,
|
|
|
|
},
|
|
|
|
|
2021-04-22 15:29:33 +02:00
|
|
|
emits: ['info'],
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.announcements,
|
2021-10-02 16:11:21 +02:00
|
|
|
icon: 'fas fa-broadcast-tower',
|
|
|
|
bg: 'var(--bg)',
|
2021-10-09 05:33:08 +02:00
|
|
|
actions: [{
|
|
|
|
asFullButton: true,
|
|
|
|
icon: 'fas fa-plus',
|
|
|
|
text: this.$ts.add,
|
|
|
|
handler: this.add,
|
|
|
|
}],
|
|
|
|
},
|
2020-01-29 20:37:25 +01:00
|
|
|
announcements: [],
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('admin/announcements/list').then(announcements => {
|
2020-01-29 20:37:25 +01:00
|
|
|
this.announcements = announcements;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-04-22 15:29:33 +02:00
|
|
|
mounted() {
|
|
|
|
this.$emit('info', this[symbols.PAGE_INFO]);
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
methods: {
|
|
|
|
add() {
|
|
|
|
this.announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
|
|
|
imageUrl: null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
remove(announcement) {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.confirm({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
this.announcements = this.announcements.filter(x => x != announcement);
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('admin/announcements/delete', announcement);
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('admin/announcements/create', announcement).then(() => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.saved
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('admin/announcements/update', announcement).then(() => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'success',
|
2020-12-26 02:47:36 +01:00
|
|
|
text: this.$ts.saved
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2021-11-18 10:45:58 +01:00
|
|
|
os.alert({
|
2020-01-29 20:37:25 +01:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2021-04-22 15:29:33 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ztgjmzrw {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
</style>
|