2020-01-29 12:37:25 -07:00
|
|
|
<template>
|
|
|
|
<div class="ztgjmzrw">
|
2020-10-17 05:12:00 -06:00
|
|
|
<div class="_section">
|
|
|
|
<div class="_content">
|
2020-12-25 18:47:36 -07:00
|
|
|
<MkButton @click="add()" primary style="margin: 0 auto 16px auto;"><Fa :icon="faPlus"/> {{ $ts.add }}</MkButton>
|
2021-04-10 03:17:42 -06:00
|
|
|
<section class="_card _gap announcements" v-for="announcement in announcements">
|
2020-10-17 05:12:00 -06:00
|
|
|
<div class="_content announcement">
|
|
|
|
<MkInput v-model:value="announcement.title">
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.title }}</span>
|
2020-10-17 05:12:00 -06:00
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model:value="announcement.text">
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.text }}</span>
|
2020-10-17 05:12:00 -06:00
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model:value="announcement.imageUrl">
|
2020-12-25 18:47:36 -07:00
|
|
|
<span>{{ $ts.imageUrl }}</span>
|
2020-10-17 05:12:00 -06:00
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">{{ $t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
2020-12-25 18:47:36 -07:00
|
|
|
<MkButton class="button" inline @click="save(announcement)" primary><Fa :icon="faSave"/> {{ $ts.save }}</MkButton>
|
|
|
|
<MkButton class="button" inline @click="remove(announcement)"><Fa :icon="faTrashAlt"/> {{ $ts.remove }}</MkButton>
|
2020-10-17 05:12:00 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
2020-01-29 12:37:25 -07:00
|
|
|
</div>
|
2020-10-17 05:12:00 -06:00
|
|
|
</div>
|
2020-01-29 12:37:25 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 05:12:00 -06:00
|
|
|
import { defineComponent } from 'vue';
|
2020-01-29 12:37:25 -07:00
|
|
|
import { faBroadcastTower, faPlus } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSave, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
2021-03-23 02:30:14 -06:00
|
|
|
import MkButton from '@client/components/ui/button.vue';
|
|
|
|
import MkInput from '@client/components/ui/input.vue';
|
|
|
|
import MkTextarea from '@client/components/ui/textarea.vue';
|
|
|
|
import * as os from '@client/os';
|
2021-04-09 21:54:12 -06:00
|
|
|
import * as symbols from '@client/symbols';
|
2020-01-29 12:37:25 -07:00
|
|
|
|
2020-10-17 05:12:00 -06:00
|
|
|
export default defineComponent({
|
2020-01-29 12:37:25 -07:00
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkTextarea,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2021-04-09 21:54:12 -06:00
|
|
|
[symbols.PAGE_INFO]: {
|
2020-12-25 18:47:36 -07:00
|
|
|
title: this.$ts.announcements,
|
2020-11-03 04:36:12 -07:00
|
|
|
icon: faBroadcastTower
|
2020-10-17 05:12:00 -06:00
|
|
|
},
|
2020-01-29 12:37:25 -07:00
|
|
|
announcements: [],
|
|
|
|
faBroadcastTower, faSave, faTrashAlt, faPlus
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('admin/announcements/list').then(announcements => {
|
2020-01-29 12:37:25 -07:00
|
|
|
this.announcements = announcements;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
add() {
|
|
|
|
this.announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
|
|
|
imageUrl: null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
remove(announcement) {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2020-01-29 12:37:25 -07:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
this.announcements = this.announcements.filter(x => x != announcement);
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('admin/announcements/delete', announcement);
|
2020-01-29 12:37:25 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('admin/announcements/create', announcement).then(() => {
|
|
|
|
os.dialog({
|
2020-01-29 12:37:25 -07:00
|
|
|
type: 'success',
|
2020-12-25 18:47:36 -07:00
|
|
|
text: this.$ts.saved
|
2020-01-29 12:37:25 -07:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2020-01-29 12:37:25 -07:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.api('admin/announcements/update', announcement).then(() => {
|
|
|
|
os.dialog({
|
2020-01-29 12:37:25 -07:00
|
|
|
type: 'success',
|
2020-12-25 18:47:36 -07:00
|
|
|
text: this.$ts.saved
|
2020-01-29 12:37:25 -07:00
|
|
|
});
|
|
|
|
}).catch(e => {
|
2020-10-17 05:12:00 -06:00
|
|
|
os.dialog({
|
2020-01-29 12:37:25 -07:00
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|