Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 1 | <template> |
| 2 | <b-modal id="upload-certificate" ref="modal" @ok="onOk" @hidden="resetForm"> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 3 | <template #modal-title> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 4 | <template v-if="certificate"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 5 | {{ $t('pageCertificates.replaceCertificate') }} |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 6 | </template> |
| 7 | <template v-else> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 8 | {{ $t('pageCertificates.addNewCertificate') }} |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 9 | </template> |
| 10 | </template> |
| 11 | <b-form> |
| 12 | <!-- Replace Certificate type --> |
| 13 | <template v-if="certificate !== null"> |
| 14 | <dl class="mb-4"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 15 | <dt>{{ $t('pageCertificates.modal.certificateType') }}</dt> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 16 | <dd>{{ certificate.certificate }}</dd> |
| 17 | </dl> |
| 18 | </template> |
| 19 | |
| 20 | <!-- Add new Certificate type --> |
| 21 | <template v-else> |
| 22 | <b-form-group |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 23 | :label="$t('pageCertificates.modal.certificateType')" |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 24 | label-for="certificate-type" |
| 25 | > |
| 26 | <b-form-select |
| 27 | id="certificate-type" |
| 28 | v-model="form.certificateType" |
| 29 | :options="certificateOptions" |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 30 | :state="getValidationState(v$.form.certificateType)" |
| 31 | @input="v$.form.certificateType.$touch()" |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 32 | > |
| 33 | </b-form-select> |
| 34 | <b-form-invalid-feedback role="alert"> |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 35 | <template v-if="!v$.form.certificateType.required"> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 36 | {{ $t('global.form.fieldRequired') }} |
| 37 | </template> |
| 38 | </b-form-invalid-feedback> |
| 39 | </b-form-group> |
| 40 | </template> |
| 41 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 42 | <b-form-group :label="$t('pageCertificates.modal.certificateFile')"> |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 43 | <form-file |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 44 | id="certificate-file" |
| 45 | v-model="form.file" |
| 46 | accept=".pem" |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 47 | :state="getValidationState(v$.form.file)" |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 48 | > |
| 49 | <template #invalid> |
| 50 | <b-form-invalid-feedback role="alert"> |
| 51 | {{ $t('global.form.required') }} |
| 52 | </b-form-invalid-feedback> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 53 | </template> |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 54 | </form-file> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 55 | </b-form-group> |
| 56 | </b-form> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 57 | <template #modal-ok> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 58 | <template v-if="certificate"> |
| 59 | {{ $t('global.action.replace') }} |
| 60 | </template> |
| 61 | <template v-else> |
| 62 | {{ $t('global.action.add') }} |
| 63 | </template> |
| 64 | </template> |
Sukanya Pandey | 3835713 | 2020-12-22 13:40:59 +0530 | [diff] [blame] | 65 | <template #modal-cancel> |
| 66 | {{ $t('global.action.cancel') }} |
| 67 | </template> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 68 | </b-modal> |
| 69 | </template> |
| 70 | |
| 71 | <script> |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 72 | import { required, requiredIf } from '@vuelidate/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 73 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 74 | import { useVuelidate } from '@vuelidate/core'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 75 | |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 76 | import FormFile from '@/components/Global/FormFile'; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 77 | import { useI18n } from 'vue-i18n'; |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 78 | |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 79 | export default { |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 80 | components: { FormFile }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 81 | mixins: [VuelidateMixin], |
| 82 | props: { |
| 83 | certificate: { |
| 84 | type: Object, |
| 85 | default: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 86 | validator: (prop) => { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 87 | if (prop === null) return true; |
| 88 | return ( |
Yoshie Muranaka | efd7c88 | 2020-10-30 09:32:06 -0700 | [diff] [blame] | 89 | Object.prototype.hasOwnProperty.call(prop, 'type') && |
| 90 | Object.prototype.hasOwnProperty.call(prop, 'certificate') |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 91 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 92 | }, |
| 93 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 94 | }, |
Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 95 | setup() { |
| 96 | return { |
| 97 | v$: useVuelidate(), |
| 98 | }; |
| 99 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 100 | data() { |
| 101 | return { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 102 | $t: useI18n().t, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 103 | form: { |
| 104 | certificateType: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 105 | file: null, |
| 106 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 107 | }; |
| 108 | }, |
| 109 | computed: { |
| 110 | certificateTypes() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 111 | return this.$store.getters['certificates/availableUploadTypes']; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 112 | }, |
| 113 | certificateOptions() { |
| 114 | return this.certificateTypes.map(({ type, label }) => { |
| 115 | return { |
| 116 | text: label, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 117 | value: type, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 118 | }; |
| 119 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 120 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 121 | }, |
| 122 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 123 | certificateOptions: function (options) { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 124 | if (options.length) { |
| 125 | this.form.certificateType = options[0].value; |
| 126 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 127 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 128 | }, |
| 129 | validations() { |
| 130 | return { |
| 131 | form: { |
| 132 | certificateType: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 133 | required: requiredIf(function () { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 134 | return !this.certificate; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 135 | }), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 136 | }, |
| 137 | file: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 138 | required, |
| 139 | }, |
| 140 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 141 | }; |
| 142 | }, |
| 143 | methods: { |
| 144 | handleSubmit() { |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 145 | this.v$.$touch(); |
| 146 | if (this.v$.$invalid) return; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 147 | this.$emit('ok', { |
| 148 | addNew: !this.certificate, |
| 149 | file: this.form.file, |
| 150 | location: this.certificate ? this.certificate.location : null, |
| 151 | type: this.certificate |
| 152 | ? this.certificate.type |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 153 | : this.form.certificateType, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 154 | }); |
| 155 | this.closeModal(); |
| 156 | }, |
| 157 | closeModal() { |
| 158 | this.$nextTick(() => { |
| 159 | this.$refs.modal.hide(); |
| 160 | }); |
| 161 | }, |
| 162 | resetForm() { |
| 163 | this.form.certificateType = this.certificateOptions.length |
| 164 | ? this.certificateOptions[0].value |
| 165 | : null; |
| 166 | this.form.file = null; |
Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame^] | 167 | this.v$.$reset(); |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 168 | }, |
| 169 | onOk(bvModalEvt) { |
| 170 | // prevent modal close |
| 171 | bvModalEvt.preventDefault(); |
| 172 | this.handleSubmit(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 173 | }, |
| 174 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 175 | }; |
| 176 | </script> |