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