Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 2 | <b-modal id="modal-user" ref="modal" @ok="onOk" @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 | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 11 | <b-form novalidate @submit="handleSubmit"> |
| 12 | <b-container> |
| 13 | <b-row> |
| 14 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 15 | <b-form-group |
| 16 | :label="$t('pageLocalUserManagement.modal.accountStatus')" |
| 17 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 18 | <b-form-radio |
| 19 | v-model="form.status" |
| 20 | name="user-status" |
| 21 | :value="true" |
| 22 | @input="$v.form.status.$touch()" |
| 23 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 24 | {{ $t('global.status.enabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 25 | </b-form-radio> |
| 26 | <b-form-radio |
| 27 | v-model="form.status" |
| 28 | name="user-status" |
| 29 | :value="false" |
| 30 | @input="$v.form.status.$touch()" |
| 31 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 32 | {{ $t('global.status.disabled') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 33 | </b-form-radio> |
| 34 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 35 | <b-form-group |
| 36 | :label="$t('pageLocalUserManagement.modal.username')" |
| 37 | label-for="username" |
| 38 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 39 | <b-form-text id="username-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 40 | {{ $t('pageLocalUserManagement.modal.cannotStartWithANumber') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 41 | <br /> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 42 | {{ |
| 43 | $t( |
| 44 | 'pageLocalUserManagement.modal.noSpecialCharactersExceptUnderscore' |
| 45 | ) |
| 46 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 47 | </b-form-text> |
| 48 | <b-form-input |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 49 | id="username" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 50 | v-model="form.username" |
| 51 | type="text" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 52 | aria-describedby="username-help-block" |
| 53 | :state="getValidationState($v.form.username)" |
| 54 | :disabled="!newUser && originalUsername === 'root'" |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 55 | @input="$v.form.username.$touch()" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 56 | /> |
| 57 | <b-form-invalid-feedback role="alert"> |
| 58 | <template v-if="!$v.form.username.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 59 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 60 | </template> |
| 61 | <template v-else-if="!$v.form.username.maxLength"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 62 | {{ |
| 63 | $t('global.form.lengthMustBeBetween', { min: 1, max: 16 }) |
| 64 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 65 | </template> |
| 66 | <template v-else-if="!$v.form.username.pattern"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 67 | {{ $t('global.form.invalidFormat') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 68 | </template> |
| 69 | </b-form-invalid-feedback> |
| 70 | </b-form-group> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 71 | <b-form-group |
| 72 | :label="$t('pageLocalUserManagement.modal.privilege')" |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 73 | label-for="privilege" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 74 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 75 | <b-form-select |
Yoshie Muranaka | a4b9e40 | 2020-03-06 14:59:46 -0800 | [diff] [blame] | 76 | id="privilege" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 77 | v-model="form.privilege" |
| 78 | :options="privilegeTypes" |
| 79 | :state="getValidationState($v.form.privilege)" |
| 80 | @input="$v.form.privilege.$touch()" |
| 81 | > |
| 82 | </b-form-select> |
| 83 | <b-form-invalid-feedback role="alert"> |
| 84 | <template v-if="!$v.form.privilege.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 85 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 86 | </template> |
| 87 | </b-form-invalid-feedback> |
| 88 | </b-form-group> |
| 89 | </b-col> |
| 90 | <b-col> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 91 | <b-form-group |
| 92 | :label="$t('pageLocalUserManagement.modal.userPassword')" |
| 93 | label-for="password" |
| 94 | > |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 95 | <b-form-text id="password-help-block"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 96 | {{ |
| 97 | $t('pageLocalUserManagement.modal.passwordMustBeBetween', { |
| 98 | min: passwordRequirements.minLength, |
| 99 | max: passwordRequirements.maxLength |
| 100 | }) |
| 101 | }} |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 102 | </b-form-text> |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 103 | <input-password-toggle> |
| 104 | <b-form-input |
| 105 | id="password" |
| 106 | v-model="form.password" |
| 107 | type="password" |
| 108 | aria-describedby="password-help-block" |
| 109 | :state="getValidationState($v.form.password)" |
| 110 | @input="$v.form.password.$touch()" |
| 111 | /> |
| 112 | <b-form-invalid-feedback role="alert"> |
| 113 | <template v-if="!$v.form.password.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 114 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 115 | </template> |
| 116 | <template |
| 117 | v-if=" |
| 118 | !$v.form.password.minLength || !$v.form.password.maxLength |
| 119 | " |
| 120 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 121 | {{ |
| 122 | $t( |
| 123 | 'pageLocalUserManagement.modal.passwordMustBeBetween', |
| 124 | { |
| 125 | min: passwordRequirements.minLength, |
| 126 | max: passwordRequirements.maxLength |
| 127 | } |
| 128 | ) |
| 129 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 130 | </template> |
| 131 | </b-form-invalid-feedback> |
| 132 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 133 | </b-form-group> |
| 134 | <b-form-group |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 135 | :label="$t('pageLocalUserManagement.modal.confirmUserPassword')" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 136 | label-for="password-confirmation" |
| 137 | > |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 138 | <input-password-toggle> |
| 139 | <b-form-input |
| 140 | id="password-confirmation" |
| 141 | v-model="form.passwordConfirmation" |
| 142 | type="password" |
| 143 | :state="getValidationState($v.form.passwordConfirmation)" |
| 144 | @input="$v.form.passwordConfirmation.$touch()" |
| 145 | /> |
| 146 | <b-form-invalid-feedback role="alert"> |
| 147 | <template v-if="!$v.form.passwordConfirmation.required"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 148 | {{ $t('global.form.fieldRequired') }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 149 | </template> |
| 150 | <template |
| 151 | v-else-if="!$v.form.passwordConfirmation.sameAsPassword" |
| 152 | > |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 153 | {{ |
| 154 | $t('pageLocalUserManagement.modal.passwordsDoNotMatch') |
| 155 | }} |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 156 | </template> |
| 157 | </b-form-invalid-feedback> |
| 158 | </input-password-toggle> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 159 | </b-form-group> |
| 160 | </b-col> |
| 161 | </b-row> |
| 162 | </b-container> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 163 | </b-form> |
| 164 | <template v-slot:modal-ok> |
| 165 | <template v-if="newUser"> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 166 | {{ $t('pageLocalUserManagement.addUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 167 | </template> |
| 168 | <template v-else> |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 169 | {{ $t('global.action.save') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 170 | </template> |
| 171 | </template> |
| 172 | </b-modal> |
| 173 | </template> |
| 174 | |
| 175 | <script> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 176 | import { |
| 177 | required, |
| 178 | maxLength, |
| 179 | minLength, |
| 180 | sameAs, |
| 181 | helpers, |
| 182 | requiredIf |
| 183 | } from 'vuelidate/lib/validators'; |
| 184 | import VuelidateMixin from '../../../components/Mixins/VuelidateMixin.js'; |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 185 | import InputPasswordToggle from '../../../components/Global/InputPasswordToggle'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 186 | |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 187 | export default { |
Yoshie Muranaka | 4ee8d29 | 2020-02-20 07:29:58 -0800 | [diff] [blame] | 188 | components: { InputPasswordToggle }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 189 | mixins: [VuelidateMixin], |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 190 | props: { |
| 191 | user: { |
| 192 | type: Object, |
| 193 | default: null |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 194 | }, |
| 195 | passwordRequirements: { |
| 196 | type: Object, |
| 197 | required: true |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 198 | } |
| 199 | }, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 200 | data() { |
| 201 | return { |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 202 | privilegeTypes: ['Administrator', 'Operator', 'ReadOnly', 'NoAccess'], |
| 203 | originalUsername: '', |
| 204 | form: { |
| 205 | status: true, |
| 206 | username: '', |
| 207 | privilege: '', |
| 208 | password: '', |
| 209 | passwordConfirmation: '' |
| 210 | } |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 211 | }; |
| 212 | }, |
| 213 | computed: { |
| 214 | newUser() { |
| 215 | return this.user ? false : true; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 216 | } |
| 217 | }, |
| 218 | watch: { |
| 219 | user: function(value) { |
| 220 | if (value === null) return; |
| 221 | this.originalUsername = value.username; |
| 222 | this.form.username = value.username; |
| 223 | this.form.status = value.Enabled; |
| 224 | this.form.privilege = value.privilege; |
| 225 | } |
| 226 | }, |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 227 | validations() { |
| 228 | return { |
| 229 | form: { |
| 230 | status: { |
| 231 | required |
| 232 | }, |
| 233 | username: { |
| 234 | required, |
| 235 | maxLength: maxLength(16), |
| 236 | pattern: helpers.regex('pattern', /^([a-zA-Z_][a-zA-Z0-9_]*)/) |
| 237 | }, |
| 238 | privilege: { |
| 239 | required |
| 240 | }, |
| 241 | password: { |
| 242 | required: requiredIf(function() { |
| 243 | return this.requirePassword(); |
| 244 | }), |
| 245 | minLength: minLength(this.passwordRequirements.minLength), |
| 246 | maxLength: maxLength(this.passwordRequirements.maxLength) |
| 247 | }, |
| 248 | passwordConfirmation: { |
| 249 | required: requiredIf(function() { |
| 250 | return this.requirePassword(); |
| 251 | }), |
| 252 | sameAsPassword: sameAs('password') |
| 253 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 254 | } |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 255 | }; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 256 | }, |
| 257 | methods: { |
| 258 | handleSubmit() { |
| 259 | let userData = {}; |
| 260 | |
| 261 | if (this.newUser) { |
| 262 | this.$v.$touch(); |
| 263 | if (this.$v.$invalid) return; |
| 264 | userData.username = this.form.username; |
| 265 | userData.status = this.form.status; |
| 266 | userData.privilege = this.form.privilege; |
| 267 | userData.password = this.form.password; |
| 268 | } else { |
| 269 | if (this.$v.$invalid) return; |
| 270 | userData.originalUsername = this.originalUsername; |
| 271 | if (this.$v.form.status.$dirty) { |
| 272 | userData.status = this.form.status; |
| 273 | } |
| 274 | if (this.$v.form.username.$dirty) { |
| 275 | userData.username = this.form.username; |
| 276 | } |
| 277 | if (this.$v.form.privilege.$dirty) { |
| 278 | userData.privilege = this.form.privilege; |
| 279 | } |
| 280 | if (this.$v.form.password.$dirty) { |
| 281 | userData.password = this.form.password; |
| 282 | } |
| 283 | if (Object.entries(userData).length === 1) { |
| 284 | this.closeModal(); |
| 285 | return; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | this.$emit('ok', { isNewUser: this.newUser, userData }); |
| 290 | this.closeModal(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 291 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 292 | closeModal() { |
| 293 | this.$nextTick(() => { |
| 294 | this.$refs.modal.hide(); |
| 295 | }); |
| 296 | }, |
| 297 | resetForm() { |
| 298 | this.form.originalUsername = ''; |
| 299 | this.form.status = true; |
| 300 | this.form.username = ''; |
| 301 | this.form.privilege = ''; |
| 302 | this.form.password = ''; |
| 303 | this.form.passwordConfirmation = ''; |
| 304 | this.$v.$reset(); |
| 305 | }, |
| 306 | requirePassword() { |
| 307 | if (this.newUser) return true; |
| 308 | if (this.$v.form.password.$dirty) return true; |
| 309 | if (this.$v.form.passwordConfirmation.$dirty) return true; |
| 310 | return false; |
| 311 | }, |
| 312 | onOk(bvModalEvt) { |
| 313 | // prevent modal close |
| 314 | bvModalEvt.preventDefault(); |
| 315 | this.handleSubmit(); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | }; |
| 319 | </script> |