$(document).ready(function(){var token=null;var app=angular.module('negativeCertificate',['agora','ngMessages']).controller('negCertCtrl',function($scope,$http,$q){$scope.data={};$scope.hideDivConfirm=true;$scope.ACEPTO='N';$scope.validado=true;$scope.certificacion={};$scope.complete=false;$scope.emailSend=false;$scope.setStep=function(pos){if(pos==1){$scope.hideDivConfirm=true;$scope.ACEPTO='N';}else{if($("#negCertFrm").isAngularFormValid()){$scope.hideDivConfirm=false;}}} $scope.verTerminos=function(){$.get("/"+$("#site_prefix").val()+'CMS/PAGE/TERM_COND_MSG',function(resp){bootbox.dialog({title:$.i18n('Terminos y Condiciones'),message:resp,show:false,size:'large',buttons:{close:{label:$.i18n('Cerrar')}}}).modal('show');});} $scope.cancelar=function(){$scope.hideDivConfirm=true;$scope.validado=true;$scope.ACEPTO='N';$scope.data.NB_CONTRIBUYENTE='';$scope.data.TX_APELLIDO_P='';$scope.data.TX_APELLIDO_M='';$scope.data.NU_SS='';$scope.data.TX_EMAIL='';} $scope.imprimir=function(id_certificado){centerPopup("/"+$("#site_prefix").val()+'print/certificacion/guest/'+id_certificado);} $("#someterBTN").click(function(event){event.preventDefault();if(token){var l=Ladda.create($(this)[0]);l.start();$.post("/"+$("#site_prefix").val()+'certificacion/negativa/validar/'+$scope.data.NU_SS,{recaptcha:token},function(resp){if(resp.success){l.stop();toastr.success(resp.message);$.post("/"+$("#site_prefix").val()+'certificacion/negativa/save',$scope.data,function(resp){if(resp.success&&resp.nticket){$.blockUI();var nticket=resp.nticket;$.post("/"+$("#site_prefix").val()+"certificacion/negativa/pago/"+resp.nticket+"/enviar",function(resp){$.unblockUI();if(resp.success&&resp.redirect_url){popupPago(resp.redirect_url,nticket);token=null;grecaptcha.reset();}else{getErrorMessage(resp.error,function(msg){toastr.info(msg,'INFO');});token=null;grecaptcha.reset();}},'json').fail(function(){l.stop();token=null;grecaptcha.reset();});}else{getErrorMessage(resp.error,function(resp){toastr.error(resp,'Error');token=null;grecaptcha.reset();});}},'json').fail(function(){l.stop();token=null;grecaptcha.reset();});}else{l.stop();$scope.validado=false;$scope.hideDivConfirm=true;$scope.ACEPTO='N';$scope.$apply();toastr.error(resp.message);token=null;grecaptcha.reset();}},'json').fail(function(){l.stop();token=null;grecaptcha.reset();});}else{grecaptcha.execute();}});function popupPago(url,ticket){var result=centerPopup(url);if(result===false){bootbox.confirm({message:'Popup esta bloqueado, Por favor desbloquear los popups y seleccione [Intentar de nuevo]',show:false,buttons:{'confirm':{label:'Intentar de nuevo',className:'btn-warning'},'cancel':{label:'Cancelar'}},callback:function(resp){if(resp){new_window=centerPopup(url);if(new_window===false){popupPago(url);}else{waitForPopupClose(new_window).then(function(){validarProceso(ticket);});}}}}).modal('show');}else{waitForPopupClose(result).then(function(){validarProceso(ticket);});}} function waitForPopupClose(popup){var deferred=$q.defer();var timer=setInterval(function(){if(popup.closed){clearInterval(timer);deferred.resolve();}},500);return deferred.promise;} function validarProceso(ticket){$.blockUI({message:'

'+$.i18n('Procesando certificacion')+'

',css:{border:'1px black solid',padding:'15px','background-color':'#fff','-webkit-border-radius':'10px','-moz-border-radius':'10px',color:'#000'}});$.post("/"+$("#site_prefix").val()+"certificacion/negativa/estatus/ticket/"+ticket,function(resp){if(resp.success){$.unblockUI();$scope.complete=true;$scope.certificacion=resp.data;$scope.emailSend=resp.email;$scope.$apply();toastr.success(resp.message);}else{$.unblockUI();toastr.error(resp.message,'Error');}},'json');}});processRecaptchaToken=function(resp){token=resp;$("#someterBTN").click();};$("#negCertFrm").addAngularMessages();$('#NU_SS').mask('000-00-0000');appManager.startApp("#negCertFrm",['negativeCertificate']);});