Commit 78226917 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

FIX: check for valid type & category in add show modal

parent 46dfc62d
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
</div> </div>
</b-col> </b-col>
</b-row> </b-row>
<b-row> <b-row>
<b-col cols="3"> <b-col cols="3">
Funding category: Funding category:
...@@ -165,33 +165,54 @@ export default { ...@@ -165,33 +165,54 @@ export default {
}, },
methods: { methods: {
// create a new show and POST it to the steering API
// new shows have to at least contain a name, a slug and a short-description.
// also a valide show type and funding category have to be choosen.
// for all other categories we can use an empty array and let the user fill
// it out through the existing show manager modals, after the show is created
addShow (event) { addShow (event) {
// prevent the modal from closing automatically on click // prevent the modal from closing automatically on click
event.preventDefault() event.preventDefault()
// only try to add a new show if name and short description are filled out // 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() === '' ) { 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) // 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.') alert('Please provide at least a title and a short description for this show.')
} else { return
// as the slug is a computed property we to assign it to the new show's slug variable }
this.newShow.slug = this.temporarySlug // also the type and funding category have to be set
let uri = process.env.VUE_APP_API_STEERING_SHOWS if (this.types.findIndex(type => type.id === this.newShow.type) === -1) {
axios.post(uri, this.newShow, { // TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
withCredentials: true, alert('Please choose a type for this show.')
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token } return
}).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
})
} }
if (this.fundingcategories.findIndex(cat => cat.id === this.newShow.fundingcategory) === -1) {
// TODO: make this nicer UI-wise (red text annotations next to input fields instead of simple alert)
alert('Please choose a funding category for this show.')
return
}
// as the slug is a computed property we have to assign it to the new show's slug property
this.newShow.slug = this.temporarySlug
// ready to go, let's POST this new show
let 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
})
}, },
// delete a show by sending a DELETE to the steering API
deleteShow (event) { deleteShow (event) {
// prevent the modal from closing automatically on click // prevent the modal from closing automatically on click
event.preventDefault() event.preventDefault()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment