$(document).ready(function () { const params = new URLSearchParams(window.location.search); if (params.has("invitationCode") == false) { setRegistrationPage(); } updateReturnUrl(); $('#profileType').on('change', function() { updateReturnUrl(); }); $('#SubmitButton').on('click', function (event) { var profileType = $('#profileType').val(); // Set cookie instead of sessionStorage - works across domains document.cookie = 'registrationProfileType=' + profileType + '; path=/; max-age=300'; createUserRegistration(); }); }); function updateReturnUrl() { var profileType = $('#profileType').val(); var url = new URL(window.location.href); if (profileType == 124430000) url.searchParams.set('returnUrl', '/portalprofile'); else if (profileType == 124430001) url.searchParams.set('returnUrl', '/my-applications'); else url.searchParams.set('returnUrl', '/'); window.history.replaceState({}, '', url.toString()); } function setRegistrationPage() { $(`
`).insertAfter($('#ConfirmPasswordTextBox').closest('.row')); } function createUserRegistration() { if (!Page_ClientValidate()) return; var record = {}; record.lw_emailaddress = $('#EmailTextBox').val(); record.lw_profiletype = $('#profileType option:selected').val(); record.lw_domain = getSubdomain(); webapi.safeAjax({ type: "POST", contentType: "application/json", url: "/_api/lw_userregistrations", data: JSON.stringify(record), success: function (data, textStatus, xhr) { var newId = xhr.getResponseHeader("entityid"); console.log(newId); }, error: function (xhr, textStatus, errorThrown) { console.log(xhr); } }); } function inJectprofileValidator() { if (typeof (Page_Validators) == 'undefined') return; var profileValidator = document.createElement('span'); profileValidator.style.display = "none"; profileValidator.id = "applydateValidator"; profileValidator.controltovalidate = "profileType"; profileValidator.errormessage = "Please select a Profile Type"; profileValidator.validationGroup = ""; profileValidator.initialvalue = ""; profileValidator.evaluationfunction = function () { if ($('#profileType option:selected').val() == '') { profileValidator.errormessage = "Please select a Profile Type"; return false; } else return true; }; Page_Validators.push(profileValidator); } function getSubdomain() { const parts = window.location.hostname.split('.'); return parts.length > 2 ? parts[0] : ''; }