blob: f4dcb824ecaef7659e1fcc4de3ca0330b6eece0b [file] [log] [blame]
Yoshie Muranakadc3d5412020-04-17 09:39:41 -07001<template>
2 <b-modal id="modal-role-group" ref="modal" @ok="onOk" @hidden="resetForm">
Derick Montague602e98a2020-10-21 16:20:00 -05003 <template #modal-title>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -07004 <template v-if="roleGroup">
5 {{ $t('pageLdap.modal.editRoleGroup') }}
6 </template>
7 <template v-else>
8 {{ $t('pageLdap.modal.addNewRoleGroup') }}
9 </template>
10 </template>
11 <b-container>
12 <b-row>
13 <b-col sm="8">
Sukanya Pandeyf125a3d2020-11-30 17:59:55 +053014 <b-form id="role-group" @submit.prevent="handleSubmit">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070015 <!-- Edit role group -->
16 <template v-if="roleGroup !== null">
17 <dl class="mb-4">
18 <dt>{{ $t('pageLdap.modal.groupName') }}</dt>
Farah Rasheed8e1ed792024-07-05 11:00:38 -050019 <dd style="word-break: break-all">{{ form.groupName }}</dd>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070020 </dl>
21 </template>
22
23 <!-- Add new role group -->
24 <template v-else>
25 <b-form-group
26 :label="$t('pageLdap.modal.groupName')"
27 label-for="role-group-name"
28 >
29 <b-form-input
30 id="role-group-name"
31 v-model="form.groupName"
Surya Vde23ea22024-07-11 15:19:46 +053032 :state="getValidationState(v$.form.groupName)"
33 @input="v$.form.groupName.$touch()"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070034 />
35 <b-form-invalid-feedback role="alert">
36 {{ $t('global.form.fieldRequired') }}
37 </b-form-invalid-feedback>
38 </b-form-group>
39 </template>
40
41 <b-form-group
42 :label="$t('pageLdap.modal.groupPrivilege')"
43 label-for="privilege"
44 >
45 <b-form-select
46 id="privilege"
47 v-model="form.groupPrivilege"
48 :options="accountRoles"
Surya Vde23ea22024-07-11 15:19:46 +053049 :state="getValidationState(v$.form.groupPrivilege)"
50 @input="v$.form.groupPrivilege.$touch()"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070051 >
Derick Montague602e98a2020-10-21 16:20:00 -050052 <template v-if="!roleGroup" #first>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070053 <b-form-select-option :value="null" disabled>
54 {{ $t('global.form.selectAnOption') }}
55 </b-form-select-option>
56 </template>
57 </b-form-select>
58 <b-form-invalid-feedback role="alert">
59 {{ $t('global.form.fieldRequired') }}
60 </b-form-invalid-feedback>
61 </b-form-group>
62 </b-form>
63 </b-col>
64 </b-row>
65 </b-container>
Sukanya Pandeyf125a3d2020-11-30 17:59:55 +053066 <template #modal-footer="{ cancel }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070067 <b-button variant="secondary" @click="cancel()">
68 {{ $t('global.action.cancel') }}
69 </b-button>
Sukanya Pandeyf125a3d2020-11-30 17:59:55 +053070 <b-button form="role-group" type="submit" variant="primary" @click="onOk">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070071 <template v-if="roleGroup">
72 {{ $t('global.action.save') }}
73 </template>
74 <template v-else>
75 {{ $t('global.action.add') }}
76 </template>
77 </b-button>
78 </template>
79 </b-modal>
80</template>
81
82<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070083import { required, requiredIf } from '@vuelidate/validators';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070084import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070085import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053086import { useI18n } from 'vue-i18n';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070087
88export default {
89 mixins: [VuelidateMixin],
90 props: {
91 roleGroup: {
92 type: Object,
93 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050094 validator: (prop) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070095 if (prop === null) return true;
96 return (
Yoshie Muranakaefd7c882020-10-30 09:32:06 -070097 Object.prototype.hasOwnProperty.call(prop, 'groupName') &&
98 Object.prototype.hasOwnProperty.call(prop, 'groupPrivilege')
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070099 );
Derick Montague602e98a2020-10-21 16:20:00 -0500100 },
101 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700102 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +0530103 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700104 setup() {
105 return {
106 v$: useVuelidate(),
107 };
108 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700109 data() {
110 return {
Surya Vde23ea22024-07-11 15:19:46 +0530111 $t: useI18n().t,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700112 form: {
113 groupName: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500114 groupPrivilege: null,
115 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700116 };
117 },
118 computed: {
119 accountRoles() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530120 return this.$store.getters['userManagement/accountRoles'];
Derick Montague602e98a2020-10-21 16:20:00 -0500121 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700122 },
123 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500124 roleGroup: function (value) {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700125 if (value === null) return;
126 this.form.groupName = value.groupName;
127 this.form.groupPrivilege = value.groupPrivilege;
Derick Montague602e98a2020-10-21 16:20:00 -0500128 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700129 },
130 validations() {
131 return {
132 form: {
133 groupName: {
Derick Montague602e98a2020-10-21 16:20:00 -0500134 required: requiredIf(function () {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700135 return !this.roleGroup;
Derick Montague602e98a2020-10-21 16:20:00 -0500136 }),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700137 },
138 groupPrivilege: {
Derick Montague602e98a2020-10-21 16:20:00 -0500139 required,
140 },
141 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700142 };
143 },
144 methods: {
145 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530146 this.v$.$touch();
147 if (this.v$.$invalid) return;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700148 this.$emit('ok', {
149 addNew: !this.roleGroup,
150 groupName: this.form.groupName,
Derick Montague602e98a2020-10-21 16:20:00 -0500151 groupPrivilege: this.form.groupPrivilege,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700152 });
153 this.closeModal();
154 },
155 closeModal() {
156 this.$nextTick(() => {
157 this.$refs.modal.hide();
158 });
159 },
160 resetForm() {
161 this.form.groupName = null;
162 this.form.groupPrivilege = null;
Surya Vde23ea22024-07-11 15:19:46 +0530163 this.v$.$reset();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700164 this.$emit('hidden');
165 },
166 onOk(bvModalEvt) {
167 // prevent modal close
168 bvModalEvt.preventDefault();
169 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500170 },
171 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700172};
173</script>