blob: 60170f1bb93bcc82fe0885b9ba1316f31d64e011 [file] [log] [blame]
Yoshie Muranaka37393812020-03-24 15:25:24 -07001<template>
2 <b-modal id="upload-certificate" ref="modal" @ok="onOk" @hidden="resetForm">
Derick Montague602e98a2020-10-21 16:20:00 -05003 <template #modal-title>
Yoshie Muranaka37393812020-03-24 15:25:24 -07004 <template v-if="certificate">
Sandeepa Singhb4406162021-07-26 15:05:39 +05305 {{ $t('pageCertificates.replaceCertificate') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -07006 </template>
7 <template v-else>
Sandeepa Singhb4406162021-07-26 15:05:39 +05308 {{ $t('pageCertificates.addNewCertificate') }}
Yoshie Muranaka37393812020-03-24 15:25:24 -07009 </template>
10 </template>
11 <b-form>
12 <!-- Replace Certificate type -->
13 <template v-if="certificate !== null">
14 <dl class="mb-4">
Sandeepa Singhb4406162021-07-26 15:05:39 +053015 <dt>{{ $t('pageCertificates.modal.certificateType') }}</dt>
Yoshie Muranaka37393812020-03-24 15:25:24 -070016 <dd>{{ certificate.certificate }}</dd>
17 </dl>
18 </template>
19
20 <!-- Add new Certificate type -->
21 <template v-else>
22 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053023 :label="$t('pageCertificates.modal.certificateType')"
Yoshie Muranaka37393812020-03-24 15:25:24 -070024 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
Sandeepa Singhb4406162021-07-26 15:05:39 +053042 <b-form-group :label="$t('pageCertificates.modal.certificateFile')">
SurenNeware978807d2020-09-03 18:35:21 +053043 <form-file
Yoshie Muranaka37393812020-03-24 15:25:24 -070044 id="certificate-file"
45 v-model="form.file"
46 accept=".pem"
Yoshie Muranaka37393812020-03-24 15:25:24 -070047 :state="getValidationState($v.form.file)"
SurenNeware978807d2020-09-03 18:35:21 +053048 >
49 <template #invalid>
50 <b-form-invalid-feedback role="alert">
51 {{ $t('global.form.required') }}
52 </b-form-invalid-feedback>
Yoshie Muranaka37393812020-03-24 15:25:24 -070053 </template>
SurenNeware978807d2020-09-03 18:35:21 +053054 </form-file>
Yoshie Muranaka37393812020-03-24 15:25:24 -070055 </b-form-group>
56 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -050057 <template #modal-ok>
Yoshie Muranaka37393812020-03-24 15:25:24 -070058 <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 Pandey38357132020-12-22 13:40:59 +053065 <template #modal-cancel>
66 {{ $t('global.action.cancel') }}
67 </template>
Yoshie Muranaka37393812020-03-24 15:25:24 -070068 </b-modal>
69</template>
70
71<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070072import { required, requiredIf } from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +053073import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070074import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka37393812020-03-24 15:25:24 -070075
SurenNeware978807d2020-09-03 18:35:21 +053076import FormFile from '@/components/Global/FormFile';
77
Yoshie Muranaka37393812020-03-24 15:25:24 -070078export default {
SurenNeware978807d2020-09-03 18:35:21 +053079 components: { FormFile },
Yoshie Muranaka37393812020-03-24 15:25:24 -070080 mixins: [VuelidateMixin],
81 props: {
82 certificate: {
83 type: Object,
84 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050085 validator: (prop) => {
Yoshie Muranaka37393812020-03-24 15:25:24 -070086 if (prop === null) return true;
87 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070088 Object.prototype.hasOwnProperty.call(prop, 'type') &&
89 Object.prototype.hasOwnProperty.call(prop, 'certificate')
Yoshie Muranaka37393812020-03-24 15:25:24 -070090 );
Derick Montague602e98a2020-10-21 16:20:00 -050091 },
92 },
Yoshie Muranaka37393812020-03-24 15:25:24 -070093 },
Ed Tanous7d6b44c2024-03-23 14:56:34 -070094 setup() {
95 return {
96 v$: useVuelidate(),
97 };
98 },
Yoshie Muranaka37393812020-03-24 15:25:24 -070099 data() {
100 return {
101 form: {
102 certificateType: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500103 file: null,
104 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700105 };
106 },
107 computed: {
108 certificateTypes() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530109 return this.$store.getters['certificates/availableUploadTypes'];
Yoshie Muranaka37393812020-03-24 15:25:24 -0700110 },
111 certificateOptions() {
112 return this.certificateTypes.map(({ type, label }) => {
113 return {
114 text: label,
Derick Montague602e98a2020-10-21 16:20:00 -0500115 value: type,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700116 };
117 });
Derick Montague602e98a2020-10-21 16:20:00 -0500118 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700119 },
120 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500121 certificateOptions: function (options) {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700122 if (options.length) {
123 this.form.certificateType = options[0].value;
124 }
Derick Montague602e98a2020-10-21 16:20:00 -0500125 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700126 },
127 validations() {
128 return {
129 form: {
130 certificateType: {
Derick Montague602e98a2020-10-21 16:20:00 -0500131 required: requiredIf(function () {
Yoshie Muranaka37393812020-03-24 15:25:24 -0700132 return !this.certificate;
Derick Montague602e98a2020-10-21 16:20:00 -0500133 }),
Yoshie Muranaka37393812020-03-24 15:25:24 -0700134 },
135 file: {
Derick Montague602e98a2020-10-21 16:20:00 -0500136 required,
137 },
138 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700139 };
140 },
141 methods: {
142 handleSubmit() {
143 this.$v.$touch();
144 if (this.$v.$invalid) return;
145 this.$emit('ok', {
146 addNew: !this.certificate,
147 file: this.form.file,
148 location: this.certificate ? this.certificate.location : null,
149 type: this.certificate
150 ? this.certificate.type
Derick Montague602e98a2020-10-21 16:20:00 -0500151 : this.form.certificateType,
Yoshie Muranaka37393812020-03-24 15:25:24 -0700152 });
153 this.closeModal();
154 },
155 closeModal() {
156 this.$nextTick(() => {
157 this.$refs.modal.hide();
158 });
159 },
160 resetForm() {
161 this.form.certificateType = this.certificateOptions.length
162 ? this.certificateOptions[0].value
163 : null;
164 this.form.file = null;
165 this.$v.$reset();
166 },
167 onOk(bvModalEvt) {
168 // prevent modal close
169 bvModalEvt.preventDefault();
170 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500171 },
172 },
Yoshie Muranaka37393812020-03-24 15:25:24 -0700173};
174</script>