Browse Source

Unique check on Status and ContactUsSource

master
Brian Conway 2 years ago
parent
commit
5dd4a432bf

+ 27
- 8
src/components/admin/status/statusNew.vue View File

89
       descriptionLoad: false,
89
       descriptionLoad: false,
90
     }
90
     }
91
   },
91
   },
92
+  created() {
93
+    this.getStatusList()
94
+  },
92
   components: {
95
   components: {
93
     alert,
96
     alert,
94
   },
97
   },
101
     }
104
     }
102
   },
105
   },
103
   computed: {
106
   computed: {
104
-    ...mapState('status', ['status']),
107
+    ...mapState('status', ['status', 'statusList']),
105
   },
108
   },
106
   methods: {
109
   methods: {
107
     ...mapActions('status', [
110
     ...mapActions('status', [
131
         return false
134
         return false
132
       }
135
       }
133
     },
136
     },
137
+    uniqueStatusCode: function (tfield) {
138
+      if (tfield) {
139
+        if (this.statusList.find((i) => i.code === this.status.code)) {
140
+          return false
141
+        } else {
142
+          return true
143
+        }
144
+      } else {
145
+        return false
146
+      }
147
+    },
134
     validatePage: function () {
148
     validatePage: function () {
135
-      console.log('validatePage')
136
       if (this.status.code && this.status.description) {
149
       if (this.status.code && this.status.description) {
137
-        console.log('passed')
138
-        this.errorOccurred = ''
139
-        this.errorMessage = ''
140
-        this.boolValidationError = false
141
-        return true
150
+        if (!this.uniqueStatusCode(this.status.code)) {
151
+          this.statusLoad = true
152
+          this.descriptionLoad = true
153
+          this.boolValidationError = true
154
+          this.errorOccurred = 'ERROR'
155
+          this.errorMessage = 'Status Code already recorded!'
156
+        } else {
157
+          this.errorOccurred = ''
158
+          this.errorMessage = ''
159
+          this.boolValidationError = false
160
+          return true
161
+        }
142
       } else {
162
       } else {
143
-        console.log('failed')
144
         this.statusLoad = true
163
         this.statusLoad = true
145
         this.descriptionLoad = true
164
         this.descriptionLoad = true
146
         this.boolValidationError = true
165
         this.boolValidationError = true

+ 30
- 5
src/components/communication/contactUsSource.vue View File

89
     alert,
89
     alert,
90
   },
90
   },
91
   mounted() {
91
   mounted() {
92
+    this.getContactUsSources()
92
     this.clearContactUsSource()
93
     this.clearContactUsSource()
93
     if (this.$route.params.id > 0) {
94
     if (this.$route.params.id > 0) {
94
       console.log(this.$route.params.id)
95
       console.log(this.$route.params.id)
97
     }
98
     }
98
   },
99
   },
99
   computed: {
100
   computed: {
100
-    ...mapState('contactUsSources', ['contactUsSource']),
101
+    ...mapState('contactUsSources', ['contactUsSource', 'contactUsSources']),
101
     checkAccess() {
102
     checkAccess() {
102
       if (Log.getUser().role === 'Super Admin') {
103
       if (Log.getUser().role === 'Super Admin') {
103
         return true
104
         return true
112
       'saveContactUsSource',
113
       'saveContactUsSource',
113
       'updateContactUsSource',
114
       'updateContactUsSource',
114
       'clearContactUsSource',
115
       'clearContactUsSource',
116
+      'getContactUsSources',
115
     ]),
117
     ]),
116
     SubmitData() {
118
     SubmitData() {
117
       if (this.validatePage()) {
119
       if (this.validatePage()) {
127
     Close() {
129
     Close() {
128
       this.$router.push('/contactUsSource/list')
130
       this.$router.push('/contactUsSource/list')
129
     },
131
     },
132
+    uniqueSource: function (tfield) {
133
+      if (tfield) {
134
+        if (
135
+          this.contactUsSources.find(
136
+            (i) => i.description === this.contactUsSource.description,
137
+          )
138
+        ) {
139
+          return false
140
+        } else {
141
+          return true
142
+        }
143
+      } else {
144
+        return false
145
+      }
146
+    },
130
     requiredField: function (tfield) {
147
     requiredField: function (tfield) {
131
       if (tfield) {
148
       if (tfield) {
132
         return true
149
         return true
138
       console.log('validatePage')
155
       console.log('validatePage')
139
       if (this.contactUsSource.description) {
156
       if (this.contactUsSource.description) {
140
         console.log('passed')
157
         console.log('passed')
141
-        this.errorOccurred = ''
142
-        this.errorMessage = ''
143
-        this.boolValidationError = false
144
-        return true
158
+        if (!this.uniqueSource(this.contactUsSource.description)) {
159
+          this.statusLoad = true
160
+          this.descriptionLoad = true
161
+          this.boolValidationError = true
162
+          this.errorOccurred = 'ERROR'
163
+          this.errorMessage = 'Status Code already recorded!'
164
+        } else {
165
+          this.errorOccurred = ''
166
+          this.errorMessage = ''
167
+          this.boolValidationError = false
168
+          return true
169
+        }
145
       } else {
170
       } else {
146
         console.log('failed')
171
         console.log('failed')
147
         this.descriptionLoad = true
172
         this.descriptionLoad = true

Loading…
Cancel
Save