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

FIX: category & logo editing

parent c22e8cfb
...@@ -685,21 +685,34 @@ export default { ...@@ -685,21 +685,34 @@ export default {
} }
}, },
saveCategories (event) { saveCategories (event) {
this.$log.debug('saveCategories', this.array, this.show.category)
if (this.array.length !== this.show.category.length || !this.array.every((value, index) => value === this.show.category[index])) { if (this.array.length !== this.show.category.length || !this.array.every((value, index) => value === this.show.category[index])) {
event.preventDefault() event.preventDefault()
this.backuparray = this.show.category let updatedShow = {
this.show.category = this.array name: this.show.name,
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { slug: this.show.slug,
short_description: this.show.short_description,
fundingcategory: this.show.fundingcategory,
type: this.show.type,
hosts: this.show.hosts,
language: this.show.language,
musicfocus: this.show.musicfocus,
owners: this.show.owners,
topic: this.show.topic,
}
updatedShow.category = this.array
let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/'
axios.put(uri, updatedShow, {
withCredentials: true, withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token } headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
}).then(() => { }).then(() => {
this.$parent.shows[this.$parent.currentShow].category = updatedShow.category
this.$parent.getCategories() this.$parent.getCategories()
this.$refs.modalShowCategories.hide() this.$refs.modalShowCategories.hide()
}).catch(error => { }).catch(error => {
this.show.category = this.backuparray this.$log.error(error.response.status + ' ' + error.response.statusText)
console.log('Error:') this.$log.error(error.response)
console.log(error) alert('Error: could not save categories. See console for details.')
alert('Error: could not save the new show information')
}) })
} }
}, },
...@@ -779,6 +792,7 @@ export default { ...@@ -779,6 +792,7 @@ export default {
}) })
} }
}, },
saveLogo (event) { saveLogo (event) {
event.preventDefault() event.preventDefault()
if (this.file === null) { alert('Please provide a file to upload') } if (this.file === null) { alert('Please provide a file to upload') }
...@@ -786,49 +800,69 @@ export default { ...@@ -786,49 +800,69 @@ export default {
else { else {
let formData = new FormData() let formData = new FormData()
this.backupstring = this.string this.backupstring = this.string
// work in progress: // these propoerties have to be sent always (and they must not be null)
// as it seems we have to use multipart webform data and add all items in order
// but this is still not working
// have to find out what exact format and encoding is needed to upload a show with files included
formData.append('name', this.show.name) formData.append('name', this.show.name)
formData.append('slug', this.show.slug) formData.append('slug', this.show.slug)
formData.append('image', this.show.image)
formData.append('logo', this.file, this.file.name);
formData.append('short_description', this.show.short_description) formData.append('short_description', this.show.short_description)
formData.append('description', this.show.description)
formData.append('email', this.show.email)
formData.append('website', this.show.website)
formData.append('type', this.show.type) formData.append('type', this.show.type)
formData.append('fundingcategory', this.show.fundingcategory) formData.append('fundingcategory', this.show.fundingcategory)
formData.append('predecessor', this.show.predecessor) // now we append the new logo file
formData.append('cba_series_id', this.show.cba_series_id) formData.append('logo', this.file, this.file.name)
formData.append('fallback_id', this.show.fallback_id) // ok then, let's submit it
formData.append('category', this.show.category) let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/'
formData.append('host', this.show.host) axios.put(uri, formData, {
formData.append('language', this.show.language)
formData.append('topic', this.show.topic)
formData.append('musicfocus', this.show.musicfocus)
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', formData, {
withCredentials: true, withCredentials: true,
headers: { headers: {
'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token, 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token,
'Content-Type': 'multipart/form-data' 'Content-Type': 'multipart/form-data',
} }
}).then(() => { }).then(() => {
//this.$parent.getHosts() this.$parent.loadAndSwitch(this.$parent.currentShowID)
this.$refs.modalLogo.hide() this.$refs.modalLogo.hide()
}).catch(error => { }).catch(error => {
this.file = null this.file = null
this.string = this.backupstring this.string = this.backupstring
console.log('Error:') this.$log.error(error.response.status + ' ' + error.response.statusText)
console.log(error) this.$log.error(error.response)
alert('Error: could not save the new logo') alert('Error: could not set new logo. See console for details.')
}) })
} }
}, },
saveImage (event) { saveImage (event) {
alert('Not yet implemented') event.preventDefault()
console.log(event) if (this.file === null) { alert('Please provide a file to upload') }
else if (this.file.type !== 'image/jpeg' && this.file.type !== 'image/png') { alert('Please provide a valid image file (JPEG or PNG)') }
else {
let formData = new FormData()
this.backupstring = this.string
// these properties have to be sent always (and they must not be null)
formData.append('name', this.show.name)
formData.append('slug', this.show.slug)
formData.append('short_description', this.show.short_description)
formData.append('type', this.show.type)
formData.append('fundingcategory', this.show.fundingcategory)
// now we append the new image file
formData.append('image', this.file, this.file.name)
// ok then, let's submit it
let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/'
axios.put(uri, formData, {
withCredentials: true,
headers: {
'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token,
'Content-Type': 'multipart/form-data',
}
}).then(() => {
this.$parent.loadAndSwitch(this.$parent.currentShowID)
this.$refs.modalImage.hide()
}).catch(error => {
this.file = null
this.string = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response)
alert('Error: could set new image. See console for details.')
})
}
}, },
/* /*
Functions to activate modals Functions to activate modals
...@@ -978,7 +1012,7 @@ export default { ...@@ -978,7 +1012,7 @@ export default {
if (this.show.logo === null) { this.string = '' } if (this.show.logo === null) { this.string = '' }
else { this.string = this.show.logo } else { this.string = this.show.logo }
this.file = null this.file = null
this.$refs.fileinputLogo.reset() //this.$refs.fileinputLogo.reset()
this.$refs.modalLogo.show() this.$refs.modalLogo.show()
}, },
showImage () { showImage () {
......
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