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">
|
|
|
|
<MkButton @click="add()" primary style="margin: 0 auto 16px auto;"><Fa :icon="faPlus"/> {{ $t('add') }}</MkButton>
|
|
|
|
<section class="_card _vMargin announcements" v-for="announcement in announcements">
|
|
|
|
<div class="_content announcement">
|
|
|
|
<MkInput v-model:value="announcement.title">
|
|
|
|
<span>{{ $t('title') }}</span>
|
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model:value="announcement.text">
|
|
|
|
<span>{{ $t('text') }}</span>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model:value="announcement.imageUrl">
|
|
|
|
<span>{{ $t('imageUrl') }}</span>
|
|
|
|
</MkInput>
|
|
|
|
<p v-if="announcement.reads">{{ $t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
|
|
|
<MkButton class="button" inline @click="save(announcement)" primary><Fa :icon="faSave"/> {{ $t('save') }}</MkButton>
|
|
|
|
<MkButton class="button" inline @click="remove(announcement)"><Fa :icon="faTrashAlt"/> {{ $t('remove') }}</MkButton>
|
|
|
|
</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';
|
2020-10-17 06:12:00 -05:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/ui/input.vue';
|
|
|
|
import MkTextarea from '@/components/ui/textarea.vue';
|
|
|
|
import * as os from '@/os';
|
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 {
|
2020-10-17 06:12:00 -05:00
|
|
|
INFO: {
|
|
|
|
header: [{
|
|
|
|
title: this.$t('announcements'),
|
|
|
|
icon: faBroadcastTower
|
|
|
|
}]
|
|
|
|
},
|
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',
|
|
|
|
text: this.$t('saved')
|
|
|
|
});
|
|
|
|
}).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',
|
|
|
|
text: this.$t('saved')
|
|
|
|
});
|
|
|
|
}).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>
|