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