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