Publish validation fix
This commit is contained in:
parent
46953da4cc
commit
cfa9371851
3 changed files with 62 additions and 41 deletions
|
|
@ -413,32 +413,47 @@ export default {
|
|||
openPublishModal () {
|
||||
const open = () => {
|
||||
// compute if the user can ask approval
|
||||
this.$store.commit('VALIDATE_MAIN', isValid => {
|
||||
if (isValid) {
|
||||
this.publishModal = true
|
||||
this.save(false).catch((err) => {
|
||||
console.log(err)
|
||||
// check against rules in the store
|
||||
const validation = []
|
||||
const keys = Object.keys(this.$store.state.mainRules)
|
||||
keys.forEach(key => {
|
||||
let value = ''
|
||||
if (key.indexOf('contacts.') !== -1) {
|
||||
value = this.$store.state.data.contacts[key.replace('contacts.', '')]
|
||||
} else {
|
||||
value = this.$store.state.data[key]
|
||||
}
|
||||
const rules = this.$store.state.mainRules[key]
|
||||
validation.push(rules.map(r => r(value)).filter(r => r === true).length === rules.length)
|
||||
})
|
||||
validation.push(this.$store.state.data.thumbnail.location.length > 1)
|
||||
const isValid = validation.filter(v => v).length === validation.length
|
||||
if (isValid) {
|
||||
this.publishModal = true
|
||||
this.save(false).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
} else {
|
||||
this.$store.commit('ADD_ALERT', {
|
||||
color: 'error',
|
||||
text: 'Vous devez remplir tout les champs requis afin de publier'
|
||||
})
|
||||
if (this.$route.name !== 'DelegateMain') {
|
||||
this.$store.commit('ON_MAIN_READY', () => {
|
||||
return true
|
||||
})
|
||||
this.$router.push({ name: 'DelegateMain' }, () => {
|
||||
this.$store.commit('VALIDATE_MAIN')
|
||||
})
|
||||
} else {
|
||||
this.$store.commit('ADD_ALERT', {
|
||||
color: 'error',
|
||||
text: 'Vous devez remplir tout les champs requis afin de publier'
|
||||
})
|
||||
this.publishModal = false
|
||||
this.$store.commit('VALIDATE_MAIN')
|
||||
}
|
||||
this.canPublish = isValid
|
||||
})
|
||||
this.publishModal = false
|
||||
}
|
||||
this.canPublish = isValid
|
||||
}
|
||||
this.$store.state.validateMain = false
|
||||
this.$router.push({ name: 'DelegateMain' }, () => {
|
||||
this.$store.commit('ON_MAIN_READY', () => {
|
||||
open()
|
||||
return true
|
||||
})
|
||||
})
|
||||
if (this.$route.name === 'DelegateMain') {
|
||||
open()
|
||||
}
|
||||
open()
|
||||
},
|
||||
askApproval () {
|
||||
this.askingApprovalLoading = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue