2020-02-16 21:03:50 +01:00
|
|
|
<template lang='pug'>
|
2020-07-25 21:41:22 +02:00
|
|
|
v-container
|
2020-08-05 17:29:03 +02:00
|
|
|
v-card-title {{$t('common.announcements')}}
|
|
|
|
v-card-subtitle(v-html="$t('admin.announcement_description')")
|
2020-10-07 11:12:13 +02:00
|
|
|
v-dialog(v-model='dialog' width='800px')
|
2020-10-09 00:40:36 +02:00
|
|
|
v-card(color='secondary')
|
2020-08-05 17:29:03 +02:00
|
|
|
v-card-title {{$t('admin.new_announcement')}}
|
2020-07-28 12:24:39 +02:00
|
|
|
v-card-text
|
2020-10-07 10:05:36 +02:00
|
|
|
v-form(v-model='valid' ref='announcement')
|
2020-08-16 14:06:21 +02:00
|
|
|
v-text-field(v-model='announcement.title' :label='$t("common.title")')
|
2021-01-24 18:20:29 +01:00
|
|
|
Editor.mt-2(v-model='announcement.announcement'
|
2020-10-09 00:40:36 +02:00
|
|
|
border no-save max-height='400px' :placeholder="$t('common.description')")
|
2020-08-05 17:29:03 +02:00
|
|
|
v-card-actions
|
|
|
|
v-spacer
|
2020-10-07 10:05:36 +02:00
|
|
|
v-btn(@click='dialog=false' color='error') {{$t('common.cancel')}}
|
2021-01-24 18:20:29 +01:00
|
|
|
v-btn(@click='save' color='primary' :disabled='loading' :loading='loading') {{$t(`common.${editing?'save':'send'}`)}}
|
2020-02-16 21:03:50 +01:00
|
|
|
|
2020-10-07 10:05:36 +02:00
|
|
|
v-btn(@click='openDialog' text color='primary') <v-icon>mdi-plus</v-icon> {{$t('common.add')}}
|
2020-08-05 17:29:03 +02:00
|
|
|
v-card-text
|
|
|
|
v-data-table(
|
2021-01-24 18:20:29 +01:00
|
|
|
v-if='announcements.length'
|
|
|
|
:hide-default-footer='announcements.length<10'
|
2020-08-05 17:29:03 +02:00
|
|
|
:headers='headers'
|
|
|
|
:items='announcements')
|
|
|
|
template(v-slot:item.actions='{ item }')
|
|
|
|
v-btn(text small @click.stop='toggle(item)'
|
2020-10-07 10:05:36 +02:00
|
|
|
:color='item.visible?"warning":"success"') {{item.visible?$t('common.disable'):$t('common.enable')}}
|
|
|
|
v-btn(text small @click='edit(item)' color='primary') {{$t('common.edit')}}
|
|
|
|
v-btn(text small @click='remove(item)' color='error') {{$t('common.delete')}}
|
2020-02-16 21:03:50 +01:00
|
|
|
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import { mapActions } from 'vuex'
|
|
|
|
import cloneDeep from 'lodash/cloneDeep'
|
|
|
|
import Editor from '../Editor'
|
|
|
|
import Announcement from '../Announcement'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: { Editor, Announcement },
|
|
|
|
data () {
|
|
|
|
return {
|
2020-08-05 17:29:03 +02:00
|
|
|
valid: false,
|
2020-07-28 12:24:39 +02:00
|
|
|
dialog: false,
|
2020-02-16 21:03:50 +01:00
|
|
|
editing: false,
|
|
|
|
announcements: [],
|
2021-01-24 18:20:29 +01:00
|
|
|
loading: false,
|
2020-07-28 12:24:39 +02:00
|
|
|
headers: [
|
|
|
|
{ value: 'title', text: 'Title' },
|
|
|
|
{ value: 'actions', text: 'Actions', align: 'right' }
|
|
|
|
],
|
2020-02-16 21:03:50 +01:00
|
|
|
announcement: { title: '', announcement: '' }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async mounted () {
|
|
|
|
this.announcements = await this.$axios.$get('/announcements')
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['setAnnouncements']),
|
|
|
|
edit (announcement) {
|
|
|
|
this.announcement.title = announcement.title
|
|
|
|
this.announcement.announcement = announcement.announcement
|
|
|
|
this.announcement.id = announcement.id
|
2020-10-07 10:05:36 +02:00
|
|
|
this.editing = true
|
2020-07-28 12:24:39 +02:00
|
|
|
this.dialog = true
|
2020-02-16 21:03:50 +01:00
|
|
|
},
|
2020-10-07 10:05:36 +02:00
|
|
|
openDialog () {
|
|
|
|
this.announcement = { title: '', announcement: '' }
|
|
|
|
this.dialog = true
|
2021-01-24 18:20:29 +01:00
|
|
|
this.$nextTick(() => this.$refs.announcement.reset())
|
2020-10-07 10:05:36 +02:00
|
|
|
},
|
2020-02-16 21:03:50 +01:00
|
|
|
async toggle (announcement) {
|
|
|
|
try {
|
|
|
|
announcement.visible = !announcement.visible
|
|
|
|
await this.$axios.$put(`/announcements/${announcement.id}`, announcement)
|
|
|
|
this.announcements = this.announcements.map(a => a.id === announcement.id ? announcement : a)
|
|
|
|
this.setAnnouncements(cloneDeep(this.announcements.filter(a => a.visible)))
|
|
|
|
} catch (e) {}
|
|
|
|
},
|
2020-10-07 11:12:13 +02:00
|
|
|
async remove (announcement) {
|
|
|
|
const ret = await this.$root.$confirm('admin.delete_announcement_confirm')
|
2021-01-24 18:20:29 +01:00
|
|
|
if (!ret) { return }
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$axios.delete(`/announcements/${announcement.id}`)
|
2020-02-16 21:03:50 +01:00
|
|
|
.then(() => {
|
2020-10-07 11:12:13 +02:00
|
|
|
this.$root.$message('admin.announcement_remove_ok')
|
2020-02-16 21:03:50 +01:00
|
|
|
this.announcements = this.announcements.filter(a => a.id !== announcement.id)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
async save () {
|
2021-01-24 18:20:29 +01:00
|
|
|
this.loading = true
|
2020-02-16 21:03:50 +01:00
|
|
|
try {
|
|
|
|
let announcement = null
|
|
|
|
if (this.editing) {
|
|
|
|
announcement = await this.$axios.$put(`/announcements/${this.announcement.id}`, this.announcement)
|
|
|
|
this.announcements = this.announcements.map(a => a.id === announcement.id ? announcement : a)
|
|
|
|
} else {
|
|
|
|
announcement = await this.$axios.$post('/announcements', this.announcement)
|
|
|
|
this.announcements = this.announcements.concat(announcement)
|
|
|
|
}
|
|
|
|
this.setAnnouncements(cloneDeep(this.announcements))
|
|
|
|
this.announcement = { title: '', announcement: '' }
|
2020-10-07 10:05:36 +02:00
|
|
|
this.$refs.announcement.reset()
|
2020-02-16 21:03:50 +01:00
|
|
|
this.editing = false
|
2020-10-07 10:05:36 +02:00
|
|
|
this.dialog = false
|
2020-02-16 21:03:50 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e)
|
|
|
|
}
|
2021-01-24 18:20:29 +01:00
|
|
|
this.loading = false
|
2020-02-16 21:03:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|