| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2020-11-18 02:11:34 +00:00
										 |  |  |   <q-form @submit="save" @reset="reset"> | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     <q-card-section class="fit row justify-start content-center items-center"> | 
					
						
							|  |  |  |       <q-input | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.firstname" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							|  |  |  |         label="Vorname" | 
					
						
							|  |  |  |         :rules="[notEmpty]" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="given-name" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <q-input | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.lastname" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							|  |  |  |         label="Nachname" | 
					
						
							|  |  |  |         :rules="[notEmpty]" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="family-name" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <q-input | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.display_name" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							| 
									
										
										
										
											2020-11-15 18:47:05 +00:00
										 |  |  |         label="Angezeigter Name" | 
					
						
							|  |  |  |         :rules="[notEmpty]" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="nickname" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <q-input | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.mail" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							|  |  |  |         label="E-Mail" | 
					
						
							|  |  |  |         :rules="[isEmail, notEmpty]" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="email" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <q-input | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.userid" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							| 
									
										
										
										
											2020-11-15 18:47:05 +00:00
										 |  |  |         label="Benutzername" | 
					
						
							| 
									
										
										
										
											2021-01-30 07:38:44 +00:00
										 |  |  |         :readonly="!newUser" | 
					
						
							| 
									
										
										
										
											2021-03-31 18:24:01 +00:00
										 |  |  |         :rules="[isFreeUID, notEmpty]" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="username" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |       <q-select | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.roles" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							|  |  |  |         label="Rollen" | 
					
						
							|  |  |  |         filled | 
					
						
							|  |  |  |         multiple | 
					
						
							|  |  |  |         use-chips | 
					
						
							| 
									
										
										
										
											2020-11-06 00:31:46 +00:00
										 |  |  |         :readonly="!canSetRoles" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         :options="allRoles" | 
					
						
							|  |  |  |         option-label="name" | 
					
						
							|  |  |  |         option-value="name" | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2020-11-15 18:47:05 +00:00
										 |  |  |       <IsoDateInput | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         v-model="userModel.birthday" | 
					
						
							| 
									
										
										
										
											2021-02-01 23:48:33 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							| 
									
										
										
										
											2020-11-15 18:47:05 +00:00
										 |  |  |         label="Geburtstag" | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         autocomplete="bday" | 
					
						
							| 
									
										
										
										
											2020-11-15 18:47:05 +00:00
										 |  |  |       /> | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |       <q-file | 
					
						
							|  |  |  |         v-model="avatar" | 
					
						
							| 
									
										
										
										
											2021-02-01 23:48:33 +00:00
										 |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |         filled | 
					
						
							|  |  |  |         label="Avatar" | 
					
						
							|  |  |  |         accept=".jpg, image/*" | 
					
						
							| 
									
										
										
										
											2020-11-16 12:36:55 +00:00
										 |  |  |         max-file-size="204800" | 
					
						
							|  |  |  |         hint="Bilddateien, max. 200 KiB" | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |         @rejected="onAvatarRejected" | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2021-01-30 15:53:56 +00:00
										 |  |  |         <template #append> | 
					
						
							| 
									
										
										
										
											2020-11-18 02:11:34 +00:00
										 |  |  |           <q-icon name="mdi-file-image" @click.stop /> | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |         </template> | 
					
						
							|  |  |  |       </q-file> | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     </q-card-section> | 
					
						
							| 
									
										
										
										
											2021-01-30 07:38:44 +00:00
										 |  |  |     <q-separator v-if="!newUser" /> | 
					
						
							| 
									
										
										
										
											2021-02-01 23:48:33 +00:00
										 |  |  |     <q-card-section v-if="!newUser" class="fit row justify-start content-center items-center"> | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       <PasswordInput | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         v-if="isCurrentUser" | 
					
						
							| 
									
										
										
										
											2021-02-01 23:48:33 +00:00
										 |  |  |         v-model="password" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         :rules="[notEmpty]" | 
					
						
							|  |  |  |         filled | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         label="Passwort" | 
					
						
							|  |  |  |         autocomplete="current-password" | 
					
						
							|  |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							|  |  |  |         hint="Passwort muss immer eingetragen werden" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       /> | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       <PasswordInput | 
					
						
							|  |  |  |         v-model="newPassword" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         filled | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |         label="Neues Password" | 
					
						
							|  |  |  |         autocomplete="new-password" | 
					
						
							|  |  |  |         class="col-xs-12 col-sm-6 q-pa-sm" | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       /> | 
					
						
							|  |  |  |     </q-card-section> | 
					
						
							|  |  |  |     <q-card-actions align="right"> | 
					
						
							| 
									
										
										
										
											2020-11-18 02:11:34 +00:00
										 |  |  |       <q-btn label="Reset" type="reset" /> | 
					
						
							|  |  |  |       <q-btn color="primary" type="submit" label="Speichern" /> | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     </q-card-actions> | 
					
						
							|  |  |  |   </q-form> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  | import { Notify } from 'quasar'; | 
					
						
							| 
									
										
										
										
											2021-01-30 15:53:56 +00:00
										 |  |  | import { hasPermission } from 'src/utils/permission'; | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  | import { notEmpty, isEmail } from 'src/utils/validators'; | 
					
						
							| 
									
										
										
										
											2021-01-30 15:53:56 +00:00
										 |  |  | import IsoDateInput from 'src/components/utils/IsoDateInput.vue'; | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  | import PasswordInput from 'src/components/utils/PasswordInput.vue'; | 
					
						
							| 
									
										
										
										
											2021-02-02 00:28:23 +00:00
										 |  |  | import { defineComponent, computed, ref, onBeforeMount, PropType } from 'vue'; | 
					
						
							| 
									
										
										
										
											2021-02-02 21:32:23 +00:00
										 |  |  | import { useUserStore } from '../../store'; | 
					
						
							| 
									
										
										
										
											2021-03-29 22:28:18 +00:00
										 |  |  | import { useMainStore } from 'src/stores'; | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   name: 'MainUserSettings', | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |   components: { IsoDateInput, PasswordInput }, | 
					
						
							| 
									
										
										
										
											2020-11-12 21:48:19 +00:00
										 |  |  |   props: { | 
					
						
							| 
									
										
										
										
											2021-01-30 15:53:56 +00:00
										 |  |  |     user: { | 
					
						
							|  |  |  |       required: true, | 
					
						
							| 
									
										
										
										
											2021-02-02 00:28:23 +00:00
										 |  |  |       type: Object as PropType<FG.User>, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-01-30 15:53:56 +00:00
										 |  |  |     newUser: { type: Boolean, required: true }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   emits: { | 
					
						
							|  |  |  |     'update:user': (payload: FG.User) => !!payload, | 
					
						
							| 
									
										
										
										
											2020-11-12 21:48:19 +00:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-01-30 07:38:44 +00:00
										 |  |  |   setup(props, { emit }) { | 
					
						
							| 
									
										
										
										
											2021-02-02 21:32:23 +00:00
										 |  |  |     const userStore = useUserStore(); | 
					
						
							|  |  |  |     const mainStore = useMainStore(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     onBeforeMount(() => { | 
					
						
							| 
									
										
										
										
											2021-02-02 21:32:23 +00:00
										 |  |  |       void userStore.getRoles(false); | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |     const password = ref(''); | 
					
						
							|  |  |  |     const newPassword = ref(''); | 
					
						
							|  |  |  |     const avatar = ref<string[]>([]); | 
					
						
							|  |  |  |     const userModel = ref(props.user); | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-30 07:38:44 +00:00
										 |  |  |     const canSetRoles = computed(() => hasPermission('users_set_roles')); | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |     const allRoles = computed(() => userStore.roles.map((role) => role.name)); | 
					
						
							|  |  |  |     const isCurrentUser = computed(() => userModel.value.userid === mainStore.currentUser.userid); | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |     function onAvatarRejected() { | 
					
						
							|  |  |  |       Notify.create({ | 
					
						
							| 
									
										
										
										
											2020-11-16 12:44:38 +00:00
										 |  |  |         group: false, | 
					
						
							|  |  |  |         type: 'negative', | 
					
						
							|  |  |  |         message: 'Datei zu groß oder keine gültige Bilddatei.', | 
					
						
							|  |  |  |         timeout: 10000, | 
					
						
							|  |  |  |         progress: true, | 
					
						
							| 
									
										
										
										
											2021-03-18 16:23:57 +00:00
										 |  |  |         actions: [{ icon: 'mdi-close', color: 'white' }], | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-11-17 23:27:44 +00:00
										 |  |  |       avatar.value = []; | 
					
						
							| 
									
										
										
										
											2020-11-16 01:28:03 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     function save() { | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       let changed = userModel.value; | 
					
						
							| 
									
										
										
										
											2021-01-21 15:23:40 +00:00
										 |  |  |       if (typeof changed.birthday === 'string') changed.birthday = new Date(changed.birthday); | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       changed = Object.assign(changed, { | 
					
						
							| 
									
										
										
										
											2021-03-18 16:23:57 +00:00
										 |  |  |         password: password.value, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       if (newPassword.value != '') { | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         changed = Object.assign(changed, { | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |           new_password: newPassword.value, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-11-12 21:48:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       emit('update:user', changed); | 
					
						
							| 
									
										
										
										
											2020-11-18 02:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-21 15:23:40 +00:00
										 |  |  |       if (avatar.value && (avatar.value.length > 0 || avatar.value instanceof File)) | 
					
						
							| 
									
										
										
										
											2021-02-02 21:32:23 +00:00
										 |  |  |         userStore.uploadAvatar(changed, avatar.value[0]).catch((response: Response) => { | 
					
						
							|  |  |  |           if (response && response.status == 400) { | 
					
						
							|  |  |  |             onAvatarRejected(); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-11-17 23:27:44 +00:00
										 |  |  |       reset(); | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function reset() { | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       userModel.value = props.user; | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       password.value = ''; | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       newPassword.value = ''; | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-31 18:24:01 +00:00
										 |  |  |     function isFreeUID(val: string) { | 
					
						
							| 
									
										
										
										
											2020-11-12 21:48:19 +00:00
										 |  |  |       return ( | 
					
						
							| 
									
										
										
										
											2021-03-31 18:24:01 +00:00
										 |  |  |         userStore.users.findIndex((user) => user.userid === val) === -1 || | 
					
						
							| 
									
										
										
										
											2020-11-12 21:48:19 +00:00
										 |  |  |         'Benutzername ist schon vergeben' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     return { | 
					
						
							|  |  |  |       allRoles, | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       avatar, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       canSetRoles, | 
					
						
							|  |  |  |       isCurrentUser, | 
					
						
							|  |  |  |       isEmail, | 
					
						
							| 
									
										
										
										
											2021-03-31 18:24:01 +00:00
										 |  |  |       isFreeUID, | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       newPassword, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |       notEmpty, | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       onAvatarRejected, | 
					
						
							|  |  |  |       password, | 
					
						
							| 
									
										
										
										
											2021-03-18 16:23:57 +00:00
										 |  |  |       reset, | 
					
						
							| 
									
										
										
										
											2021-03-31 15:22:55 +00:00
										 |  |  |       save, | 
					
						
							|  |  |  |       userModel, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-03-18 16:23:57 +00:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-11-06 00:17:04 +00:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |