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> |
| 65 | </b-modal> |
| 66 | </template> |
| 67 | |
| 68 | <script> |
| 69 | import { required, requiredIf } from 'vuelidate/lib/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame] | 70 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 71 | |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 72 | import FormFile from '@/components/Global/FormFile'; |
| 73 | |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 74 | export default { |
SurenNeware | 978807d | 2020-09-03 18:35:21 +0530 | [diff] [blame] | 75 | components: { FormFile }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 76 | mixins: [VuelidateMixin], |
| 77 | props: { |
| 78 | certificate: { |
| 79 | type: Object, |
| 80 | default: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 81 | validator: (prop) => { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 82 | if (prop === null) return true; |
| 83 | return ( |
Yoshie Muranaka | efd7c88 | 2020-10-30 09:32:06 -0700 | [diff] [blame] | 84 | Object.prototype.hasOwnProperty.call(prop, 'type') && |
| 85 | Object.prototype.hasOwnProperty.call(prop, 'certificate') |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 86 | ); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 87 | }, |
| 88 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 89 | }, |
| 90 | data() { |
| 91 | return { |
| 92 | form: { |
| 93 | certificateType: null, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 94 | file: null, |
| 95 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 96 | }; |
| 97 | }, |
| 98 | computed: { |
| 99 | certificateTypes() { |
| 100 | return this.$store.getters['sslCertificates/availableUploadTypes']; |
| 101 | }, |
| 102 | certificateOptions() { |
| 103 | return this.certificateTypes.map(({ type, label }) => { |
| 104 | return { |
| 105 | text: label, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 106 | value: type, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 107 | }; |
| 108 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 109 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 110 | }, |
| 111 | watch: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 112 | certificateOptions: function (options) { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 113 | if (options.length) { |
| 114 | this.form.certificateType = options[0].value; |
| 115 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 116 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 117 | }, |
| 118 | validations() { |
| 119 | return { |
| 120 | form: { |
| 121 | certificateType: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 122 | required: requiredIf(function () { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 123 | return !this.certificate; |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 124 | }), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 125 | }, |
| 126 | file: { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 127 | required, |
| 128 | }, |
| 129 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 130 | }; |
| 131 | }, |
| 132 | methods: { |
| 133 | handleSubmit() { |
| 134 | this.$v.$touch(); |
| 135 | if (this.$v.$invalid) return; |
| 136 | this.$emit('ok', { |
| 137 | addNew: !this.certificate, |
| 138 | file: this.form.file, |
| 139 | location: this.certificate ? this.certificate.location : null, |
| 140 | type: this.certificate |
| 141 | ? this.certificate.type |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 142 | : this.form.certificateType, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 143 | }); |
| 144 | this.closeModal(); |
| 145 | }, |
| 146 | closeModal() { |
| 147 | this.$nextTick(() => { |
| 148 | this.$refs.modal.hide(); |
| 149 | }); |
| 150 | }, |
| 151 | resetForm() { |
| 152 | this.form.certificateType = this.certificateOptions.length |
| 153 | ? this.certificateOptions[0].value |
| 154 | : null; |
| 155 | this.form.file = null; |
| 156 | this.$v.$reset(); |
| 157 | }, |
| 158 | onOk(bvModalEvt) { |
| 159 | // prevent modal close |
| 160 | bvModalEvt.preventDefault(); |
| 161 | this.handleSubmit(); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 162 | }, |
| 163 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 164 | }; |
| 165 | </script> |