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