| |
|
|
| import { StateManager } from '../services/state-manager.js'; |
|
|
| export const ProfileComponent = { |
| elements: { |
| profileModal: null, |
| profileBtn: null, |
| ageGroupInput: null, |
| genderInput: null, |
| roleInputs: null, |
| participantInput: null, |
| welcomePopup: null |
| }, |
|
|
| |
| |
| |
| init() { |
| this.elements.profileModal = document.getElementById('profile-modal'); |
| this.elements.profileBtn = document.getElementById('profileBtn'); |
| this.elements.ageGroupInput = document.getElementById('age-group'); |
| this.elements.genderInput = document.getElementById('gender'); |
| this.elements.roleInputs = document.querySelectorAll('input[name="role"]'); |
| this.elements.participantInput = document.getElementById('participant-id'); |
| this.elements.welcomePopup = document.getElementById('welcomePopup'); |
|
|
| this.attachEventListeners(); |
| }, |
|
|
| |
| |
| |
| attachEventListeners() { |
| |
| this.elements.genderInput.addEventListener('click', () => this.checkProfileValidity()); |
| this.elements.ageGroupInput.addEventListener('click', () => this.checkProfileValidity()); |
| this.elements.roleInputs.forEach(input => |
| input.addEventListener('change', () => this.checkProfileValidity()) |
| ); |
| this.elements.participantInput.addEventListener('input', () => this.checkParticipantIdInput()); |
| this.elements.participantInput.addEventListener('input', () => this.checkProfileValidity()); |
|
|
| |
| this.elements.profileBtn.addEventListener('click', () => this.submitProfile()); |
| }, |
|
|
| |
| |
| |
| checkProfileValidity() { |
| |
| const genderSelected = this.elements.genderInput.value !== ''; |
|
|
| |
| const ageSelected = this.elements.ageGroupInput.value !== ''; |
|
|
| |
| const roleSelected = Array.from(this.elements.roleInputs).some(input => input.checked); |
|
|
| |
| const participantIdEntered = this.elements.participantInput.value.trim().length > 0; |
|
|
| |
| if (genderSelected && ageSelected && roleSelected && participantIdEntered) { |
| this.elements.profileBtn.disabled = false; |
| this.elements.profileBtn.classList.replace('disabled-button', 'ok-button'); |
| } else { |
| this.elements.profileBtn.disabled = true; |
| this.elements.profileBtn.classList.replace('ok-button', 'disabled-button'); |
| } |
| }, |
|
|
| |
| |
| |
| submitProfile() { |
| const profileData = { |
| ageGroup: this.elements.ageGroupInput.value, |
| gender: this.elements.genderInput.value, |
| roles: Array.from(document.querySelectorAll('input[name="role"]:checked')).map(input => input.value), |
| participantId: this.elements.participantInput.value.trim() |
| }; |
|
|
| StateManager.updateProfile(profileData); |
|
|
| |
| this.elements.welcomePopup.style.display = 'none'; |
| document.body.classList.remove('no-scroll'); |
| }, |
|
|
| checkParticipantIdInput() { |
| const input = this.elements.participantInput; |
| |
| const start = input.selectionStart; |
| const end = input.selectionEnd; |
|
|
| |
| const newValue = input.value.replace(/[^-a-zA-Z0-9_]/g, ''); |
|
|
| |
| if (input.value !== newValue) { |
| input.value = newValue; |
| |
| input.setSelectionRange(start - 1, end - 1); |
| } |
| } |
| }; |