Ver código fonte

Unique check on Status and ContactUsSource

master
Brian Conway 2 anos atrás
pai
commit
5dd4a432bf

+ 27
- 8
src/components/admin/status/statusNew.vue Ver arquivo

@@ -89,6 +89,9 @@ export default {
89 89
       descriptionLoad: false,
90 90
     }
91 91
   },
92
+  created() {
93
+    this.getStatusList()
94
+  },
92 95
   components: {
93 96
     alert,
94 97
   },
@@ -101,7 +104,7 @@ export default {
101 104
     }
102 105
   },
103 106
   computed: {
104
-    ...mapState('status', ['status']),
107
+    ...mapState('status', ['status', 'statusList']),
105 108
   },
106 109
   methods: {
107 110
     ...mapActions('status', [
@@ -131,16 +134,32 @@ export default {
131 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 148
     validatePage: function () {
135
-      console.log('validatePage')
136 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 162
       } else {
143
-        console.log('failed')
144 163
         this.statusLoad = true
145 164
         this.descriptionLoad = true
146 165
         this.boolValidationError = true

+ 30
- 5
src/components/communication/contactUsSource.vue Ver arquivo

@@ -89,6 +89,7 @@ export default {
89 89
     alert,
90 90
   },
91 91
   mounted() {
92
+    this.getContactUsSources()
92 93
     this.clearContactUsSource()
93 94
     if (this.$route.params.id > 0) {
94 95
       console.log(this.$route.params.id)
@@ -97,7 +98,7 @@ export default {
97 98
     }
98 99
   },
99 100
   computed: {
100
-    ...mapState('contactUsSources', ['contactUsSource']),
101
+    ...mapState('contactUsSources', ['contactUsSource', 'contactUsSources']),
101 102
     checkAccess() {
102 103
       if (Log.getUser().role === 'Super Admin') {
103 104
         return true
@@ -112,6 +113,7 @@ export default {
112 113
       'saveContactUsSource',
113 114
       'updateContactUsSource',
114 115
       'clearContactUsSource',
116
+      'getContactUsSources',
115 117
     ]),
116 118
     SubmitData() {
117 119
       if (this.validatePage()) {
@@ -127,6 +129,21 @@ export default {
127 129
     Close() {
128 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 147
     requiredField: function (tfield) {
131 148
       if (tfield) {
132 149
         return true
@@ -138,10 +155,18 @@ export default {
138 155
       console.log('validatePage')
139 156
       if (this.contactUsSource.description) {
140 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 170
       } else {
146 171
         console.log('failed')
147 172
         this.descriptionLoad = true

Carregando…
Cancelar
Salvar