Commit 5c4ffcce authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Validate email and website meta data for shows

parent c67f4b29
...@@ -267,7 +267,7 @@ export default { ...@@ -267,7 +267,7 @@ export default {
if (!item || type !== 'row') { if (!item || type !== 'row') {
return ''; return '';
} }
return item.id === this.timeslot.id return item.id === this.timeslot.id
? 'table-info' ? 'table-info'
: '' : ''
......
...@@ -125,34 +125,58 @@ ...@@ -125,34 +125,58 @@
</b-col> </b-col>
</b-row> </b-row>
<!-- TODO: use b-form outside the b-form-input, so that
simple input validation works automagically -->
<b-modal <b-modal
ref="modalEmail" ref="modalEmail"
title="E-Mail" title="E-Mail"
size="lg" size="lg"
@ok="saveEmail" @ok="(modalEvt) => { modalEvt.preventDefault(); saveEmail() }"
> >
<b-form-input <form
v-model="string" ref="emailForm"
type="email" @submit.stop.prevent="saveEmail"
placeholder="Put a contact address of your show here" >
/> <b-form-group
:state="emailState"
label="Name"
label-for="show-email"
invalid-feedback="Please enter a valid email address"
>
<b-form-input
id="show-email"
v-model="email"
type="email"
:state="emailState"
placeholder="Put a contact address of your show here"
/>
</b-form-group>
</form>
</b-modal> </b-modal>
<!-- TODO: use b-form outside the b-form-input, so that
simple input validation works automagically -->
<b-modal <b-modal
ref="modalWebsite" ref="modalWebsite"
title="Website" title="Website"
size="lg" size="lg"
@ok="saveWebsite" @ok="(modalEvt) => { modalEvt.preventDefault(); saveWebsite() }"
> >
<b-form-input <form
v-model="string" ref="urlForm"
type="url" @submit.stop.prevent="saveWebsite"
placeholder="Put the website of your show here" >
/> <b-form-group
:state="urlState"
label="Name"
label-for="show-url"
invalid-feedback="Please enter a valid URL"
>
<b-form-input
id="show-url"
v-model="url"
type="url"
:state="urlState"
placeholder="Put the website of your show here"
/>
</b-form-group>
</form>
</b-modal> </b-modal>
<b-modal <b-modal
...@@ -243,7 +267,10 @@ export default { ...@@ -243,7 +267,10 @@ export default {
data () { data () {
return { return {
string: '', email: '',
url: '',
emailState: null,
urlState: null,
id: 0, id: 0,
} }
}, },
...@@ -332,14 +359,14 @@ export default { ...@@ -332,14 +359,14 @@ export default {
}, },
methods: { methods: {
openModalEmail () { openModalEmail () {
if (this.selectedShow.email !== null) { this.string = this.selectedShow.email } if (this.selectedShow.email !== null) { this.email = this.selectedShow.email }
else { this.string = '' } else { this.email = '' }
this.$refs.modalEmail.show() this.$refs.modalEmail.show()
}, },
openModalWebsite() { openModalWebsite() {
if (this.selectedShow.website !== null) { this.string = this.selectedShow.website } if (this.selectedShow.website !== null) { this.url = this.selectedShow.website }
else { this.string = '' } else { this.url = '' }
this.$refs.modalWebsite.show() this.$refs.modalWebsite.show()
}, },
...@@ -367,26 +394,49 @@ export default { ...@@ -367,26 +394,49 @@ export default {
this.$refs.modalType.show() this.$refs.modalType.show()
}, },
saveProperty (property, value, modal, event) { saveProperty (property, value, modal) {
if (value !== this.selectedShow[property]) { if (value !== this.selectedShow[property]) {
if (event) { event.preventDefault() }
this.$store.dispatch('shows/updateProperty', { this.$store.dispatch('shows/updateProperty', {
id: this.selectedShow.id, id: this.selectedShow.id,
property: property, property: property,
value: value, value: value,
callback: () => { callback: () => {
modal.hide() modal.hide()
},
callbackCancel: (error) => {
if (error.data.email) {
this.emailState = false;
}
if (error.data.website) {
this.urlState = false;
}
} }
}) })
} }
}, },
saveEmail (event) { saveEmail () {
this.saveProperty('email', this.string, this.$refs.modalEmail, event) const valid = this.$refs.emailForm.checkValidity();
console.log(valid);
this.emailState = valid;
if (!valid) {
return;
}
this.saveProperty('email', this.email, this.$refs.modalEmail)
}, },
saveWebsite (event) { saveWebsite () {
this.saveProperty('website', this.string, this.$refs.modalWebsite, event) const valid = this.$refs.urlForm.checkValidity();
this.urlState = valid;
if (!valid) {
return;
}
this.saveProperty('website', this.url, this.$refs.modalWebsite)
}, },
saveCBAid (event) { saveCBAid (event) {
......
...@@ -367,8 +367,7 @@ const actions = { ...@@ -367,8 +367,7 @@ const actions = {
}).then(response => { }).then(response => {
if (data && typeof(data.callback) === 'function') { data.callback(response) } if (data && typeof(data.callback) === 'function') { data.callback(response) }
}).catch(error => { }).catch(error => {
handleApiError(this, error, 'could not update show') if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel(error.response) }
if (data && typeof(data.callbackCancel) === 'function') { data.callbackCancel() }
}) })
}, },
...@@ -384,7 +383,11 @@ const actions = { ...@@ -384,7 +383,11 @@ const actions = {
property: data.property, property: data.property,
value: data.value value: data.value
}) })
if (typeof(data.callback) === 'function') { data.callback() } if (typeof(data.callback) === 'function') { data.callback() }
},
callbackCancel: error => {
if (typeof(data.callbackCancel) === 'function') { data.callbackCancel(error) }
} }
}) })
}, },
......
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