diff --git a/client/src/components/SchemaSubForm.vue b/client/src/components/SchemaSubForm.vue index c3404fe..1cde5c3 100644 --- a/client/src/components/SchemaSubForm.vue +++ b/client/src/components/SchemaSubForm.vue @@ -585,7 +585,6 @@ export default { } }, mounted () { - console.log('schemainstance', this.schemainstance) // this.oldFiles = this.schemainstance.data[0].Fileattachment.length }, created () {} diff --git a/client/src/components/SchemaView.vue b/client/src/components/SchemaView.vue index 4bd5e25..39353f4 100644 --- a/client/src/components/SchemaView.vue +++ b/client/src/components/SchemaView.vue @@ -713,8 +713,13 @@ export default { this.validErr = [] let allcheck = [] this.bLoading = true + let currentStageP = this.$route.params.stateid + let currentStateP = this.flowzData.processList[currentStageP] + let permission = {} + permission = currentStateP.permission + console.log(permission) for (let dobj of this.formSchemaInstance.data) { - let flag = this.checkValidation(dobj, this.entity) + let flag = this.checkValidation(dobj, this.entity, permission) allcheck.push(flag) } this.check = _.indexOf(allcheck, false) @@ -762,6 +767,10 @@ export default { }, saveInstanceData () { + let currentStageP = this.$route.params.stateid + let currentStateP = this.flowzData.processList[currentStageP] + let permission = {} + permission = currentStateP.permission let currentStateId = this.$route.params.stateid if (this.schema.hasOwnProperty('emailSchema')) { if (this.schema.emailSchema.action === true) { @@ -784,7 +793,7 @@ export default { this.validErr = [] let allcheck = [] for (let dobj of obj.data) { - let flag = this.checkValidation(dobj, this.entity) + let flag = this.checkValidation(dobj, this.entity, permission) allcheck.push(flag) } this.check = _.indexOf(allcheck, false) @@ -878,7 +887,7 @@ export default { this.validErr = [] let allcheck = [] for (let dobj of obj.data) { - let flag = this.checkValidation(dobj, this.entity) + let flag = this.checkValidation(dobj, this.entity, permission) allcheck.push(flag) } this.check = _.indexOf(allcheck, false) @@ -894,7 +903,7 @@ export default { this.validErr = [] let allcheck = [] for (let dobj of obj.data) { - let flag = this.checkValidation(dobj, this.entity) + let flag = this.checkValidation(dobj, this.entity, permission) allcheck.push(flag) } this.check = _.indexOf(allcheck, false) @@ -960,94 +969,185 @@ export default { } }) }, - checkValidation (data, ent) { + checkValidation (data, ent, permission) { let self = this for (let v of ent) { - if (v.customtype) { - for (let d of data[v.name]) { - self.validFlag = self.checkValidation(d, v.entity[0].entity) - } - } else { - if (!v.property.optional) { - if (data[v.name] === '') { - self.validErr.push({name: v.name, errmsg: 'Field is required.'}) - self.validFlag = false - } else if (Array.isArray(data[v.name]) && data[v.name].length === 0) { - self.validErr.push({name: v.name, errmsg: 'File is required.'}) - self.validFlag = false - } else if (v.type === 'text') { - if (v.property.regEx !== '') { - let patt0 = v.property.regEx - let res0 = patt0.test(data[v.name]) - if (!res0) { - self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) - self.validFlag = false - } - } else if (v.property.max !== 0) { - if (data[v.name].length > v.property.max) { - self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'}) - self.validFlag = false - } - } else if (v.property.allowedValue.length > 0) { - let exist = _.indexOf(v.property.allowedValue, data[v.name]) - if (exist === -1) { - self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) - self.validFlag = false - } + if (permission[v.name] !== undefined) { + if (permission[v.name].write || permission[v.name].read) { + if (v.customtype) { + for (let d of data[v.name]) { + self.validFlag = self.checkValidation(d, v.entity[0].entity, permission) } - } else if (v.type === 'email' && data[v.name] !== '') { - let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx) - let res1 = patt1.test(data[v.name]) - if (!res1) { - self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) - self.validFlag = false - } else if (v.property.allowedValue.length > 0) { - let exist = _.indexOf(v.property.allowedValue, data[v.name]) - if (exist === -1) { - self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) + } else { + if (!v.property.optional) { + if (data[v.name] === '') { + self.validErr.push({name: v.name, errmsg: 'Field is required.'}) self.validFlag = false - } - } - } else if (v.type === 'phone') { - let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx) - let res2 = patt2.test(data[v.name]) - if (!res2) { - self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'}) - self.validFlag = false - } else if (v.property.allowedValue.length > 0) { - let exist = _.indexOf(v.property.allowedValue, data[v.name]) - if (exist === -1) { - self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'}) + } else if (Array.isArray(data[v.name]) && data[v.name].length === 0) { + self.validErr.push({name: v.name, errmsg: 'File is required.'}) self.validFlag = false + } else if (v.type === 'text') { + if (v.property.regEx !== '') { + let patt0 = v.property.regEx + let res0 = patt0.test(data[v.name]) + if (!res0) { + self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) + self.validFlag = false + } + } else if (v.property.max !== 0) { + if (data[v.name].length > v.property.max) { + self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'}) + self.validFlag = false + } + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'email' && data[v.name] !== '') { + let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx) + let res1 = patt1.test(data[v.name]) + if (!res1) { + self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) + self.validFlag = false + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'phone') { + let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx) + let res2 = patt2.test(data[v.name]) + if (!res2) { + self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'}) + self.validFlag = false + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'number') { + if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'date') { + if (v.property.mindate !== '' && v.property.maxdate !== '') { + if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) { + self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate}) + self.validFlag = false + } + } else if (v.property.mindate !== '') { + if (data[v.name] < v.property.mindate) { + self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'}) + self.validFlag = false + } + } else if (v.property.maxdate !== '') { + if (data[v.name] > v.property.maxdate) { + self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'}) + self.validFlag = false + } + } } } - } else if (v.type === 'number') { - if (v.property.allowedValue.length > 0) { - let exist = _.indexOf(v.property.allowedValue, data[v.name]) - if (exist === -1) { - self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'}) - self.validFlag = false - } + } + } + } else { + if (v.customtype) { + for (let d of data[v.name]) { + self.validFlag = self.checkValidation(d, v.entity[0].entity, permission) } - } else if (v.type === 'date') { - if (v.property.mindate !== '' && v.property.maxdate !== '') { - if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) { - self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate}) + } else { + if (!v.property.optional) { + if (data[v.name] === '') { + self.validErr.push({name: v.name, errmsg: 'Field is required.'}) self.validFlag = false - } - } else if (v.property.mindate !== '') { - if (data[v.name] < v.property.mindate) { - self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'}) - self.validFlag = false - } - } else if (v.property.maxdate !== '') { - if (data[v.name] > v.property.maxdate) { - self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'}) + } else if (Array.isArray(data[v.name]) && data[v.name].length === 0) { + self.validErr.push({name: v.name, errmsg: 'File is required.'}) self.validFlag = false + } else if (v.type === 'text') { + if (v.property.regEx !== '') { + let patt0 = v.property.regEx + let res0 = patt0.test(data[v.name]) + if (!res0) { + self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) + self.validFlag = false + } + } else if (v.property.max !== 0) { + if (data[v.name].length > v.property.max) { + self.validErr.push({name: v.name, errmsg: 'max ' + v.property.max + ' characters allowed.'}) + self.validFlag = false + } + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'email' && data[v.name] !== '') { + let patt1 = (v.property.regEx === '') ? new RegExp('[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,3}$') : new RegExp(v.property.regEx) + let res1 = patt1.test(data[v.name]) + if (!res1) { + self.validErr.push({name: v.name, errmsg: 'Invalid Email.'}) + self.validFlag = false + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Email, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'phone') { + let patt2 = (v.property.regEx === '') ? new RegExp('^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$') : new RegExp(v.property.regEx) + let res2 = patt2.test(data[v.name]) + if (!res2) { + self.validErr.push({name: v.name, errmsg: 'Invalid Phone.'}) + self.validFlag = false + } else if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Phone, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'number') { + if (v.property.allowedValue.length > 0) { + let exist = _.indexOf(v.property.allowedValue, data[v.name]) + if (exist === -1) { + self.validErr.push({name: v.name, errmsg: 'Not Allowed Number, Please select allow one.'}) + self.validFlag = false + } + } + } else if (v.type === 'date') { + if (v.property.mindate !== '' && v.property.maxdate !== '') { + if (data[v.name] < v.property.mindate && data[v.name] > v.property.maxdate) { + self.validErr.push({name: v.name, errmsg: 'Date must in between ' + v.property.mindate + ' and ' + v.property.maxdate}) + self.validFlag = false + } + } else if (v.property.mindate !== '') { + if (data[v.name] < v.property.mindate) { + self.validErr.push({name: v.name, errmsg: 'Date must be greater than or equal ' + v.property.mindate + '.'}) + self.validFlag = false + } + } else if (v.property.maxdate !== '') { + if (data[v.name] > v.property.maxdate) { + self.validErr.push({name: v.name, errmsg: 'Date must be less than or equal ' + v.property.mindate + '.'}) + self.validFlag = false + } + } } } } - } } } return self.validFlag