Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 0b8cffd | 2020-06-23 08:44:54 -0700 | [diff] [blame] | 2 | <b-modal id="modal-user" ref="modal" @hidden="resetForm"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 3 | <template v-slot:modal-title> |
| 4 | <template v-if="newUser"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 5 | {{ $t('pageLocalUserManagement.addUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 6 | </template> |
| 7 | <template v-else> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 8 | {{ $t('pageLocalUserManagement.editUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 9 | </template> |
| 10 | </template> |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 11 | <b-form id="form-user" novalidate @submit.prevent="handleSubmit"> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 12 | <b-container> |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 13 | <!-- Manual unlock form control --> |
| 14 | <b-row v-if="!newUser && manualUnlockPolicy && user.Locked"> |
| 15 | <b-col sm="9"> |
| 16 | <alert :show="true" variant="warning" small> |
| 17 | <template v-if="!$v.form.manualUnlock.$dirty"> |
| 18 | {{ $t('pageLocalUserManagement.modal.accountLocked') }} |
| 19 | </template> |
| 20 | <template v-else> |
| 21 | {{ |
| 22 | $t('pageLocalUserManagement.modal.clickSaveToUnlockAccount') |
| 23 | }} |
| 24 | </template> |
| 25 | </alert> |
| 26 | </b-col> |
| 27 | <b-col sm="3"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 28 | <input |
| 29 | v-model="form.manualUnlock" |
| 30 | data-test-id="localUserManagement-input-manualUnlock" |
| 31 | type="hidden" |
| 32 | value="false" |
| 33 | /> |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 34 | <b-button |
| 35 | variant="primary" |
| 36 | :disabled="$v.form.manualUnlock.$dirty" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 37 | data-test-id="localUserManagement-button-manualUnlock" |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 38 | @click="$v.form.manualUnlock.$touch()" |
| 39 | > |
| 40 | {{ $t('pageLocalUserManagement.modal.unlock') }} |
| 41 | </b-button> |
| 42 | </b-col> |
| 43 | </b-row> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 44 | <b-row> |
| 45 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 46 | <b-form-group |
| 47 | :label="$t('pageLocalUserManagement.modal.accountStatus')" |
| 48 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 49 | <b-form-radio |
| 50 | v-model="form.status" |
| 51 | name="user-status" |
| 52 | :value="true" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 53 | data-test-id="localUserManagement-radioButton-statusEnabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 54 | @input="$v.form.status.$touch()" |
| 55 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 56 | {{ $t('global.status.enabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 57 | </b-form-radio> |
| 58 | <b-form-radio |
| 59 | v-model="form.status" |
| 60 | name="user-status" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 61 | data-test-id="localUserManagement-radioButton-statusDisabled" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 62 | :value="false" |
| 63 | @input="$v.form.status.$touch()" |
| 64 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 65 | {{ $t('global.status.disabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 66 | </b-form-radio> |
| 67 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 68 | <b-form-group |
| 69 | :label="$t('pageLocalUserManagement.modal.username')" |
| 70 | label-for="username" |
| 71 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 72 | <b-form-text id="username-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 73 | {{ $t('pageLocalUserManagement.modal.cannotStartWithANumber') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 74 | <br /> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 75 | {{ |
| 76 | $t( |
| 77 | 'pageLocalUserManagement.modal.noSpecialCharactersExceptUnderscore' |
| 78 | ) |
| 79 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 80 | </b-form-text> |
| 81 | <b-form-input |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 82 | id="username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 83 | v-model="form.username" |
| 84 | type="text" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 85 | aria-describedby="username-help-block" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 86 | data-test-id="localUserManagement-input-username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 87 | :state="getValidationState($v.form.username)" |
| 88 | :disabled="!newUser && originalUsername === 'root'" |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 89 | @input="$v.form.username.$touch()" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 90 | /> |
| 91 | <b-form-invalid-feedback role="alert"> |
| 92 | <template v-if="!$v.form.username.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 93 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 94 | </template> |
| 95 | <template v-else-if="!$v.form.username.maxLength"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 96 | {{ |
| 97 | $t('global.form.lengthMustBeBetween', { min: 1, max: 16 }) |
| 98 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 99 | </template> |
| 100 | <template v-else-if="!$v.form.username.pattern"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 101 | {{ $t('global.form.invalidFormat') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 102 | </template> |
| 103 | </b-form-invalid-feedback> |
| 104 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 105 | <b-form-group |
| 106 | :label="$t('pageLocalUserManagement.modal.privilege')" |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 107 | label-for="privilege" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 108 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 109 | <b-form-select |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 110 | id="privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 111 | v-model="form.privilege" |
| 112 | :options="privilegeTypes" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 113 | data-test-id="localUserManagement-select-privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 114 | :state="getValidationState($v.form.privilege)" |
| 115 | @input="$v.form.privilege.$touch()" |
| 116 | > |
| 117 | </b-form-select> |
| 118 | <b-form-invalid-feedback role="alert"> |
| 119 | <template v-if="!$v.form.privilege.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 120 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 121 | </template> |
| 122 | </b-form-invalid-feedback> |
| 123 | </b-form-group> |
| 124 | </b-col> |
| 125 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 126 | <b-form-group |
| 127 | :label="$t('pageLocalUserManagement.modal.userPassword')" |
| 128 | label-for="password" |
| 129 | > |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 130 | <b-form-text id="password-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 131 | {{ |
| 132 | $t('pageLocalUserManagement.modal.passwordMustBeBetween', { |
| 133 | min: passwordRequirements.minLength, |
| 134 | max: passwordRequirements.maxLength |
| 135 | }) |
| 136 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 137 | </b-form-text> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 138 | <input-password-toggle> |
| 139 | <b-form-input |
| 140 | id="password" |
| 141 | v-model="form.password" |
| 142 | type="password" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 143 | data-test-id="localUserManagement-input-password" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 144 | aria-describedby="password-help-block" |
| 145 | :state="getValidationState($v.form.password)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 146 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 147 | @input="$v.form.password.$touch()" |
| 148 | /> |
| 149 | <b-form-invalid-feedback role="alert"> |
| 150 | <template v-if="!$v.form.password.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 151 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 152 | </template> |
| 153 | <template |
| 154 | v-if=" |
| 155 | !$v.form.password.minLength || !$v.form.password.maxLength |
| 156 | " |
| 157 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 158 | {{ |
| 159 | $t( |
| 160 | 'pageLocalUserManagement.modal.passwordMustBeBetween', |
| 161 | { |
| 162 | min: passwordRequirements.minLength, |
| 163 | max: passwordRequirements.maxLength |
| 164 | } |
| 165 | ) |
| 166 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 167 | </template> |
| 168 | </b-form-invalid-feedback> |
| 169 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 170 | </b-form-group> |
| 171 | <b-form-group |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 172 | :label="$t('pageLocalUserManagement.modal.confirmUserPassword')" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 173 | label-for="password-confirmation" |
| 174 | > |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 175 | <input-password-toggle> |
| 176 | <b-form-input |
| 177 | id="password-confirmation" |
| 178 | v-model="form.passwordConfirmation" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 179 | data-test-id="localUserManagement-input-passwordConfirmation" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 180 | type="password" |
| 181 | :state="getValidationState($v.form.passwordConfirmation)" |
Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 182 | class="form-control-with-button" |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 183 | @input="$v.form.passwordConfirmation.$touch()" |
| 184 | /> |
| 185 | <b-form-invalid-feedback role="alert"> |
| 186 | <template v-if="!$v.form.passwordConfirmation.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 187 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 188 | </template> |
| 189 | <template |
| 190 | v-else-if="!$v.form.passwordConfirmation.sameAsPassword" |
| 191 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 192 | {{ |
| 193 | $t('pageLocalUserManagement.modal.passwordsDoNotMatch') |
| 194 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 195 | </template> |
| 196 | </b-form-invalid-feedback> |
| 197 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 198 | </b-form-group> |
| 199 | </b-col> |
| 200 | </b-row> |
| 201 | </b-container> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 202 | </b-form> |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 203 | <template v-slot:modal-footer="{ ok, cancel }"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 204 | <b-button |
| 205 | variant="secondary" |
| 206 | data-test-id="localUserManagement-button-cancel" |
| 207 | @click="cancel()" |
| 208 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 209 | {{ $t('global.action.cancel') }} |
| 210 | </b-button> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 211 | <b-button |
| 212 | form="form-user" |
| 213 | data-test-id="localUserManagement-button-submit" |
| 214 | type="submit" |
| 215 | variant="primary" |
| 216 | @click="onOk" |
| 217 | > |
Yoshie Muranaka | 9a9092d | 2020-05-04 08:24:21 -0700 | [diff] [blame] | 218 | <template v-if="newUser"> |
| 219 | {{ $t('pageLocalUserManagement.addUser') }} |
| 220 | </template> |
| 221 | <template v-else> |
| 222 | {{ $t('global.action.save') }} |
| 223 | </template> |
| 224 | </b-button> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 225 | </template> |
| 226 | </b-modal> |
| 227 | </template> |
| 228 | |
| 229 | <script> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 230 | import { |
| 231 | required, |
| 232 | maxLength, |
| 233 | minLength, |
| 234 | sameAs, |
| 235 | helpers, |
| 236 | requiredIf |
| 237 | } from 'vuelidate/lib/validators'; |
SurenNeware | 6185909 | 2020-10-01 09:37:32 +0530 | [diff] [blame^] | 238 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| 239 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
| 240 | import Alert from '@/components/Global/Alert'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 241 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 242 | export default { |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 243 | components: { Alert, InputPasswordToggle }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 244 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 245 | props: { |
| 246 | user: { |
| 247 | type: Object, |
| 248 | default: null |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 249 | }, |
| 250 | passwordRequirements: { |
| 251 | type: Object, |
| 252 | required: true |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 253 | } |
| 254 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 255 | data() { |
| 256 | return { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 257 | originalUsername: '', |
| 258 | form: { |
| 259 | status: true, |
| 260 | username: '', |
| 261 | privilege: '', |
| 262 | password: '', |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 263 | passwordConfirmation: '', |
| 264 | manualUnlock: false |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 265 | } |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 266 | }; |
| 267 | }, |
| 268 | computed: { |
| 269 | newUser() { |
| 270 | return this.user ? false : true; |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 271 | }, |
| 272 | accountSettings() { |
| 273 | return this.$store.getters['localUsers/accountSettings']; |
| 274 | }, |
| 275 | manualUnlockPolicy() { |
| 276 | return !this.accountSettings.accountLockoutDuration; |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 277 | }, |
| 278 | privilegeTypes() { |
| 279 | return this.$store.getters['localUsers/accountRoles']; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 280 | } |
| 281 | }, |
| 282 | watch: { |
| 283 | user: function(value) { |
| 284 | if (value === null) return; |
| 285 | this.originalUsername = value.username; |
| 286 | this.form.username = value.username; |
| 287 | this.form.status = value.Enabled; |
| 288 | this.form.privilege = value.privilege; |
| 289 | } |
| 290 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 291 | validations() { |
| 292 | return { |
| 293 | form: { |
| 294 | status: { |
| 295 | required |
| 296 | }, |
| 297 | username: { |
| 298 | required, |
| 299 | maxLength: maxLength(16), |
| 300 | pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/) |
| 301 | }, |
| 302 | privilege: { |
| 303 | required |
| 304 | }, |
| 305 | password: { |
| 306 | required: requiredIf(function() { |
| 307 | return this.requirePassword(); |
| 308 | }), |
| 309 | minLength: minLength(this.passwordRequirements.minLength), |
| 310 | maxLength: maxLength(this.passwordRequirements.maxLength) |
| 311 | }, |
| 312 | passwordConfirmation: { |
| 313 | required: requiredIf(function() { |
| 314 | return this.requirePassword(); |
| 315 | }), |
| 316 | sameAsPassword: sameAs('password') |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 317 | }, |
| 318 | manualUnlock: {} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 319 | } |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 320 | }; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 321 | }, |
| 322 | methods: { |
| 323 | handleSubmit() { |
| 324 | let userData = {}; |
| 325 | |
| 326 | if (this.newUser) { |
| 327 | this.$v.$touch(); |
| 328 | if (this.$v.$invalid) return; |
| 329 | userData.username = this.form.username; |
| 330 | userData.status = this.form.status; |
| 331 | userData.privilege = this.form.privilege; |
| 332 | userData.password = this.form.password; |
| 333 | } else { |
| 334 | if (this.$v.$invalid) return; |
| 335 | userData.originalUsername = this.originalUsername; |
| 336 | if (this.$v.form.status.$dirty) { |
| 337 | userData.status = this.form.status; |
| 338 | } |
| 339 | if (this.$v.form.username.$dirty) { |
| 340 | userData.username = this.form.username; |
| 341 | } |
| 342 | if (this.$v.form.privilege.$dirty) { |
| 343 | userData.privilege = this.form.privilege; |
| 344 | } |
| 345 | if (this.$v.form.password.$dirty) { |
| 346 | userData.password = this.form.password; |
| 347 | } |
Yoshie Muranaka | 1f9ed4c | 2020-03-26 16:59:54 -0700 | [diff] [blame] | 348 | if (this.$v.form.manualUnlock.$dirty) { |
| 349 | // If form manualUnlock control $dirty then |
| 350 | // set user Locked property to false |
| 351 | userData.locked = false; |
| 352 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 353 | if (Object.entries(userData).length === 1) { |
| 354 | this.closeModal(); |
| 355 | return; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | this.$emit('ok', { isNewUser: this.newUser, userData }); |
| 360 | this.closeModal(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 361 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 362 | closeModal() { |
| 363 | this.$nextTick(() => { |
| 364 | this.$refs.modal.hide(); |
| 365 | }); |
| 366 | }, |
| 367 | resetForm() { |
| 368 | this.form.originalUsername = ''; |
| 369 | this.form.status = true; |
| 370 | this.form.username = ''; |
| 371 | this.form.privilege = ''; |
| 372 | this.form.password = ''; |
| 373 | this.form.passwordConfirmation = ''; |
| 374 | this.$v.$reset(); |
Yoshie Muranaka | 791622b | 2020-04-17 13:55:16 -0700 | [diff] [blame] | 375 | this.$emit('hidden'); |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 376 | }, |
| 377 | requirePassword() { |
| 378 | if (this.newUser) return true; |
| 379 | if (this.$v.form.password.$dirty) return true; |
| 380 | if (this.$v.form.passwordConfirmation.$dirty) return true; |
| 381 | return false; |
| 382 | }, |
| 383 | onOk(bvModalEvt) { |
| 384 | // prevent modal close |
| 385 | bvModalEvt.preventDefault(); |
| 386 | this.handleSubmit(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | }; |
| 390 | </script> |