{"version":3,"sources":["webpack:///./widgets/myAccountUpdateProfilePage.js"],"names":["MyAccountUpdateProfilePage","element","_classCallCheck","this","$element","$","$scroller","countryAPI","data","registerAPI","$errorMessagesServerSide","find","$sucessMessages","countries","$form","concat","$formValidate","loadCountries","buildForm","selectEvents","resetForm","key","value","_this","ajax","type","url","headers","siteTypeId","success","$countrySelect","append","markup","forEach","country","Name","setTimeout","selectpicker","error","offset","arguments","length","undefined","scrollTo","top","position","duration","easing","_this2","on","event","currentTarget","blur","focus","formGroupElements","woolmarkContactTypeLicence","woolmarkContactTypeOther","val","show","hide","areaStudyOther","removeClass","message","addClass","text","_this3","validator","addMethod","_element","RegExp","regexPassword","test","each","_index","attr","_","isNil","hasClass","window","location","validate","submitHandler","form","preventDefault","array","serializeArray","formData","map","n","i","forOwn","trim","json_text","JSON","stringify","request","Request","method","body","fetch","then","response","status","handleServerSideError","statusText","invalidHandler","errorList","parent","scrollToElement","ignore","rules","Salutation","required","FirstName","LastName","Email","email","Country","EducationLevel","OverMinimumAge","TermsAndConditions","messages","errorClass","errorElement","errorPlacement","is","parents","after","insertAfter","highlight","unhighlight"],"mappings":"g3BAAA,IAGaA,EAA0B,WAkBrC,O,EAjBD,SAAAA,EAAYC,I,4FAASC,CAAA,KAAAF,GACpBG,KAAKF,QAAUA,EACfE,KAAKC,SAAWC,EAAEF,KAAKF,SACvBE,KAAKG,UAAYD,EAAE,iBACnBF,KAAKI,WAAaJ,KAAKC,SAASI,KAAK,cACrCL,KAAKM,YAAcN,KAAKC,SAASI,KAAK,eACtCL,KAAKO,yBAA2BP,KAAKC,SAASO,KAAK,+BACnDR,KAAKS,gBAAkBT,KAAKC,SAASO,KAAK,qBAC1CR,KAAKU,UAAY,GACjBV,KAAKW,MAAQT,EAAE,IAADU,OAZJ,6BAYY,UACtBZ,KAAKa,cACDb,KAAKI,YACRJ,KAAKc,gBAENd,KAAKe,YACLf,KAAKgB,eACLhB,KAAKiB,c,EACL,EAAAC,IAAA,gBAAAC,MA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XE,SAAU,CACTF,SAAU,6BAEXG,MAAO,CACNH,SAAU,iCACVI,MAAO,uCAERC,QAAS,CACRL,SAAU,4BAEXQ,mBAAoB,CACnBR,SAAU,8CAGZU,WAAY,gCACZC,aAAc,OACdC,eAAgB,SAACtF,EAAOrC,GACpBI,EAAEJ,GAAS4H,GAAG,UAChBxH,EAAEJ,GAAS6H,QAAQ,qBAAqBC,MAAMzF,GAG9CA,EAAM0F,YAAY/H,IAGpBgI,UAAW,SAAChI,GACXI,EAAEJ,GAAS8D,SAAS,cAAcF,YAAY,aAE/CqE,YAAa,SAACjI,GACbI,EAAEJ,GAAS8D,SAAS,YAAYF,YAAY,sB,0FAhRT,I","file":"89.js","sourcesContent":["const NS = 'MyAccountUpdateProfilePage';\nconst CLS = 'myAccountUpdateProfilePage';\n\nexport class MyAccountUpdateProfilePage {\n\tconstructor(element) {\n\t\tthis.element = element;\n\t\tthis.$element = $(this.element);\n\t\tthis.$scroller = $('.tpl-scroller');\n\t\tthis.countryAPI = this.$element.data('countryApi');\n\t\tthis.registerAPI = this.$element.data('registerApi');\n\t\tthis.$errorMessagesServerSide = this.$element.find('.error-messages--serverSide');\n\t\tthis.$sucessMessages = this.$element.find('.success-messages');\n\t\tthis.countries = [];\n\t\tthis.$form = $(`#${CLS}-form`);\n\t\tthis.$formValidate;\n\t\tif (this.countryAPI) {\n\t\t\tthis.loadCountries();\n\t\t}\n\t\tthis.buildForm();\n\t\tthis.selectEvents();\n\t\tthis.resetForm();\n\t}\n\n\n\n\tloadCountries() {\n\t\t$.ajax({\n\t\t\ttype: 'GET',\n\t\t\turl: this.countryAPI,\n\t\t\theaders: {\n\t\t\t\t'X-IDS-SiteTypeId': this.siteTypeId\n\t\t\t},\n\t\t\tsuccess: (data) => {\n\t\t\t\tthis.countries = data;\n\n\t\t\t\tlet $countrySelect = this.$element.find('select.country');\n\t\t\t\t$countrySelect.append(() => {\n\t\t\t\t\tlet markup = '';\n\t\t\t\t\tthis.countries.forEach((country) => {\n\t\t\t\t\t\tmarkup += ``;\n\t\t\t\t\t});\n\t\t\t\t\treturn markup;\n\t\t\t\t});\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t$countrySelect.selectpicker('refresh');\n\t\t\t\t\t$countrySelect.selectpicker('render');\n\t\t\t\t\tthis.resetForm(); // When countries is changed it sets it ot is-valid, reset said form to prevent this\n\t\t\t\t}, 100);\n\t\t\t},\n\t\t\terror: () => {\n\t\t\t\tconsole.error(`${NS}::Error`, 'Could not load the list of countries');\n\t\t\t}\n\t\t});\n\t}\n\n\tscrollToElement(element, offset = 0) {\n\t\treturn scrollTo(this.$scroller[0], { top: $(element).position().top + offset, duration: 500, easing: 'ease-in-out' });\n\t}\n\n\tselectEvents() {\n\t\tthis.$element.find('select').on('change', (event) => {\n\t\t\t$(event.currentTarget).blur().focus();\n\t\t});\n\n\t\tlet formGroupElements = {\n\t\t\twoolmarkContactTypeLicence: this.$element.find('.woolmarkContactTypeLicence'),\n\t\t\twoolmarkContactTypeOther: this.$element.find('.woolmarkContactTypeOther'),\n\t\t};\n\n\t\t// Deals with on change for education level\n\t\tthis.$element.find('select.woolmarkContactType').on('change', (event) => {\n\t\t\tif(this.$element.find('select.woolmarkContactType').val() === 'Other') {\n\t\t\t\tformGroupElements.woolmarkContactTypeOther.show();\n\t\t\t}\n\t\t\telse{\n\t\t\t\tformGroupElements.woolmarkContactTypeOther.hide();\n\t\t\t}\n\t\t\tif(this.$element.find('select.woolmarkContactType').val() === 'Woolmark Licensee') {\n\t\t\t\tformGroupElements.woolmarkContactTypeLicence.show();\n\t\t\t}\n\t\t\telse{\n\t\t\t\tformGroupElements.woolmarkContactTypeLicence.hide();\n\t\t\t}\n\t\t});\n\n\t\t// Deals with change for area of study\n\t\tthis.$element.find('select.areaStudy').on('change', (event) => {\n\t\t\tif($(event.currentTarget).val() === 'Other') {\n\t\t\t\tformGroupElements.areaStudyOther.show();\n\t\t\t}\n\t\t\telse {\n\t\t\t\tformGroupElements.areaStudyOther.hide().find('#AreaStudyOther').val('').removeClass('is-valid is-invalid');\n\t\t\t}\n\t\t});\n\t}\n\n\thandleServerSideError(message) {\n\t\tthis.$errorMessagesServerSide.addClass('is-active').text(message);\n\t}\n\n\tresetForm() {\n\t\tthis.$form.removeClass('is-submitted');\n\t\tthis.$formValidate.resetForm();\n\t}\n\t\n\t/**\n\t * Implements the form and form validation using jQuery validation: https://jqueryvalidation.org/\n\t */\n\tbuildForm() {\n\t\t$.validator.addMethod('password', (value, _element) => {\n\t\t\treturn new RegExp(this.regexPassword).test(value);\n\t\t}, `Please enter a password that contains 8–20 characters, at least one capital letter, one number, and one special character [- ! @ # $ % ^ & * ( ) _ +].`);\n\n\t\t$(`select.slctpckr`).each((_index, element) => {\n\t\t\t// Enable default selected value by passing the data-value in the select\n\t\t\tlet $element = $(element);\n\t\t\tlet value = $element.attr('data-value');\n\t\t\t$element.selectpicker();\n\t\n\t\t\tif(!_.isNil(value)) {\n\t\t\t\t$element.selectpicker('val', value);\n\t\t\t\t$element.selectpicker('refresh');\n\t\t\t}\n\t\n\t\t\t// Update value attr\n\t\t\t$element.on('changed.bs.select', () => {\n\t\t\t\tlet value = $element.selectpicker().val();\n\t\t\t\t$element.attr('data-value', value);\n\t\n\t\t\t\t// if language selector, redirect to link\n\t\t\t\tif ($element.hasClass('siteLanguageWidget-languageSelect')) {\n\t\t\t\t\twindow.location = value;\n\t\t\t\t}\n\t\t\t});\n\t\n\t\t\t$element.on('refreshed.bs.select', () => {\n\t\t\t\tvalue = $element.attr('data-value');\n\t\n\t\t\t\tif(!_.isNil(value)) {\n\t\t\t\t\t$element.selectpicker('val', value);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t\t\n\t\tthis.$formValidate = this.$form.validate({\n\t\t\tsubmitHandler: (form, event) => {\n\t\t\t\tthis.$errorMessagesServerSide.removeClass('is-active').text('');\n\t\t\t\t$(event.currentTarget).addClass('is-submitted');\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\tvar array = $(form).serializeArray()\n\t\t\t\tvar formData = {};\n\t\t\t\t$.map(array, function (n, i) {\n\t\t\t\t\tformData[n['name']] = n['value'];\n\t\t\t\t});\n\n\t\t\t\t// Removes empty field values\n\t\t\t\t_.forOwn(formData, (value, key) => {\n\t\t\t\t\tif(_.isNil(value) || value.trim() === '') {\n\t\t\t\t\t\tdelete formData[key];\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\tvar json_text = JSON.stringify(formData); \n\n\t\t\t\tlet request = new Request(this.registerAPI, {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\tbody: json_text,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t'Content-Type': 'application/json'\n\t\t\t\t\t}\n\t\t\t\t});\n\n\t\t\t\t//this.fullScreenLoaderService.create();\n\n\t\t\t\t// submit form data using fetch api\n\t\t\t\tfetch(request)\n\t\t\t\t\t.then((response) => {\n\t\t\t\t\t\tif(response.status === 200) {\n\t\t\t\t\t\t\tthis.$sucessMessages.show();\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis.handleServerSideError(response.statusText);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t//this.fullScreenLoaderService.destroy();\n\t\t\t\t\t})\n\t\t\t\t\t.catch((error) => {\n\t\t\t\t\t\t// errors (failed call)\n\t\t\t\t\t\tthis.handleServerSideError(error);\n\t\t\t\t\t\t//this.fullScreenLoaderService.destroy();\n\t\t\t\t\t});\n\t\t\t},\n\t\t\tinvalidHandler: (event, validator) => {\n\t\t\t\t$(event.currentTarget).addClass('is-submitted');\n\t\t\t\tif(validator.errorList[0]) {\n\t\t\t\t\tlet element = validator.errorList[0].element;\n\t\t\t\t\t// Caveat for custom-control (radio + checkbox) as the element itself is absolutely positioned.\n\t\t\t\t\t// Scroll to the parent element of it instead.\n\t\t\t\t\tif($(element).parent('.custom-control') && $(element).parent('.custom-control').length > 0) {\n\t\t\t\t\t\tthis.scrollToElement($(element).parent('.custom-control')[0], -60);\n\t\t\t\t\t}\n\t\t\t\t\t// Second caveat for custom bootstrap select (generated) content\n\t\t\t\t\t// Also scroll to the parent element of the select instead\n\t\t\t\t\telse if($(element).parent('.bootstrap-select') && $(element).parent('.bootstrap-select').length > 0) {\n\t\t\t\t\t\tthis.scrollToElement($(element).parent('.bootstrap-select')[0], -60);\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.scrollToElement(element, -60);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tignore: [],\n\t\t\trules: {\n\t\t\t\tSalutation: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tFirstName: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tLastName: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tEmail: {\n\t\t\t\t\trequired: true,\n\t\t\t\t\temail: true\n\t\t\t\t},\n\t\t\t\tCountry: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tEducationLevel: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tOverMinimumAge: {\n\t\t\t\t\trequired: true\n\t\t\t\t},\n\t\t\t\tTermsAndConditions: {\n\t\t\t\t\trequired: true\n\t\t\t\t}\n\t\t\t},\n\t\t\tmessages: {\n\t\t\t\tSalutation: {\n\t\t\t\t\trequired: 'Please select a title.'\n\t\t\t\t},\n\t\t\t\tFirstName: {\n\t\t\t\t\trequired: 'Please enter a first name.'\n\t\t\t\t},\n\t\t\t\tLastName: {\n\t\t\t\t\trequired: 'Please enter a last name.'\n\t\t\t\t},\n\t\t\t\tEmail: {\n\t\t\t\t\trequired: 'Please enter an email address.',\n\t\t\t\t\temail: 'Please enter a valid email address.'\n\t\t\t\t},\n\t\t\t\tCountry: {\n\t\t\t\t\trequired: 'Please select a country.'\n\t\t\t\t},\n\t\t\t\tTermsAndConditions: {\n\t\t\t\t\trequired: 'Please agree to the terms and conditions.'\n\t\t\t\t}\n\t\t\t},\n\t\t\terrorClass: 'error-messages is-active mt-1',\n\t\t\terrorElement: 'span',\n\t\t\terrorPlacement: (error, element) => {\n\t\t\t\tif($(element).is('select')) {\n\t\t\t\t\t$(element).parents('.bootstrap-select').after(error);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\terror.insertAfter(element);\n\t\t\t\t}\n\t\t\t},\n\t\t\thighlight: (element) => {\n\t\t\t\t$(element).addClass('is-invalid').removeClass('is-valid');\n\t\t\t},\n\t\t\tunhighlight: (element) => {\n\t\t\t\t$(element).addClass('is-valid').removeClass('is-invalid');\n\t\t\t}\n\t\t});\n\t}\n}"],"sourceRoot":""}