function RecoveryUserView(options){var self=this; self.userServiceFacade=options.userServiceFacade; self.inet=options.inet; self.i18n=options.i18n; self.messageHandler=options.messageHandler; self.idRecaptcha=null; self._init(); }RecoveryUserView.prototype._init=function(){var self=this; self._loadStep("recoveryUserStep",{i18n:self.i18n}); $(document).off("submit","#recoveryUserForm").on("submit","#recoveryUserForm",function(event){event.preventDefault(); self._submitFormEmail(); }); $(document).off("submit","#recoveryOTPForm").on("submit","#recoveryOTPForm",function(event){event.preventDefault(); self._submitForm(); }); $(document).off("submit","#formRestoreUserFourthStep").on("submit","#formRestoreUserFourthStep",function(event){event.preventDefault(); self._submitFormFinalStep(); }); $("#recoveryUserCountrySelect").select2({width:"100%",closeOnSelect:false,}); $("body").loader("show"); self.loadCaptcha(); }; RecoveryUserView.prototype._loadStep=function(action,params,module){var self=this; captcha.hide(); if(!module&&module!=""){module="recoveryUser"; }self.inet.loadStep(action,params,module); }; RecoveryUserView.prototype.loadCaptcha=function(reset){var self=this; var countryCode={countryCode:inet.countryCode}; self.userServiceFacade.checkCaptcha(countryCode,self._onSuccessCheckCaptcha,self._onErrorCheckCaptcha,self); }; RecoveryUserView.prototype._onSuccessCheckCaptcha=function(data){var self=this; captcha.render(data); }; RecoveryUserView.prototype._onErrorCheckCaptcha=function(response,textStatus,errorThrown){var self=this; self.messageHandler.showMessage(self.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("error.internal"),"messageArea"); }; RecoveryUserView.prototype._submitFormEmail=function(){var self=this; var empId=$.trim($("#inputUserIdRecoveryUser").val()); var captchaToken=""; var hasEmptyFields=false; var empIdComplete=""; const emailRegex=/^[^\s@]+@[^\s@]+\.[^\s@]+$/; if(empId!=""){if(!empId.match(emailRegex)){var msg=i18n.msg("error.mail"); self._addValidationMailWarning("inputUserIdRecoveryUser",msg); hasEmptyFields=true; }else{self._removeValidationWarning("inputUserIdRecoveryUser",hasEmptyFields); hasEmptyFields=false; }}else{self._addValidationWarning("inputUserIdRecoveryUser"); hasEmptyFields=true; }var data=captcha.val(); if(captcha.isRequired()&&$.isEmptyObject(data)){hasEmptyFields=true; self._addValidationCaptchaWarning(); }else{self._removeValidationCaptchaWarning(hasEmptyFields); }if(hasEmptyFields==false){empIdComplete=empId; self.userServiceFacade.sendOTP(empIdComplete,captcha.val(),self._onSuccessSendOneTimePassword,self._onErrorSendOneTimePassword,self); }}; RecoveryUserView.prototype._addValidationMailWarning=function(idDiv,msg){var self=this; $("#"+idDiv).addClass("rojo"); $("#"+idDiv+" + span").html(msg).removeClass("hide"); }; RecoveryUserView.prototype._onSuccessSendOneTimePassword=function(data){var self=this; if(data.sent=="true"){var mail=$.trim($("#inputUserIdRecoveryUser").val()); var params={mail:mail,i18n:this.i18n}; this._loadStep("recoveryUserStep2",params); }else{if(data.code=="98"){this._addValidationWarning("inputUserIdRecoveryUser",data.message,null); }else{this._addValidationWarning("inputUserIdRecoveryUser",this.i18n.msg("error.message.not.send"),null); }this.loadCaptcha(); }}; RecoveryUserView.prototype._onErrorSendOneTimePassword=function(response,textStatus,errorThrown){this._addValidationWarning("inputUserIdRecoveryUser","",response); this.loadCaptcha(); }; RecoveryUserView.prototype._submitForm=function(){var self=this; var oneTimePassword=$.trim($("#inputOtpIdRecoveryUser").val()); var captchaToken=""; var mail=$("#mailFormStep2").val(); var hasEmptyFields=false; if(oneTimePassword!=""){self._removeValidationWarning("inputOtpIdRecoveryUser",hasEmptyFields); hasEmptyFields=false; }else{self._addValidationWarning("inputOtpIdRecoveryUser"); hasEmptyFields=true; }var data=captcha.val(); if(captcha.isRequired()&&$.isEmptyObject(data)){hasEmptyFields=true; self._addValidationCaptchaWarning(); }else{self._removeValidationCaptchaWarning(hasEmptyFields); }if(hasEmptyFields==false){var g_recaptcha_response=(data["g-recaptcha-response"])?data["g-recaptcha-response"]:null; var recaptcha_response_field=(data.recaptcha_response_field)?data.recaptcha_response_field:null; var uid=(data.uid)?data.uid:null; var oneTimePasswordDto={oneTimePassword:oneTimePassword,countryCode:(data.countryCode)?data.countryCode:null}; if(g_recaptcha_response!=null){oneTimePasswordDto["g-recaptcha-response"]=g_recaptcha_response; }if(recaptcha_response_field!=null){oneTimePasswordDto.recaptcha_response_field=recaptcha_response_field; }if(uid!=null){oneTimePasswordDto.uid=uid; }self.userServiceFacade.validateOTP(mail,oneTimePasswordDto,self._onSuccessRecoveryUser,self._onErrorRecoveryUser,self); }}; RecoveryUserView.prototype._onSuccessRecoveryUser=function(data){if(data.valid=="true"){var login=data.login; this._loadStep("recoveryUserFinalStep",{login:login}); $("body").loader("hide"); }else{if(data.code=="98"){this._addValidationWarning("inputOtpIdRecoveryUser",data.message,null); }else{this._addValidationWarning("inputOtpIdRecoveryUser",this.i18n.msg("error.otp.not.valid"),null); }this.loadCaptcha(); }}; RecoveryUserView.prototype._onErrorRecoveryUser=function(response,textStatus,errorThrown){this._addValidationWarning("inputOtpIdRecoveryUser","",response); this.loadCaptcha(); }; RecoveryUserView.prototype._submitFormFinalStep=function(){var login=$("#recoverUserFormStepFinal").val(); $("#userLogin").val(login); $("#recoveryView").modal("hide"); $("#real_pass").focus(); }; RecoveryUserView.prototype._addValidationWarning=function(idDiv,msg,response){var self=this; $("#"+idDiv).addClass("rojo"); if((null==msg||msg=="")&&null===response){msg=this.i18n.msg("error.required.field"); $("#"+idDiv+" + span").html(msg).removeClass("hide"); }else{if(msg!==null&&response===null){$("#"+idDiv+" + span").html(msg).removeClass("hide"); }else{var message=$.parseJSON(response.responseText).message; $("#"+idDiv+" + span").html(message).removeClass("hide"); }}}; RecoveryUserView.prototype._addValidationCaptchaWarning=function(idDiv){var self=this; captcha.addBorderValidation(); this.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_REQUIRED_FIELD,this.i18n.msg("error.required.field"),"messageArea"); }; RecoveryUserView.prototype._removeValidationWarning=function(idDiv,hasEmptyFields){$("#"+idDiv).removeClass("rojo"); $("#"+idDiv+" + span").addClass("hide"); }; RecoveryUserView.prototype._removeValidationCaptchaWarning=function(hasEmptyFields){captcha.removeBorderValidation(); if(!hasEmptyFields){$("#texto_alerta").removeClass("texto_alerta_rojo"); }};