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

modal for add show now uses store

parent c73df362
......@@ -85,9 +85,9 @@
</template>
<script>
import axios from 'axios'
import slugify from '../mixins/slugify.js'
import showUpdates from '../mixins/showUpdates.js'
import { mapGetters } from 'vuex'
export default {
mixins: [ slugify, showUpdates ],
......@@ -106,19 +106,12 @@ export default {
topic: [],
musicfocus: [],
},
show: null,
loaded: {
types: false,
fundingcategories: false,
users: false,
},
types: [],
fundingcategories: [],
users: [],
}
},
computed: {
loaded () { return this.$store.state.shows.loaded },
temporarySlug: function () {
return this.slugify(this.newShow.name)
},
......@@ -144,6 +137,12 @@ export default {
}
return options
},
...mapGetters({
types: 'shows/types',
fundingcategories: 'shows/fundingcategories',
users: 'auth/users',
})
},
methods: {
......@@ -177,30 +176,20 @@ export default {
// 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
let modal = this.$refs.modalAddShow
this.$store.dispatch('shows/submitShow', {
show: this.newShow,
callback: () => {
modal.hide()
}
})
},
// clear and fetch modal data and open the modal to add new shows
showModalAddShow () {
openModal () {
this.newShow.name = ''
this.newShow.slug = ''
this.newShow.short_description = ''
this.loadTypes()
this.loadFundingCategories()
this.$refs.modalAddShow.show()
},
}
......
......@@ -11,7 +11,7 @@
v-if="$parent.user.steeringUser.is_superuser"
v-b-popover.hover.top="'Add a new show'"
variant="info"
@click="$refs.appModalSuperuser.showModalAddShow()"
@click="$refs.addShowModal.openModal()"
>
+
</b-button>
......@@ -61,8 +61,8 @@
:show="shows[currentShow]"
:show-aggregate="current"
/>
<app-modalSuperuser
ref="appModalSuperuser"
<addShowModal
ref="addShowModal"
/>
<app-modalPlaylist
ref="appModalPlaylist"
......@@ -298,7 +298,7 @@ import showMetaArrays from './ShowMetaArrays.vue'
import showMetaOwners from './ShowMetaOwners.vue'
import modalNotes from './ShowManagerModalNotes.vue'
import modalShow from './ShowManagerModalShow.vue'
import modalSuperuser from './ShowManagerModalSuperuser.vue'
import modalAddShow from './AddShowModal.vue'
import modalPlaylist from './ShowManagerModalPlaylist.vue'
import timeslotSort from '../mixins/timeslotSort'
import prettyDate from '../mixins/prettyDate'
......@@ -311,8 +311,8 @@ export default {
components: {
'app-modalNotes': modalNotes,
'app-modalShow': modalShow,
'app-modalSuperuser': modalSuperuser,
'app-modalPlaylist': modalPlaylist,
'addShowModal': modalAddShow,
'show-jumbotron': showJumbotron,
'show-metaArrays': showMetaArrays,
'show-metaSimpleTypes': showMetaSimpleTypes,
......
......@@ -85,6 +85,10 @@ const mutations = {
setShows(state, shows) {
state.shows = shows
},
addShow (state, show) {
state.shows.push(show)
},
setTimeslots(state, slots) {
state.timeslots = slots
},
......@@ -187,6 +191,20 @@ const actions = {
})
},
submitShow (ctx, data) {
let uri = process.env.VUE_APP_API_STEERING_SHOWS
axios.post(uri, data.show , {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + ctx.rootState.auth.user.access_token }
}).then(response => {
ctx.commit('addShow', response.data)
if (data && typeof(data.callback) === 'function') { data.callback(response) }
}).catch(error => {
handleApiError(this, error, 'could not add new show')
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
})
},
updateShow (ctx, data) {
ctx.commit('loading', 'shows')
let uri = process.env.VUE_APP_API_STEERING_SHOWS + data.id + '/'
......
Markdown is supported
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