{"version":3,"sources":["Pages/Login.js"],"names":["initializeLogin","formElement","loginUrl","clearFormErrors","i","elements","length","HTMLInputElement","classList","remove","loginContent","document","getElementById","Form","onbeforesubmit","done","window","location","data","path","fail","errorResponse","JSON","parse","err","responseText","console","log","type","error","properties","Object","getOwnPropertyNames","property","element","querySelector","add","initializeLoginAppSelect","redirecToV1","e","currentTarget","dataset","url","showLoginView","email","transition","value","passwordContainer","appSelector","setTimeout","focus","showPasswordForm","version1Column","addEventListener","version2Column","context","action","v1","v2","textContent","createdMonth","createdYear","builder","LoginViewBuilder","avatar","buildAvatar","name","buildAvatarInitials","color","insertBefore","extractInitials","_avatarId","_avatarImageId","_avatarInitialsId","_userCreatedDateId","_avatarImageTemplate","_createAvatarImage","_avatarInitialsTemplate","_createAvatarInitials","clone","cloneNode","firstElementChild","alt","src","title","avatarInitials","img","createElement","id","template","createDocumentFragment","appendChild","container","className","initials"],"mappings":";;;;;;;;;;;;;AA+DO,aAASA,eAAT,CAAyBC,WAAzB,EAAsCC,QAAtC,EAAgD;AACnD,iBAASC,eAAT,GAA2B;AACvB,iBAAK,IAAIC,IAAI,CAAb,EAAgBA,IAAIH,YAAYI,QAAZ,CAAqBC,MAAzC,EAAiDF,GAAjD,EAAsD;AAClD,oBAAI,EAAEH,YAAYI,QAAZ,CAAqBD,CAArB,aAAmCG,gBAArC,CAAJ,EACI;;AAEJN,4BAAYI,QAAZ,CAAqBD,CAArB,EAAwBI,SAAxB,CAAkCC,MAAlC,CAAyC,aAAzC;AACH;AACJ;;AAED,YAAMC,eAAeC,SAASC,cAAT,CAAwB,eAAxB,CAArB;;AAEA,YAAIC,IAAJ,CAASZ,WAAT,EAAsB;AAClBa,4BAAgB,0BAAM;AAClBX;AACA,uBAAO,IAAP;AACH,aAJiB;AAKlBY,kBAAM,oBAAQ;AAAEC,uBAAOC,QAAP,GAAkBC,KAAKC,IAAvB;AAA8B,aAL5B;AAMlBC,kBAAM,mBAAO;AACT,oBAAIC,gBAAgBC,KAAK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{ Form } from \"../Components/Forms.js\";\r\nimport { extractInitials } from \"../Components/Helpers.js\";\r\n\r\nclass LoginViewBuilder {\r\n constructor() {\r\n this._avatarId = \"v2-avatar\";\r\n this._avatarImageId = \"v2-avatar-image\";\r\n this._avatarInitialsId = \"v2-avatar-initials\";\r\n this._userCreatedDateId = \"v2-user-created\";\r\n\r\n this._avatarImageTemplate = this._createAvatarImage();\r\n this._avatarInitialsTemplate = this._createAvatarInitials();\r\n }\r\n\r\n buildAvatar(avatar, name) {\r\n let clone = this._avatarImageTemplate.cloneNode(true);\r\n\r\n clone.firstElementChild.alt = name;\r\n clone.firstElementChild.src = avatar;\r\n\r\n return clone;\r\n }\r\n\r\n buildAvatarInitials(color, name) {\r\n let clone = this._avatarInitialsTemplate.cloneNode(true);\r\n\r\n let avatar = clone.querySelector(`#${this._avatarId}`);\r\n avatar.classList.add(color);\r\n avatar.title = name;\r\n\r\n let avatarInitials = clone.querySelector(`#${this._avatarInitialsId}`);\r\n avatarInitials.textContent = extractInitials(name);\r\n\r\n return clone;\r\n }\r\n\r\n _createAvatarImage() {\r\n let img = document.createElement('img');\r\n img.id = this._avatarImageId;\r\n img.classList.add('avatar-image');\r\n\r\n let template = document.createDocumentFragment();\r\n template.appendChild(img);\r\n\r\n return template;\r\n }\r\n\r\n _createAvatarInitials() {\r\n let container = document.createElement('div');\r\n container.id = this._avatarId;\r\n container.className = 'user-avatar avatar-medium center-margin version-avatar';\r\n\r\n let initials = document.createElement('div');\r\n initials.id = this._avatarInitialsId;\r\n container.appendChild(initials);\r\n\r\n let template = document.createDocumentFragment();\r\n template.appendChild(container);\r\n\r\n return template;\r\n }\r\n}\r\n\r\nexport function initializeLogin(formElement, loginUrl) {\r\n function clearFormErrors() {\r\n for (let i = 0; i < formElement.elements.length; i++) {\r\n if (!(formElement.elements[i] instanceof HTMLInputElement))\r\n continue;\r\n\r\n formElement.elements[i].classList.remove('login-error');\r\n }\r\n }\r\n\r\n const loginContent = document.getElementById('login-content');\r\n\r\n new Form(formElement, {\r\n onbeforesubmit: () => {\r\n clearFormErrors();\r\n return true;\r\n },\r\n done: data => { window.location = data.path; },\r\n fail: err => {\r\n let errorResponse = JSON.parse(err.responseText);\r\n console.log(errorResponse);\r\n\r\n if (errorResponse.type === 'validation') {\r\n let error = errorResponse.error;\r\n let properties = Object.getOwnPropertyNames(error);\r\n\r\n for (let i = 0; i < properties.length; i++) {\r\n let property = properties[i];\r\n\r\n let element = loginContent.querySelector(`[name=${property}]`);\r\n if (element)\r\n element.classList.add('login-error');\r\n }\r\n }\r\n }\r\n });\r\n}\r\n\r\nexport function initializeLoginAppSelect(formElement, loginUrl) {\r\n function clearFormErrors() {\r\n for (let i = 0; i < formElement.elements.length; i++) {\r\n if (!(formElement.elements[i] instanceof HTMLInputElement))\r\n continue;\r\n\r\n formElement.elements[i].classList.remove('login-error');\r\n }\r\n }\r\n\r\n function redirecToV1(e) {\r\n window.location = e.currentTarget.dataset.url;\r\n }\r\n\r\n function showLoginView(email, transition) {\r\n clearFormErrors();\r\n\r\n loginContent.querySelector('[type=email]').value = email;\r\n\r\n let passwordContainer = loginContent.querySelector('#passwordElement');\r\n passwordContainer.classList.remove('hide');\r\n\r\n\r\n if (transition) {\r\n appSelector.classList.add('transition-out');\r\n setTimeout(() => {\r\n appSelector.classList.add('hide');\r\n appSelector.classList.remove('transition-out');\r\n\r\n loginContent.classList.remove('hide');\r\n loginContent.classList.add('transition-in');\r\n }, 250);\r\n } else {\r\n window.setTimeout(() => {\r\n passwordContainer.querySelector('input').focus();\r\n }, 10);\r\n }\r\n }\r\n\r\n function showPasswordForm(e) {\r\n showLoginView(e.currentTarget.dataset.email, true);\r\n }\r\n\r\n let loginContent = document.getElementById('login-content');\r\n loginContent.querySelector('[type=email]').focus();\r\n\r\n let appSelector = document.getElementById('appSelector');\r\n\r\n let version1Column = appSelector.querySelector('[data-version=\"1\"]');\r\n version1Column.addEventListener('click', redirecToV1, true);\r\n\r\n let version2Column = appSelector.querySelector('[data-version=\"2\"]');\r\n version2Column.addEventListener('click', showPasswordForm, true);\r\n\r\n new Form(formElement, {\r\n onbeforesubmit: () => {\r\n clearFormErrors();\r\n return true;\r\n },\r\n\r\n done: data => {\r\n if (formElement.dataset.context === 'version-select') {\r\n formElement.action = loginUrl;\r\n formElement.dataset.context = 'app-selection';\r\n\r\n if (data.v1) {\r\n if (!data.v2)\r\n window.location = version1Column.dataset.url;\r\n else {\r\n version2Column.dataset.email = data.email;\r\n\r\n version2Column.querySelector('#v2-user-created').textContent = `Created in ${data.createdMonth} of ${data.createdYear}`;\r\n\r\n let builder = new LoginViewBuilder();\r\n let avatar = data.avatar\r\n ? builder.buildAvatar(data.avatar, data.name)\r\n : builder.buildAvatarInitials(data.color, data.name);\r\n\r\n version2Column.insertBefore(avatar, version2Column.querySelector('.version-number'));\r\n\r\n loginContent.classList.add('transition-out');\r\n setTimeout(() => {\r\n loginContent.classList.add('hide');\r\n loginContent.classList.add('transitioned-out');\r\n loginContent.classList.remove('transition-out');\r\n\r\n appSelector.classList.remove('hide');\r\n appSelector.classList.add('transition-in');\r\n\r\n setTimeout(() => {\r\n appSelector.classList.add('transitioned-in');\r\n appSelector.classList.remove('transition-in');\r\n }, 250);\r\n\r\n }, 250);\r\n }\r\n }\r\n else {\r\n showLoginView(data.email);\r\n }\r\n }\r\n else {\r\n window.location = data.path;\r\n }\r\n },\r\n\r\n fail: err => {\r\n let errorResponse = JSON.parse(err.responseText);\r\n console.log(errorResponse);\r\n\r\n if (errorResponse.type === 'validation') {\r\n let error = errorResponse.error;\r\n let properties = Object.getOwnPropertyNames(error);\r\n\r\n for (let i = 0; i < properties.length; i++) {\r\n let property = properties[i];\r\n\r\n let element = loginContent.querySelector(`[name=${property}]`);\r\n if (element)\r\n element.classList.add('login-error');\r\n }\r\n }\r\n }\r\n });\r\n\r\n}\r\n"]}