blob: 38ff4730c4799a601e515e7265cf19d6a285c3df [file] [log] [blame]
Yoshie Muranakadc3d5412020-04-17 09:39:41 -07001<template>
jason westoverd36ac8a2025-11-03 20:58:59 -06002 <b-modal
3 id="modal-role-group"
4 ref="modal"
5 :title="modalTitle"
6 @ok="onOk"
7 @hidden="resetForm"
8 >
Yoshie Muranakadc3d5412020-04-17 09:39:41 -07009 <b-container>
10 <b-row>
11 <b-col sm="8">
Sukanya Pandeyf125a3d2020-11-30 17:59:55 +053012 <b-form id="role-group" @submit.prevent="handleSubmit">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070013 <!-- Edit role group -->
14 <template v-if="roleGroup !== null">
15 <dl class="mb-4">
jason westoverd36ac8a2025-11-03 20:58:59 -060016 <dt>{{ i18n.t('pageLdap.modal.groupName') }}</dt>
Farah Rasheed8e1ed792024-07-05 11:00:38 -050017 <dd style="word-break: break-all">{{ form.groupName }}</dd>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070018 </dl>
19 </template>
20
21 <!-- Add new role group -->
22 <template v-else>
23 <b-form-group
jason westoverd36ac8a2025-11-03 20:58:59 -060024 :label="i18n.t('pageLdap.modal.groupName')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070025 label-for="role-group-name"
26 >
27 <b-form-input
28 id="role-group-name"
29 v-model="form.groupName"
Surya Vde23ea22024-07-11 15:19:46 +053030 :state="getValidationState(v$.form.groupName)"
31 @input="v$.form.groupName.$touch()"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070032 />
33 <b-form-invalid-feedback role="alert">
jason westoverd36ac8a2025-11-03 20:58:59 -060034 {{ i18n.t('global.form.fieldRequired') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070035 </b-form-invalid-feedback>
36 </b-form-group>
37 </template>
38
39 <b-form-group
jason westoverd36ac8a2025-11-03 20:58:59 -060040 :label="i18n.t('pageLdap.modal.groupPrivilege')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070041 label-for="privilege"
42 >
43 <b-form-select
44 id="privilege"
45 v-model="form.groupPrivilege"
46 :options="accountRoles"
Surya Vde23ea22024-07-11 15:19:46 +053047 :state="getValidationState(v$.form.groupPrivilege)"
48 @input="v$.form.groupPrivilege.$touch()"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070049 >
Derick Montague602e98a2020-10-21 16:20:00 -050050 <template v-if="!roleGroup" #first>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070051 <b-form-select-option :value="null" disabled>
jason westoverd36ac8a2025-11-03 20:58:59 -060052 {{ i18n.t('global.form.selectAnOption') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070053 </b-form-select-option>
54 </template>
55 </b-form-select>
56 <b-form-invalid-feedback role="alert">
jason westoverd36ac8a2025-11-03 20:58:59 -060057 {{ i18n.t('global.form.fieldRequired') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070058 </b-form-invalid-feedback>
59 </b-form-group>
60 </b-form>
61 </b-col>
62 </b-row>
63 </b-container>
jason westoverd36ac8a2025-11-03 20:58:59 -060064 <template #footer="{ cancel }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070065 <b-button variant="secondary" @click="cancel()">
jason westoverd36ac8a2025-11-03 20:58:59 -060066 {{ i18n.t('global.action.cancel') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070067 </b-button>
Sukanya Pandeyf125a3d2020-11-30 17:59:55 +053068 <b-button form="role-group" type="submit" variant="primary" @click="onOk">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070069 <template v-if="roleGroup">
jason westoverd36ac8a2025-11-03 20:58:59 -060070 {{ i18n.t('global.action.save') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070071 </template>
72 <template v-else>
jason westoverd36ac8a2025-11-03 20:58:59 -060073 {{ i18n.t('global.action.add') }}
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070074 </template>
75 </b-button>
76 </template>
77 </b-modal>
78</template>
79
80<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070081import { required, requiredIf } from '@vuelidate/validators';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070082import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070083import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053084import { useI18n } from 'vue-i18n';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070085
86export default {
87 mixins: [VuelidateMixin],
88 props: {
89 roleGroup: {
90 type: Object,
91 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050092 validator: (prop) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070093 if (prop === null) return true;
94 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070095 Object.prototype.hasOwnProperty.call(prop, 'groupName') &&
96 Object.prototype.hasOwnProperty.call(prop, 'groupPrivilege')
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070097 );
Derick Montague602e98a2020-10-21 16:20:00 -050098 },
99 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700100 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +0530101 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700102 setup() {
jason westoverd36ac8a2025-11-03 20:58:59 -0600103 const i18n = useI18n();
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700104 return {
105 v$: useVuelidate(),
jason westoverd36ac8a2025-11-03 20:58:59 -0600106 i18n,
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700107 };
108 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700109 data() {
110 return {
111 form: {
112 groupName: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500113 groupPrivilege: null,
114 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700115 };
116 },
117 computed: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600118 modalTitle() {
119 return this.roleGroup
120 ? this.i18n.t('pageLdap.modal.editRoleGroup')
121 : this.i18n.t('pageLdap.modal.addNewRoleGroup');
122 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700123 accountRoles() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530124 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500125 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700126 },
127 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500128 roleGroup: function (value) {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700129 if (value === null) return;
130 this.form.groupName = value.groupName;
131 this.form.groupPrivilege = value.groupPrivilege;
Derick Montague602e98a2020-10-21 16:20:00 -0500132 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700133 },
134 validations() {
135 return {
136 form: {
137 groupName: {
Derick Montague602e98a2020-10-21 16:20:00 -0500138 required: requiredIf(function () {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700139 return !this.roleGroup;
Derick Montague602e98a2020-10-21 16:20:00 -0500140 }),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700141 },
142 groupPrivilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500143 required,
144 },
145 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700146 };
147 },
148 methods: {
149 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530150 this.v$.$touch();
151 if (this.v$.$invalid) return;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700152 this.$emit('ok', {
153 addNew: !this.roleGroup,
154 groupName: this.form.groupName,
Derick Montague602e98a2020-10-21 16:20:00 -0500155 groupPrivilege: this.form.groupPrivilege,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700156 });
157 this.closeModal();
158 },
159 closeModal() {
160 this.$nextTick(() => {
161 this.$refs.modal.hide();
162 });
163 },
164 resetForm() {
165 this.form.groupName = null;
166 this.form.groupPrivilege = null;
Surya Vde23ea22024-07-11 15:19:46 +0530167 this.v$.$reset();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700168 this.$emit('hidden');
169 },
170 onOk(bvModalEvt) {
171 // prevent modal close
172 bvModalEvt.preventDefault();
173 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500174 },
175 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700176};
177</script>