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

Validate email and website meta data for shows

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