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"> |
| 5 | {{ $t('pageSslCertificates.replaceCertificate') }} |
| 6 | </template> |
| 7 | <template v-else> |
| 8 | {{ $t('pageSslCertificates.addNewCertificate') }} |
| 9 | </template> |
| 10 | </template> |
| 11 | <b-form> |
| 12 | <!-- Replace Certificate type --> |
| 13 | <template v-if="certificate !== null"> |
| 14 | <dl class="mb-4"> |
| 15 | <dt>{{ $t('pageSslCertificates.modal.certificateType') }}</dt> |
| 16 | <dd>{{ certificate.certificate }}</dd> |
| 17 | </dl> |
| 18 | </template> |
| 19 | |
| 20 | <!-- Add new Certificate type --> |
| 21 | <template v-else> |
| 22 | <b-form-group |
| 23 | :label="$t('pageSslCertificates.modal.certificateType')" |
| 24 | label-for="certificate-type" |
| 25 | > |
| 26 | <b-form-select |
| 27 | id="certificate-type" |
| 28 | v-model="form.certificateType" |
| 29 | :options="certificateOptions" |
| 30 | :state="getValidationState($v.form.certificateType)" |
| 31 | @input="$v.form.certificateType.$touch()" |
| 32 | > |
| 33 | </b-form-select> |
| 34 | <b-form-invalid-feedback role="alert"> |
| 35 | <template v-if="!$v.form.certificateType.required"> |
| 36 | {{ $t('global.form.fieldRequired') }} |
| 37 | </template> |
| 38 | </b-form-invalid-feedback> |
| 39 | </b-form-group> |
| 40 | </template> |
| 41 | |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 42 | <b-form-group :label="$t('pageSslCertificates.modal.certificateFile')"> |
| 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" |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [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> |
| 72 | import { required, requiredIf } from 'vuelidate/lib/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 73 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 74 | |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 75 | import FormFile from '@/components/Global/FormFile'; |
| 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 | }, |
| 93 | data() { |
| 94 | return { |
| 95 | form: { |
| 96 | certificateType: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 97 | file: null, |
| 98 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 99 | }; |
| 100 | }, |
| 101 | computed: { |
| 102 | certificateTypes() { |
| 103 | return this.$store.getters['sslCertificates/availableUploadTypes']; |
| 104 | }, |
| 105 | certificateOptions() { |
| 106 | return this.certificateTypes.map(({ type, label }) => { |
| 107 | return { |
| 108 | text: label, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 109 | value: type, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 110 | }; |
| 111 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 112 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 113 | }, |
| 114 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 115 | certificateOptions: function (options) { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 116 | if (options.length) { |
| 117 | this.form.certificateType = options[0].value; |
| 118 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 119 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 120 | }, |
| 121 | validations() { |
| 122 | return { |
| 123 | form: { |
| 124 | certificateType: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | required: requiredIf(function () { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 126 | return !this.certificate; |
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 | file: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | required, |
| 131 | }, |
| 132 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 133 | }; |
| 134 | }, |
| 135 | methods: { |
| 136 | handleSubmit() { |
| 137 | this.$v.$touch(); |
| 138 | if (this.$v.$invalid) return; |
| 139 | this.$emit('ok', { |
| 140 | addNew: !this.certificate, |
| 141 | file: this.form.file, |
| 142 | location: this.certificate ? this.certificate.location : null, |
| 143 | type: this.certificate |
| 144 | ? this.certificate.type |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 145 | : this.form.certificateType, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 146 | }); |
| 147 | this.closeModal(); |
| 148 | }, |
| 149 | closeModal() { |
| 150 | this.$nextTick(() => { |
| 151 | this.$refs.modal.hide(); |
| 152 | }); |
| 153 | }, |
| 154 | resetForm() { |
| 155 | this.form.certificateType = this.certificateOptions.length |
| 156 | ? this.certificateOptions[0].value |
| 157 | : null; |
| 158 | this.form.file = null; |
| 159 | this.$v.$reset(); |
| 160 | }, |
| 161 | onOk(bvModalEvt) { |
| 162 | // prevent modal close |
| 163 | bvModalEvt.preventDefault(); |
| 164 | this.handleSubmit(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 165 | }, |
| 166 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 167 | }; |
| 168 | </script> |