2020-01-29 12:37:25 -07:00
|
|
|
<template>
|
|
|
|
<div class="ztgjmzrw">
|
|
|
|
<portal to="icon"><fa :icon="faBroadcastTower"/></portal>
|
2020-07-24 10:56:52 -06:00
|
|
|
<portal to="title">{{ $t('announcements') }}</portal>
|
2020-01-29 12:37:25 -07:00
|
|
|
<mk-button @click="add()" primary style="margin: 0 auto 16px auto;"><fa :icon="faPlus"/> {{ $t('add') }}</mk-button>
|
2020-01-29 19:10:42 -07:00
|
|
|
<section class="_card announcements">
|
2020-01-29 12:37:25 -07:00
|
|
|
<div class="_content announcement" v-for="announcement in announcements">
|
2020-02-13 09:24:05 -07:00
|
|
|
<mk-input v-model="announcement.title">
|
2020-07-24 10:56:52 -06:00
|
|
|
<span>{{ $t('title') }}</span>
|
2020-01-29 12:37:25 -07:00
|
|
|
</mk-input>
|
|
|
|
<mk-textarea v-model="announcement.text">
|
2020-07-24 10:56:52 -06:00
|
|
|
<span>{{ $t('text') }}</span>
|
2020-01-29 12:37:25 -07:00
|
|
|
</mk-textarea>
|
|
|
|
<mk-input v-model="announcement.imageUrl">
|
2020-07-24 10:56:52 -06:00
|
|
|
<span>{{ $t('imageUrl') }}</span>
|
2020-01-29 12:37:25 -07:00
|
|
|
</mk-input>
|
|
|
|
<p v-if="announcement.reads">{{ $t('nUsersRead', { n: announcement.reads }) }}</p>
|
|
|
|
<div class="buttons">
|
|
|
|
<mk-button class="button" inline @click="save(announcement)" primary><fa :icon="faSave"/> {{ $t('save') }}</mk-button>
|
|
|
|
<mk-button class="button" inline @click="remove(announcement)"><fa :icon="faTrashAlt"/> {{ $t('remove') }}</mk-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
|
|
|
import { faBroadcastTower, faPlus } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSave, faTrashAlt } from '@fortawesome/free-regular-svg-icons';
|
|
|
|
import MkButton from '../../components/ui/button.vue';
|
|
|
|
import MkInput from '../../components/ui/input.vue';
|
|
|
|
import MkTextarea from '../../components/ui/textarea.vue';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: this.$t('announcements') as string
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkTextarea,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
announcements: [],
|
|
|
|
faBroadcastTower, faSave, faTrashAlt, faPlus
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.$root.api('admin/announcements/list').then(announcements => {
|
|
|
|
this.announcements = announcements;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
add() {
|
|
|
|
this.announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
|
|
|
imageUrl: null
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
remove(announcement) {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
showCancelButton: true
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
this.announcements = this.announcements.filter(x => x != announcement);
|
|
|
|
this.$root.api('admin/announcements/delete', announcement);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
save(announcement) {
|
|
|
|
if (announcement.id == null) {
|
|
|
|
this.$root.api('admin/announcements/create', announcement).then(() => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
text: this.$t('saved')
|
|
|
|
});
|
|
|
|
}).catch(e => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$root.api('admin/announcements/update', announcement).then(() => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
text: this.$t('saved')
|
|
|
|
});
|
|
|
|
}).catch(e => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ztgjmzrw {
|
|
|
|
> .announcements {
|
|
|
|
> .announcement {
|
|
|
|
> .buttons {
|
|
|
|
> .button:first-child {
|
|
|
|
margin-right: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|