summaryrefslogtreecommitdiff
path: root/src/client/app/admin/views/announcements.vue
blob: 31a2ab50b77d88c6b215d54ab03231a9c500edf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<template>
<div class="cdeuzmsthagexbkpofbmatmugjuvogfb">
	<ui-card>
		<div slot="title"><fa icon="broadcast-tower"/> {{ $t('announcements') }}</div>
		<section v-for="(announcement, i) in announcements" class="fit-top">
			<ui-input v-model="announcement.title" @change="save">
				<span>{{ $t('title') }}</span>
			</ui-input>
			<ui-textarea v-model="announcement.text">
				<span>{{ $t('text') }}</span>
			</ui-textarea>
			<ui-horizon-group>
				<ui-button @click="save()"><fa :icon="['far', 'save']"/> {{ $t('save') }}</ui-button>
				<ui-button @click="remove(i)"><fa :icon="['far', 'trash-alt']"/> {{ $t('remove') }}</ui-button>
			</ui-horizon-group>
		</section>
		<section>
			<ui-button @click="add"><fa icon="plus"/> {{ $t('add') }}</ui-button>
		</section>
	</ui-card>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import i18n from '../../i18n';

export default Vue.extend({
	i18n: i18n('admin/views/announcements.vue'),
	data() {
		return {
			announcements: [],
		};
	},

	created() {
		this.$root.getMeta().then(meta => {
			this.announcements = meta.broadcasts;
		});
	},

	methods: {
		add() {
			this.announcements.unshift({
				title: '',
				text: ''
			});
		},

		remove(i) {
			this.$root.alert({
				type: 'warning',
				text: this.$t('_remove.are-you-sure').replace('$1', this.announcements.find((_, j) => j == i).title),
				showCancelButton: true
			}).then(res => {
				if (!res) return;
				this.announcements = this.announcements.filter((_, j) => j !== i);
				this.save(true);
				this.$root.alert({
					type: 'success',
					text: this.$t('_remove.removed')
				});
			});
		},

		save(silent) {
			this.$root.api('admin/update-meta', {
				broadcasts: this.announcements
			}).then(() => {
				if (!silent) {
					this.$root.alert({
						type: 'success',
						text: this.$t('saved')
					});
				}
			}).catch(e => {
				this.$root.alert({
					type: 'error',
					text: e
				});
			});
		}
	}
});
</script>

<style lang="stylus" scoped>
.cdeuzmsthagexbkpofbmatmugjuvogfb
	@media (min-width 500px)
		padding 16px

</style>