| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 1 | <template> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 2 | <b-modal |
| 3 | id="modal-role-group" |
| 4 | ref="modal" |
| 5 | :title="modalTitle" |
| 6 | @ok="onOk" |
| 7 | @hidden="resetForm" |
| 8 | > |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 9 | <b-container> |
| 10 | <b-row> |
| 11 | <b-col sm="8"> |
| Sukanya Pandey | f125a3d | 2020-11-30 17:59:55 +0530 | [diff] [blame] | 12 | <b-form id="role-group" @submit.prevent="handleSubmit"> |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 13 | <!-- Edit role group --> |
| 14 | <template v-if="roleGroup !== null"> |
| 15 | <dl class="mb-4"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 16 | <dt>{{ i18n.t('pageLdap.modal.groupName') }}</dt> |
| Farah Rasheed | 8e1ed79 | 2024-07-05 11:00:38 -0500 | [diff] [blame] | 17 | <dd style="word-break: break-all">{{ form.groupName }}</dd> |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 18 | </dl> |
| 19 | </template> |
| 20 | |
| 21 | <!-- Add new role group --> |
| 22 | <template v-else> |
| 23 | <b-form-group |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 24 | :label="i18n.t('pageLdap.modal.groupName')" |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 25 | label-for="role-group-name" |
| 26 | > |
| 27 | <b-form-input |
| 28 | id="role-group-name" |
| 29 | v-model="form.groupName" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 30 | :state="getValidationState(v$.form.groupName)" |
| 31 | @input="v$.form.groupName.$touch()" |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 32 | /> |
| 33 | <b-form-invalid-feedback role="alert"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 34 | {{ i18n.t('global.form.fieldRequired') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 35 | </b-form-invalid-feedback> |
| 36 | </b-form-group> |
| 37 | </template> |
| 38 | |
| 39 | <b-form-group |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 40 | :label="i18n.t('pageLdap.modal.groupPrivilege')" |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 41 | label-for="privilege" |
| 42 | > |
| 43 | <b-form-select |
| 44 | id="privilege" |
| 45 | v-model="form.groupPrivilege" |
| 46 | :options="accountRoles" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 47 | :state="getValidationState(v$.form.groupPrivilege)" |
| 48 | @input="v$.form.groupPrivilege.$touch()" |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 49 | > |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 50 | <template v-if="!roleGroup" #first> |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 51 | <b-form-select-option :value="null" disabled> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 52 | {{ i18n.t('global.form.selectAnOption') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 53 | </b-form-select-option> |
| 54 | </template> |
| 55 | </b-form-select> |
| 56 | <b-form-invalid-feedback role="alert"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 57 | {{ i18n.t('global.form.fieldRequired') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 58 | </b-form-invalid-feedback> |
| 59 | </b-form-group> |
| 60 | </b-form> |
| 61 | </b-col> |
| 62 | </b-row> |
| 63 | </b-container> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 64 | <template #footer="{ cancel }"> |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 65 | <b-button variant="secondary" @click="cancel()"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 66 | {{ i18n.t('global.action.cancel') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 67 | </b-button> |
| Sukanya Pandey | f125a3d | 2020-11-30 17:59:55 +0530 | [diff] [blame] | 68 | <b-button form="role-group" type="submit" variant="primary" @click="onOk"> |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 69 | <template v-if="roleGroup"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 70 | {{ i18n.t('global.action.save') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 71 | </template> |
| 72 | <template v-else> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 73 | {{ i18n.t('global.action.add') }} |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 74 | </template> |
| 75 | </b-button> |
| 76 | </template> |
| 77 | </b-modal> |
| 78 | </template> |
| 79 | |
| 80 | <script> |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 81 | import { required, requiredIf } from '@vuelidate/validators'; |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 82 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 83 | import { useVuelidate } from '@vuelidate/core'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 84 | import { useI18n } from 'vue-i18n'; |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 85 | |
| 86 | export default { |
| 87 | mixins: [VuelidateMixin], |
| 88 | props: { |
| 89 | roleGroup: { |
| 90 | type: Object, |
| 91 | default: null, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 92 | validator: (prop) => { |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 93 | if (prop === null) return true; |
| 94 | return ( |
| Yoshie Muranaka | efd7c88 | 2020-10-30 09:32:06 -0700 | [diff] [blame] | 95 | Object.prototype.hasOwnProperty.call(prop, 'groupName') && |
| 96 | Object.prototype.hasOwnProperty.call(prop, 'groupPrivilege') |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 97 | ); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 98 | }, |
| 99 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 100 | }, |
| Hariharan Rangasamy | c5d60f5 | 2025-10-31 12:58:56 +0530 | [diff] [blame] | 101 | emits: ['ok', 'hidden'], |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 102 | setup() { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 103 | const i18n = useI18n(); |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 104 | return { |
| 105 | v$: useVuelidate(), |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 106 | i18n, |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 107 | }; |
| 108 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 109 | data() { |
| 110 | return { |
| 111 | form: { |
| 112 | groupName: null, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 113 | groupPrivilege: null, |
| 114 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 115 | }; |
| 116 | }, |
| 117 | computed: { |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 118 | modalTitle() { |
| 119 | return this.roleGroup |
| 120 | ? this.i18n.t('pageLdap.modal.editRoleGroup') |
| 121 | : this.i18n.t('pageLdap.modal.addNewRoleGroup'); |
| 122 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 123 | accountRoles() { |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 124 | return this.$store.getters['userManagement/accountRoles']; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 126 | }, |
| 127 | watch: { |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 128 | roleGroup: function (value) { |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 129 | if (value === null) return; |
| 130 | this.form.groupName = value.groupName; |
| 131 | this.form.groupPrivilege = value.groupPrivilege; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 132 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 133 | }, |
| 134 | validations() { |
| 135 | return { |
| 136 | form: { |
| 137 | groupName: { |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 138 | required: requiredIf(function () { |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 139 | return !this.roleGroup; |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 140 | }), |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 141 | }, |
| 142 | groupPrivilege: { |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 143 | required, |
| 144 | }, |
| 145 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 146 | }; |
| 147 | }, |
| 148 | methods: { |
| 149 | handleSubmit() { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 150 | this.v$.$touch(); |
| 151 | if (this.v$.$invalid) return; |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 152 | this.$emit('ok', { |
| 153 | addNew: !this.roleGroup, |
| 154 | groupName: this.form.groupName, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 155 | groupPrivilege: this.form.groupPrivilege, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 156 | }); |
| 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 V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 167 | this.v$.$reset(); |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 168 | this.$emit('hidden'); |
| 169 | }, |
| 170 | onOk(bvModalEvt) { |
| 171 | // prevent modal close |
| 172 | bvModalEvt.preventDefault(); |
| 173 | this.handleSubmit(); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 174 | }, |
| 175 | }, |
| Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 176 | }; |
| 177 | </script> |