blob: 927163e499385650363fbe287a7b0545679a44ab [file] [log] [blame]
Yoshie Muranaka37393812020-03-24 15:25:24 -07001<template>
jason westoverd36ac8a2025-11-03 20:58:59 -06002 <b-modal
3 id="upload-certificate"
4 ref="modal"
5 :title="modalTitle"
6 @ok="onOk"
7 @hidden="resetForm"
8 >
Yoshie Muranaka37393812020-03-24 15:25:24 -07009 <b-form>
10 <!-- Replace Certificate type -->
11 <template v-if="certificate !== null">
12 <dl class="mb-4">
jason westoverd36ac8a2025-11-03 20:58:59 -060013 <dt>{{ i18n.t('pageCertificates.modal.certificateType') }}</dt>
Yoshie Muranaka37393812020-03-24 15:25:24 -070014 <dd>{{ certificate.certificate }}</dd>
15 </dl>
16 </template>
17
18 <!-- Add new Certificate type -->
19 <template v-else>
20 <b-form-group
jason westoverd36ac8a2025-11-03 20:58:59 -060021 :label="i18n.t('pageCertificates.modal.certificateType')"
Yoshie Muranaka37393812020-03-24 15:25:24 -070022 label-for="certificate-type"
23 >
24 <b-form-select
25 id="certificate-type"
26 v-model="form.certificateType"
27 :options="certificateOptions"
Surya Vde23ea22024-07-11 15:19:46 +053028 :state="getValidationState(v$.form.certificateType)"
29 @input="v$.form.certificateType.$touch()"
Yoshie Muranaka37393812020-03-24 15:25:24 -070030 >
31 </b-form-select>
32 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053033 <template v-if="v$.form.certificateType.required.$invalid">
jason westoverd36ac8a2025-11-03 20:58:59 -060034 {{ i18n.t('global.form.fieldRequired') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -070035 </template>
36 </b-form-invalid-feedback>
37 </b-form-group>
38 </template>
39
jason westoverd36ac8a2025-11-03 20:58:59 -060040 <b-form-group :label="i18n.t('pageCertificates.modal.certificateFile')">
SurenNeware978807d2020-09-03 18:35:21 +053041 <form-file
Yoshie Muranaka37393812020-03-24 15:25:24 -070042 id="certificate-file"
43 v-model="form.file"
44 accept=".pem"
Surya Vde23ea22024-07-11 15:19:46 +053045 :state="getValidationState(v$.form.file)"
SurenNeware978807d2020-09-03 18:35:21 +053046 >
47 <template #invalid>
48 <b-form-invalid-feedback role="alert">
jason westoverd36ac8a2025-11-03 20:58:59 -060049 {{ i18n.t('global.form.required') }}
SurenNeware978807d2020-09-03 18:35:21 +053050 </b-form-invalid-feedback>
Yoshie Muranaka37393812020-03-24 15:25:24 -070051 </template>
SurenNeware978807d2020-09-03 18:35:21 +053052 </form-file>
Yoshie Muranaka37393812020-03-24 15:25:24 -070053 </b-form-group>
54 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -050055 <template #modal-ok>
Yoshie Muranaka37393812020-03-24 15:25:24 -070056 <template v-if="certificate">
jason westoverd36ac8a2025-11-03 20:58:59 -060057 {{ i18n.t('global.action.replace') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -070058 </template>
59 <template v-else>
jason westoverd36ac8a2025-11-03 20:58:59 -060060 {{ i18n.t('global.action.add') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -070061 </template>
62 </template>
Sukanya Pandey38357132020-12-22 13:40:59 +053063 <template #modal-cancel>
jason westoverd36ac8a2025-11-03 20:58:59 -060064 {{ i18n.t('global.action.cancel') }}
Sukanya Pandey38357132020-12-22 13:40:59 +053065 </template>
Yoshie Muranaka37393812020-03-24 15:25:24 -070066 </b-modal>
67</template>
68
69<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070070import { required, requiredIf } from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +053071import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070072import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka37393812020-03-24 15:25:24 -070073
SurenNeware978807d2020-09-03 18:35:21 +053074import FormFile from '@/components/Global/FormFile';
Surya Vde23ea22024-07-11 15:19:46 +053075import { useI18n } from 'vue-i18n';
SurenNeware978807d2020-09-03 18:35:21 +053076
Yoshie Muranaka37393812020-03-24 15:25:24 -070077export default {
SurenNeware978807d2020-09-03 18:35:21 +053078 components: { FormFile },
Yoshie Muranaka37393812020-03-24 15:25:24 -070079 mixins: [VuelidateMixin],
80 props: {
81 certificate: {
82 type: Object,
83 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050084 validator: (prop) => {
Yoshie Muranaka37393812020-03-24 15:25:24 -070085 if (prop === null) return true;
86 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070087 Object.prototype.hasOwnProperty.call(prop, 'type') &&
88 Object.prototype.hasOwnProperty.call(prop, 'certificate')
Yoshie Muranaka37393812020-03-24 15:25:24 -070089 );
Derick Montague602e98a2020-10-21 16:20:00 -050090 },
91 },
Yoshie Muranaka37393812020-03-24 15:25:24 -070092 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053093 emits: ['ok'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070094 setup() {
jason westoverd36ac8a2025-11-03 20:58:59 -060095 const i18n = useI18n();
Ed Tanous7d6b44c2024-03-23 14:56:34 -070096 return {
97 v$: useVuelidate(),
jason westoverd36ac8a2025-11-03 20:58:59 -060098 i18n,
Ed Tanous7d6b44c2024-03-23 14:56:34 -070099 };
100 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700101 data() {
102 return {
103 form: {
104 certificateType: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500105 file: null,
106 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700107 };
108 },
109 computed: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600110 modalTitle() {
111 return this.certificate
112 ? this.i18n.t('pageCertificates.replaceCertificate')
113 : this.i18n.t('pageCertificates.addNewCertificate');
114 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700115 certificateTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530116 return this.$store.getters['certificates/availableUploadTypes'];
Yoshie Muranaka37393812020-03-24 15:25:24 -0700117 },
118 certificateOptions() {
119 return this.certificateTypes.map(({ type, label }) => {
120 return {
121 text: label,
Derick Montague602e98a2020-10-21 16:20:00 -0500122 value: type,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700123 };
124 });
Derick Montague602e98a2020-10-21 16:20:00 -0500125 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700126 },
127 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500128 certificateOptions: function (options) {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700129 if (options.length) {
130 this.form.certificateType = options[0].value;
131 }
Derick Montague602e98a2020-10-21 16:20:00 -0500132 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700133 },
134 validations() {
135 return {
136 form: {
137 certificateType: {
Derick Montague602e98a2020-10-21 16:20:00 -0500138 required: requiredIf(function () {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700139 return !this.certificate;
Derick Montague602e98a2020-10-21 16:20:00 -0500140 }),
Yoshie Muranaka37393812020-03-24 15:25:24 -0700141 },
142 file: {
Derick Montague602e98a2020-10-21 16:20:00 -0500143 required,
144 },
145 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700146 };
147 },
148 methods: {
149 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530150 this.v$.$touch();
151 if (this.v$.$invalid) return;
Yoshie Muranaka37393812020-03-24 15:25:24 -0700152 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 Montague602e98a2020-10-21 16:20:00 -0500158 : this.form.certificateType,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700159 });
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 Vde23ea22024-07-11 15:19:46 +0530172 this.v$.$reset();
Yoshie Muranaka37393812020-03-24 15:25:24 -0700173 },
174 onOk(bvModalEvt) {
175 // prevent modal close
176 bvModalEvt.preventDefault();
177 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500178 },
179 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700180};
181</script>