Newer
Older
<template>
<b-row>

jackie / Andrea Ida Malkah Klaura
committed
<b-col>
<h3>{{ title }}</h3>
</b-col>

jackie / Andrea Ida Malkah Klaura
committed
<b-col
v-if="shows.length > 10"
align="right"
>
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
<b-input-group prepend="Select show:">
<b-form-input
v-model="inputSelector"
list="list-of-shows"
autocomplete="off"
@keypress="keypressed"
/>
<b-input-group-append>
<b-button
variant="success"
:disabled="disabledOk"
@click="confirmSelector"
>
<b-icon-check />
</b-button>
<b-button
variant="danger"
:disabled="disabledReset"
@click="resetSelector"
>
<b-icon-x />
</b-button>
</b-input-group-append>
</b-input-group>
<datalist id="list-of-shows">
<option
v-for="show in shows"
:key="show.id"
>
{{ show.name }} (ID: {{ show.id }})
</option>
</datalist>
</b-col>
<b-col

jackie / Andrea Ida Malkah Klaura
committed
v-else
align="right"
>
<b-dropdown
id="ddshows"
variant="info"
>
<b-dropdown-item
v-for="(show, index) in shows"
:key="show.id"
@click="switchShow(index)"
>
{{ show.name }}
</b-dropdown-item>
</b-dropdown>

jackie / Andrea Ida Malkah Klaura
committed
<b-button
v-if="isSuperuser"
v-b-popover.hover.top="'Add a new show'"
variant="info"
@click="$refs.addShowModal.openModal()"
>
+
</b-button>
<addShowModal
ref="addShowModal"
:callback="newShowAdded"
/>
</b-col>
</b-row>
</template>
<script>
import { mapGetters } from 'vuex'
import { BIconCheck, BIconX } from 'bootstrap-vue'

jackie / Andrea Ida Malkah Klaura
committed
import modalAddShow from './shows/AddShowModal.vue'
export default {
components: {
BIconCheck,
BIconX,

jackie / Andrea Ida Malkah Klaura
committed
'addShowModal': modalAddShow,
props: {
title: { type: String, default: 'Unlabeled component title' },
callback: { type: Function, default: null }
},
data () {
return {
inputSelector: '',
}
},
computed: {

Richard Blechinger
committed
isSuperuser () {
const user = this.$store.state.auth.user.steeringUser;
return user && user.is_superuser;
},
loaded () {
return {
shows: this.$store.state.shows.loaded.shows,

jackie / Andrea Ida Malkah Klaura
committed
types: this.$store.state.shows.loaded.types,
fundingcategories: this.$store.state.shows.loaded.fundingcategories,
}
},

jackie / Andrea Ida Malkah Klaura
committed
disabledOk () { return ! this.isValidSelector() },
disabledReset () { return this.inputSelector.length > 0 ? false : true },
...mapGetters({
shows: 'shows/shows',
selectedShow: 'shows/selectedShow',
})
},

jackie / Andrea Ida Malkah Klaura
committed
created () {
if (!this.loaded.types) {
this.$store.dispatch('shows/fetchMetaArray', {property: 'types', onlyActive: true})
}
if (!this.loaded.fundingcategories) {
this.$store.dispatch('shows/fetchMetaArray', {property: 'fundingcategories', onlyActive: true})
}
},
methods: {
switchShow: function (index) {
this.$store.commit('shows/switchShow', index)
this.updateInputSelector()
if (this.callback) { this.callback() }
},

jackie / Andrea Ida Malkah Klaura
committed
newShowAdded () {
this.updateInputSelector()
if (this.callback) { this.callback() }
},
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
updateInputSelector () {
this.inputSelector = this.selectedShow.name + ' (ID: ' + this.selectedShow.id + ')'
},
isValidSelector () {
let pattern = /^.*\(ID: \d+\)$/
if (pattern.test(this.inputSelector)) {
if ( this.shows.findIndex(s => s.id == this.getSelectorId()) >= 0 ) {
return true
}
}
return false
},
getSelectorId () {
let s = this.inputSelector.split('(ID: ')
return s[s.length-1].slice(0,-1)
},
keypressed (k) {
if (k.key === 'Enter') {
if (this.isValidSelector()) {
this.switchShow(this.shows.findIndex(s => s.id == this.getSelectorId()))
}
}
},
confirmSelector () {
this.keypressed({key: 'Enter'})
},
resetSelector () {
this.inputSelector = ''
},
}
}
</script>