2022-03-17 18:54:52 +00:00
|
|
|
import { mapState } from 'vuex'
|
2022-03-17 16:59:10 +00:00
|
|
|
import Announcement from '../announcement/announcement.vue'
|
2022-03-17 20:51:32 +00:00
|
|
|
import AnnouncementEditor from '../announcement_editor/announcement_editor.vue'
|
2022-03-17 16:59:10 +00:00
|
|
|
|
|
|
|
const AnnouncementsPage = {
|
|
|
|
components: {
|
2022-03-17 19:45:45 +00:00
|
|
|
Announcement,
|
2022-03-17 20:51:32 +00:00
|
|
|
AnnouncementEditor
|
2022-03-17 16:59:10 +00:00
|
|
|
},
|
2022-03-17 18:54:52 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
newAnnouncement: {
|
2022-03-17 19:45:45 +00:00
|
|
|
content: '',
|
|
|
|
startsAt: undefined,
|
|
|
|
endsAt: undefined,
|
|
|
|
allDay: false
|
2022-03-17 18:54:52 +00:00
|
|
|
},
|
|
|
|
posting: false,
|
|
|
|
error: undefined
|
|
|
|
}
|
|
|
|
},
|
2022-03-17 18:01:45 +00:00
|
|
|
mounted () {
|
|
|
|
this.$store.dispatch('fetchAnnouncements')
|
|
|
|
},
|
2022-03-17 16:59:10 +00:00
|
|
|
computed: {
|
2022-03-17 18:54:52 +00:00
|
|
|
...mapState({
|
|
|
|
currentUser: state => state.users.currentUser
|
|
|
|
}),
|
2022-03-17 16:59:10 +00:00
|
|
|
announcements () {
|
2022-03-17 18:01:45 +00:00
|
|
|
return this.$store.state.announcements.announcements
|
2022-12-24 17:17:09 +00:00
|
|
|
},
|
|
|
|
canPostAnnouncement () {
|
|
|
|
return this.currentUser && this.currentUser.privileges.includes('announcements_manage_announcements')
|
2022-03-17 16:59:10 +00:00
|
|
|
}
|
2022-03-17 18:54:52 +00:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
postAnnouncement () {
|
|
|
|
this.posting = true
|
|
|
|
this.$store.dispatch('postAnnouncement', this.newAnnouncement)
|
2022-03-17 19:45:45 +00:00
|
|
|
.then(() => {
|
|
|
|
this.newAnnouncement.content = ''
|
|
|
|
this.startsAt = undefined
|
|
|
|
this.endsAt = undefined
|
|
|
|
})
|
2022-03-17 18:54:52 +00:00
|
|
|
.catch(error => {
|
|
|
|
this.error = error.error
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.posting = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
clearError () {
|
|
|
|
this.error = undefined
|
|
|
|
}
|
2022-03-17 16:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AnnouncementsPage
|