function RecoveryPasswordView(options){var self=this; self.userServiceFacade=options.userServiceFacade; self.inet=options.inet; self.i18n=options.i18n; self.messageHandler=options.messageHandler; self.idRecaptcha=""; self.scrollbar=null; self.sessionToken=null; self.countryCode=null; self.fullName=""; self.deliveryType=null; self._init(); }RecoveryPasswordView.prototype._init=function(){var self=this; var action="recoveryPasswordStep1"; var params={i18n:self.i18n}; self.fullName=""; self._loadStep(action,params,"recoveryPassword"); $("body").loader("show"); this.loadCaptcha(); self._initHandlers(); }; RecoveryPasswordView.prototype._loadStep=function(action,params,module){var self=this; captcha.hide(); if(!module&&module!=""){module="recoveryPassword"; }self.inet.loadStep(action,params,module); $('[data-toggle="popover"]').popover({placement:"right"}); }; RecoveryPasswordView.prototype.loadCaptcha=function(){var self=this; var countryCode={countryCode:inet.countryCode}; self.userServiceFacade.checkCaptcha(countryCode,self._onSuccessCheckCaptcha,self._onErrorCheckCaptcha,self); }; RecoveryPasswordView.prototype._onSuccessCheckCaptcha=function(data){captcha.render(data); }; RecoveryPasswordView.prototype._onErrorCheckCaptcha=function(response,textStatus,errorThrown){var self=this; $("body").loader("hide"); self.messageHandler.showMessage(self.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("error.internal"),"messageArea"); }; RecoveryPasswordView.prototype._initHandlers=function(){var self=this; $(document).off("submit","#formRecoveryPassFirstStep").on("submit","#formRecoveryPassFirstStep",function(event){event.preventDefault(); self._submitFormFirstStep(); }); $(document).off("submit","#formRestorePassSecondStep").on("submit","#formRestorePassSecondStep",function(event){event.preventDefault(); self._submitFormSecondStep(); }); $(document).off("submit","#formRestorePassThirdStep").on("submit","#formRestorePassThirdStep",function(event){event.preventDefault(); self._submitFormThirdStep(); }); $(document).off("submit","#formRestorePassFourthStep").on("submit","#formRestorePassFourthStep",function(event){event.preventDefault(); self._submitFormFourthStep(); }); $(document).off("keypress","#recoveryPasswordFormLogin").on("keypress","#recoveryPasswordFormLogin",function(event){self._processMaxLength(event); }); $(document).off("focus","#recoveryPassInputPass").on("focus","#recoveryPassInputPass",function(event){self._onFocusSetPassword("recoveryPassWarningPass",event.target); }); $(document).off("blur","#recoveryPassInputPass").on("blur","#recoveryPassInputPass",function(event){self._onBlurSetPassword("recoveryPassWarningPass",event.target); }); $(document).off("focus","#recoveryPassInputPassRepeat").on("focus","#recoveryPassInputPassRepeat",function(event){self._onFocusSetPassword("recoveryPassWarningRepeatPass",event.target); }); $(document).off("blur","#recoveryPassInputPassRepeat").on("blur","#recoveryPassInputPassRepeat",function(event){self._onBlurSetPassword("recoveryPassWarningRepeatPass",event.target); }); }; RecoveryPasswordView.prototype._onFocusSetPassword=function(idWarning,elem){var self=this; if(!$(elem).hasClass("repeatPassword")){$("#"+idWarning).removeClass("hide"); inet.updateScrollbar(); }}; RecoveryPasswordView.prototype._onBlurSetPassword=function(idWarning,elem){var self=this; if(!$(elem).hasClass("repeatPassword")){$("#"+idWarning).addClass("hide"); }inet.updateScrollbar(); }; RecoveryPasswordView.prototype._submitFormFirstStep=function(data){var self=this; var login=$.trim($("#recoveryPasswordFormLogin").val()); var hasEmptyFields=false; var captchaToken=""; if(login==""){hasEmptyFields=true; self._addValidationWarning("recoveryPasswordFormLogin"); }else{self._removeValidationWarning("recoveryPasswordFormLogin",hasEmptyFields); }var data=captcha.val(); if(captcha.isRequired()&&$.isEmptyObject(data)){hasEmptyFields=true; self._addValidationCaptchaWarning(); }else{self._removeValidationCaptchaWarning(hasEmptyFields); }if(!hasEmptyFields){$("body").loader("show"); self.userServiceFacade.getDeliveryType(login,data,self._onSuccessGetDeliveryType,self._onErrorGetDeliveryType,this); }inet.updateScrollbar(); }; RecoveryPasswordView.prototype._onSuccessGetDeliveryType=function(data){var self=this; if(data.userValid==true){self.fullName=data.name+" "+data.lastName; self.deliveryType=data; self._renderSecondStep(data); }else{if(data.code=="98"){self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,data.message,"messageArea"); }else{self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("error.user.not.valid"),"messageArea"); }this.loadCaptcha(); }}; RecoveryPasswordView.prototype._onErrorGetDeliveryType=function(response,textStatus,errorThrown){this.loadCaptcha(); $("body").loader("hide"); this.messageHandler.handleErrors(response,"messageArea"); }; RecoveryPasswordView.prototype._renderSecondStep=function(data){var action="recoveryPasswordStep2"; var params={mail:data.mail,login:data.login,i18n:this.i18n,mobile:data.mobile,}; this._loadStep(action,params,"recoveryPassword"); this.loadCaptcha(); $(".supportMailLink").attr("href",$(".supportMailLink").attr("href")+"?subject="+data.login); }; RecoveryPasswordView.prototype._submitFormSecondStep=function(){var self=this; var checked=$("input.radioButtonSendPin:checked").val(); var login=$("#loginFormStep2").val(); var captchaToken=""; var hasEmptyFields=false; if(checked){var data=captcha.val(); if(captcha.isRequired()&&$.isEmptyObject(data)){hasEmptyFields=true; self._addValidationCaptchaWarning(); }else{self._removeValidationCaptchaWarning(hasEmptyFields); }$("body").loader("show"); data.deliveryType=checked; self.userServiceFacade.sendPIN(login,data,self._onSuccessSendPIN,self._onErrorSendPIN,this); }else{self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("msg.info.selectWhereToSend"),"messageArea"); inet.updateScrollbar(); }}; RecoveryPasswordView.prototype._onSuccessSendPIN=function(data){var login=$("#loginFormStep2").val(); var params={login:login,}; if(data&&data.sent=="true"){this._renderThirdStep(params); }else{if(data&&data.code=="98"){this.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,data.message,"messageArea"); }else{this.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,this.i18n.msg("error.internal"),"messageArea"); }this.loadCaptcha(); }}; RecoveryPasswordView.prototype._onErrorSendPIN=function(response,textStatus,errorThrown){this.loadCaptcha(); this.messageHandler.handleErrors(response,"messageArea"); }; RecoveryPasswordView.prototype._renderThirdStep=function(params){var self=this; var action="recoveryPasswordStep3"; this._loadStep(action,params,"recoveryPassword"); this.loadCaptcha(); var minSize=8; if(this.deliveryType!=null&&this.deliveryType.cpType==1){minSize=12; }var textWarning=i18n.msg("msg.info.password.secure"); textWarning=textWarning.replace("",minSize); $("#recoveryPassWarningPassTextoAviso").html(textWarning); this.passwordValidation=$("#recoveryPassInputPass").passwordValidation({lowerCaseRequired:true,upperCaseRequired:true,minSize:minSize,simbolRequired:false,numberRequired:true,acceptInvalidCaracters:true,verifyName:this.fullName}); $("body").click(function(event){if(event.target.id!="recoveryPassInputPass"){self.passwordValidation.passwordValidation("hide"); }}); $("#recoveryPassInputPin").focus(function(event){self.passwordValidation.passwordValidation("hide"); }); $("#recoveryPassInputPassRepeat").focus(function(event){self.passwordValidation.passwordValidation("hide"); }); $(".mCSB_container").attrchange({trackValues:true,callback:function(event){if($(".popover").prop("style")){var top=event.target.style.top.replace("px",""); var oldValueStr=event.oldValue; var oldValueNormal=""; var oldTopValue=(inet.parseStringToObject(event.oldValue).top!=undefined&&inet.parseStringToObject(event.oldValue).top!=null)?inet.parseStringToObject(event.oldValue).top.replace("px",""):""; var newTopValue=(inet.parseStringToObject(event.newValue).top!=undefined&&inet.parseStringToObject(event.newValue).top!=null)?inet.parseStringToObject(event.newValue).top.replace("px",""):""; if(oldTopValue==""||newTopValue==""){return; }var newTop=Number($(".popover").prop("style").top.replace("px",""))+Number((newTopValue-oldTopValue)); $(".popover").prop("style").top=newTop+"px"; }}}); $(".supportMailLink").attr("href",$(".supportMailLink").attr("href")+"?subject="+$("#loginFormStep3").val()); }; RecoveryPasswordView.prototype._submitFormThirdStep=function(){var self=this; var pin=$("#recoveryPassInputPin").val(); var pass=$("#recoveryPassInputPass").val(); var passRepeat=$("#recoveryPassInputPassRepeat").val(); var login=$("#loginFormStep3").val(); var hasEmptyFields=false; var captchaToken=""; if(pin!=""){self._removeValidationWarning("recoveryPassInputPin",hasEmptyFields); }else{self._addValidationWarning("recoveryPassInputPin"); hasEmptyFields=true; }if(pass!=""){self._removeValidationWarning("recoveryPassInputPass",hasEmptyFields); }else{self._addValidationWarning("recoveryPassInputPass"); hasEmptyFields=true; }if(passRepeat!=""){self._removeValidationWarning("recoveryPassInputPassRepeat",hasEmptyFields); }else{self._addValidationWarning("recoveryPassInputPassRepeat"); hasEmptyFields=true; }var data=captcha.val(); if(captcha.isRequired()&&$.isEmptyObject(data)){hasEmptyFields=true; self._addValidationCaptchaWarning(); }else{self._removeValidationCaptchaWarning(hasEmptyFields); }if(hasEmptyFields==false){if(pass!=passRepeat){self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("error.password.repeat"),"messageArea"); }else{if($("#recoveryPassInputPass").attr("valid")!="true"){self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("pwd.validator.invalidPassMsg"),"messageArea"); }else{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 passwordPinDto={password:pass,pin:pin,countryCode:(data.countryCode)?data.countryCode:null}; if(g_recaptcha_response!=null){passwordPinDto["g-recaptcha-response"]=g_recaptcha_response; }if(recaptcha_response_field!=null){passwordPinDto.recaptcha_response_field=recaptcha_response_field; }if(uid!=null){passwordPinDto.uid=uid; }$("body").loader("show"); self.userServiceFacade.changePassword(login,passwordPinDto,self._onSuccessChangePassword,self._onErrorChangePassword,this); }}inet.updateScrollbar(); }}; RecoveryPasswordView.prototype._onSuccessChangePassword=function(data){var self=this; if(data.changed=="true"){var action="recoveryPasswordFinalStep"; var params={login:$("#loginFormStep3").val()}; self._loadStep(action,params,"recoveryPassword"); $("body").loader("hide"); }else{this.loadCaptcha(); self.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_ERROR,self.i18n.msg("error.password.notChanged"),"messageArea"); inet.updateScrollbar(); }}; RecoveryPasswordView.prototype._onErrorChangePassword=function(response,textStatus,errorThrown){var self=this; this.loadCaptcha(); this.messageHandler.handleErrors(response,"messageArea"); inet.updateScrollbar(); if(response.responseJSON.code=="95"){$(self.passwordValidation[0]).attr("errorcode","95"); setTimeout(function(){self.passwordValidation.passwordValidation("show"); },500); }}; RecoveryPasswordView.prototype._submitFormFourthStep=function(event){var login=$("#loginFormStepFinal").val(); $("#userLogin").val(login); $("#recoveryView").modal("hide"); $("#real_pass").focus(); }; RecoveryPasswordView.prototype._addValidationWarning=function(idDiv){var self=this; $("#"+idDiv).addClass("rojo"); this.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_REQUIRED_FIELD,this.i18n.msg("error.required.field"),"messageArea"); }; RecoveryPasswordView.prototype._removeValidationWarning=function(idDiv,hasEmptyFields){$("#"+idDiv).removeClass("rojo"); if(!hasEmptyFields){$("#texto_alerta").removeClass("texto_alerta_rojo"); }}; RecoveryPasswordView.prototype._addValidationCaptchaWarning=function(){var self=this; captcha.addBorderValidation(); this.messageHandler.showMessage(this.messageHandler.MESSAGE_TYPE_REQUIRED_FIELD,this.i18n.msg("error.required.field"),"messageArea"); }; RecoveryPasswordView.prototype._removeValidationCaptchaWarning=function(hasEmptyFields){captcha.removeBorderValidation(); if(!hasEmptyFields){$("#texto_alerta").removeClass("texto_alerta_rojo"); }}; RecoveryPasswordView.prototype._processMaxLength=function(event){if(event.target.value.length>=30){event.preventDefault(); }}; RecoveryPasswordView.prototype.refreshCaptcha=function(countryCode){var self=this; var data={countryCode:countryCode}; self.userServiceFacade.refreshCaptchaImg(data,self._onSuccessRefreshCaptchaImg,self._onErrorRefreshCaptchaImg); }; RecoveryPasswordView.prototype._onSuccessRefreshCaptchaImg=function(data){var self=this; if(data.image){$("#jCaptchaImg").attr("src","data:image/png;base64,"+data.image); $("#jCaptchaInput").val(""); if($("#jCaptchaDiv").hasClass("hide")){$("#jCaptchaDiv").removeClass("hide"); }self.sessionToken=data.uid; }else{$("#jCaptchaDiv").removeClass("hide"); }}; RecoveryPasswordView.prototype._onErrorRefreshCaptchaImg=function(response,textStatus,errorThrown){this.messageHandler.handleErrors(response,"messageArea"); inet.updateScrollbar(); };