Newer
Older
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
<template>
<div>
<b-modal
ref="modalAddShow"
title="Create a new show"
size="lg"
@ok="addShow"
>
<b-container fluid>
<b-row>
<b-col cols="2">
Name of the show:
</b-col>
<b-col cols="10">
<b-form-input
v-model="newShow.name"
type="text"
placeholder="Enter a title for this new show"
/>
</b-col>
<b-col cols="2" />
<b-col cols="10">
<small class="slug">Slug: {{ temporarySlug }}</small>
</b-col>
</b-row>
<br>
<b-row>
<b-col cols="2">
Short description:
</b-col>
<b-col cols="10">
<b-form-input
v-model="newShow.short_description"
type="text"
placeholder="Enter a short description for this show"
/>
</b-col>
</b-row>
</b-container>
</b-modal>
</div>
</template>
<script>
import axios from 'axios'
import slugify from '../mixins/slugify.js'
export default {
mixins: [ slugify ],
data () {
return {
newShow: {
name: "",
slug: "",
short_description: "",
type: 1,
fundingcategory: 1,
category: [],
hosts: [],
owners: [],
language: [],
topic: [],
musicfocus: []
}
}
},
computed: {
temporarySlug: function () {
return this.slug(this.newShow.name)
}
},
methods: {
addShow (event) {
// prevent the modal from closing automatically on click
event.preventDefault()
// only try to add a new show if name and short description are filled out
if (this.newShow.name.trim() === '' || this.newShow.short_description.trim() === '' ) {
// TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
alert('Please provide at least a title and a short description for this show.')
} else {
// as the slug is a computed property we to assign it to the new show's slug variable
this.newShow.slug = this.temporarySlug
var uri = process.env.VUE_APP_API_STEERING_SHOWS
axios.post(uri, this.newShow, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
}).then(response => {
// everything was fine, we can close the modal now
this.$refs.modalAddShow.hide()
this.$parent.loadAndSwitch(response.data.id)
}).catch(error => {
this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response)
alert('Error: could not add new show. See console for details.')
// and we leave the modal open, so no call to its .hide function here
})
}
},
showModalAddShow () {
this.newShow.name = ''
this.newShow.slug = ''
this.newShow.short_description = ''
// TODO:
// - load types & funding categories
this.$refs.modalAddShow.show()
}
}
}
</script>
<style scoped>
.slug {
color: gray;
}
</style>