Sharkey/src/client/app/admin/views/announcements.vue

93 lines
2.1 KiB
Vue
Raw Normal View History

2018-09-03 17:23:50 +03:00
<template>
<div class="cdeuzmsthagexbkpofbmatmugjuvogfb">
2018-11-02 16:05:53 +02:00
<ui-card>
<div slot="title"><fa icon="broadcast-tower"/> {{ $t('announcements') }}</div>
2018-11-03 16:57:14 +02:00
<section v-for="(announcement, i) in announcements" class="fit-top">
<ui-input v-model="announcement.title" @change="save">
<span>{{ $t('title') }}</span>
2018-11-03 16:57:14 +02:00
</ui-input>
<ui-textarea v-model="announcement.text">
<span>{{ $t('text') }}</span>
2018-11-03 16:57:14 +02:00
</ui-textarea>
<ui-horizon-group class="fit-bottom">
<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>
2018-11-04 07:23:28 +02:00
</ui-horizon-group>
2018-11-03 16:57:14 +02:00
</section>
2018-11-02 16:05:53 +02:00
<section>
<ui-button @click="add"><fa icon="plus"/> {{ $t('add') }}</ui-button>
2018-11-02 16:05:53 +02:00
</section>
</ui-card>
2018-09-03 17:23:50 +03:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../i18n';
2018-09-03 17:23:50 +03:00
export default Vue.extend({
i18n: i18n('admin/views/announcements.vue'),
2018-09-03 17:23:50 +03:00
data() {
return {
2018-11-03 16:57:14 +02:00
announcements: [],
2018-09-03 17:23:50 +03:00
};
},
2018-11-03 16:57:14 +02:00
2018-09-03 17:23:50 +03:00
created() {
2018-11-09 01:13:34 +02:00
this.$root.getMeta().then(meta => {
2018-11-03 16:57:14 +02:00
this.announcements = meta.broadcasts;
2018-09-03 17:23:50 +03:00
});
},
2018-11-03 16:57:14 +02:00
2018-09-03 17:23:50 +03:00
methods: {
2018-11-03 16:57:14 +02:00
add() {
2018-11-14 22:00:30 +02:00
this.announcements.unshift({
2018-11-03 16:57:14 +02:00
title: '',
text: ''
});
},
2018-10-02 17:42:46 +03:00
2018-11-03 16:57:14 +02:00
remove(i) {
2018-12-02 08:28:52 +02:00
this.$root.dialog({
2018-11-05 03:40:01 +02:00
type: 'warning',
text: this.$t('_remove.are-you-sure').replace('$1', this.announcements.find((_, j) => j == i).title),
2018-11-05 03:40:01 +02:00
showCancelButton: true
2018-12-02 13:10:53 +02:00
}).then(({ canceled }) => {
if (canceled) return;
2018-11-05 03:40:01 +02:00
this.announcements = this.announcements.filter((_, j) => j !== i);
this.save(true);
2018-12-02 08:28:52 +02:00
this.$root.dialog({
2018-11-05 03:40:01 +02:00
type: 'success',
text: this.$t('_remove.removed')
2018-11-05 03:40:01 +02:00
});
});
2018-11-03 16:57:14 +02:00
},
2018-10-02 17:42:46 +03:00
2018-11-05 03:40:01 +02:00
save(silent) {
2018-11-09 01:13:34 +02:00
this.$root.api('admin/update-meta', {
2018-11-03 16:57:14 +02:00
broadcasts: this.announcements
2018-10-02 17:42:46 +03:00
}).then(() => {
2018-11-05 03:40:01 +02:00
if (!silent) {
2018-12-02 08:28:52 +02:00
this.$root.dialog({
2018-11-05 03:40:01 +02:00
type: 'success',
text: this.$t('saved')
2018-11-05 03:40:01 +02:00
});
}
2018-11-03 16:57:14 +02:00
}).catch(e => {
2018-12-02 08:28:52 +02:00
this.$root.dialog({
2018-11-05 03:32:45 +02:00
type: 'error',
text: e
});
2018-09-03 17:23:50 +03:00
});
}
}
});
</script>
<style lang="stylus" scoped>
.cdeuzmsthagexbkpofbmatmugjuvogfb
@media (min-width 500px)
padding 16px
</style>