darksantos

JS

Aug 7th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.   //$("#firma, #firma-anexo, #firma-tutor").jSignature();
  3.   //Webcam.attach('#div-carnClienteFrontal');
  4. });
  5.  
  6. $('#btn-guardar').click(function() {
  7.   var sign = $('#signature').jSignature('getData', 'base30');
  8.   console.log(sign);
  9.   alert(sign);
  10. });
  11.  
  12. $('#btn-borrar-firma').click(function(e) {
  13.   e.preventDefault();
  14.   $('#firma').jSignature('reset');
  15.   $('#Formulario_firmaExoneracionCliente').removeAttr('value');
  16. });
  17. $('#btn-borrar-firma-anexo').click(function(e) {
  18.   e.preventDefault();
  19.   $('#firma-anexo').jSignature('reset');
  20.   $('#Formulario_firmaAnexo').removeAttr('value');
  21. });
  22. $('#btn-borrar-firma-tutor').click(function(e) {
  23.   e.preventDefault();
  24.   $('#firma-tutor').jSignature('reset');
  25.   $('#Formulario_firmaTutor').removeAttr('value');
  26. });
  27.  
  28. $('#btn-sgte-anexo').click(function() {
  29.   var firma = $('#firma').jSignature('getData', 'base30');
  30.   if (firma != null) {
  31.     if (firma[1] != '') {
  32.       $('#input-firma').val(firma[1]);
  33.       $('#form-firma').submit();
  34.     } else alert('Debe firmar en el recuadro para continuar.');
  35.   }
  36. });
  37.  
  38. /*$("#btn-finalizar").click(function(){
  39.     var firmaAnexo = $("#firma-anexo").jSignature("getData","base30");
  40.     console.log(firmaAnexo);
  41.     if(firmaAnexo != null){
  42.         if(firmaAnexo[1] != ''){
  43.             $('#input-firma-anexo').val(firmaAnexo[1]);
  44.         }
  45.     }
  46. });*/
  47.  
  48. function consultaCliente(rut) {
  49.   //alert(rut);
  50.   $.ajax({
  51.     type: 'POST',
  52.     url: 'ConsultaCliente/',
  53.     data: { rut: rut },
  54.     success: function(data) {
  55.       var json = JSON.parse(data);
  56.       console.log(json);
  57.       if (json != null) {
  58.         if (json.status != 'ERROR') {
  59.           var datosCliente = json.cliente;
  60.           $('#Cliente_nombreCompletoCliente').val(
  61.             datosCliente.nombreCompletoCliente
  62.           );
  63.           $('#Cliente_domicilioCliente').val(datosCliente.domicilioCliente);
  64.           $('#Cliente_fechaNacCliente').val(datosCliente.fechaNacCliente);
  65.           $('#Cliente_emailCliente').val(datosCliente.emailCliente);
  66.           $('#contratoRut').html($('#Cliente_rutCliente').val());
  67.           $('#contratoNombre').html($('#Cliente_nombreCompletoCliente').val());
  68.           $('#contratoDomicilio').html($('#Cliente_domicilioCliente').val());
  69.           //$('#btn-sgte').focus();
  70.           $('#div-rut-firma').html(rut);
  71.           if (!json.mayorEdad) {
  72.             $('#div-menor').show();
  73.             $('#firma-tutor').jSignature();
  74.           } else {
  75.             $('#div-menor').hide();
  76.             $('#firma-tutor').html('');
  77.           }
  78.         } else {
  79.           $('#Cliente_nombreCompletoCliente').val('');
  80.           $('#Cliente_domicilioCliente').val('');
  81.           $('#Cliente_fechaNacCliente').val('');
  82.           $('#Cliente_emailCliente').val('');
  83.           $('#div-rut-firma').html('');
  84.           $('#contratoRut').html($('#Cliente_rutCliente').val());
  85.         }
  86.       }
  87.     }
  88.   });
  89. }
  90. $(":radio[value='1']").click(function() {
  91.   //alert("Usted no puede tatuarse si padece de esa condición");
  92.   $.Zebra_Dialog(
  93.     'Usted <strong>NO</strong> puede tatuarse si padece de esa condición.Consulte con el <strong>TATUADOR</strong>.',
  94.     {
  95.       type: 'warning',
  96.       title: 'Aviso',
  97.       position: ['center', 'top + 50']
  98.     }
  99.   );
  100. });
  101.  
  102. $('#email1,#email2').change(function() {
  103.   //alert( "Handler for .change() called." );
  104.   // juntando email
  105.   var email1 = $('#email1').val();
  106.   console.log(email1);
  107.   var email2 = $('#email2').val();
  108.   console.log(email2);
  109.  
  110.   if (email1 && email2) {
  111.     $('#Cliente_emailCliente').val(email1 + '@' + email2);
  112.   } else {
  113.     $('#Cliente_emailCliente').val('');
  114.   }
  115.   console.log('archivado');
  116. });
  117.  
  118. $('#month_start,#day_start,#year_start').change(function() {
  119.   //alert( "Handler for .change() called." );
  120.  
  121.   var dia = $('#day_start').val();
  122.   var mes = $('#month_start').val();
  123.   var anio = $('#year_start').val();
  124.   var guion = '-';
  125.   var cero = '0';
  126.  
  127.   if (dia < 10) {
  128.     dia = cero + dia;
  129.   }
  130.  
  131.   var fecha = anio + guion + mes + guion + dia;
  132.   $('#Cliente_fechaNacCliente').val(fecha);
  133.  
  134.   console.log(fecha);
  135.  
  136.   var hoy = new Date();
  137.   var dia = $('#day_start').val();
  138.   var mes = $('#month_start').val();
  139.   var anio = $('#year_start').val();
  140.  
  141.   var today = new Date();
  142.   var anionac = new Date(anio, mes - 1, dia);
  143.   var edad = today.getFullYear() - anionac.getFullYear();
  144.   var month = today.getMonth() - anionac.getMonth();
  145.   if (month < 0 || (month === 0 && today.getDate() < anionac.getDate())) {
  146.     edad--;
  147.   }
  148.   console.log('la edad es +' + edad);
  149.  
  150.   //var diff = hoy.getFullYear() - anio;
  151.   var diff = edad;
  152.   console.log(diff + guion);
  153.   if (diff < 18) {
  154.     $('#div-menor').show();
  155.     $('#firma-tutor').html('');
  156.     $('#firma-tutor').jSignature({ width: 768, height: 250 });
  157.     //$('#Formulario_firmaExoneracionCliente').val('');
  158.   } else {
  159.     $('#div-menor').hide();
  160.     $('#firma-tutor').html('');
  161.   }
  162. });
  163. $('#chbk-aceptar').click(function(e) {
  164.   if ($('#chbk-aceptar').prop('checked') == true) {
  165.     // Se activí
  166.     $('#formularios').css('display: visible');
  167.     $('#formularios, #btn-finalizar').fadeIn();
  168.     //$('#firma-anexo, #firma').jSignature('reset');
  169.     $('#firma-anexo, #firma').jSignature({ width: 768, height: 250 });
  170.     $('html, body').animate(
  171.       {
  172.         scrollTop: $('#formularios').offset().top
  173.       },
  174.       1000
  175.     );
  176.   } else {
  177.     //alert('adasd');
  178.     $('#firma-anexo, #firma').html('');
  179.     $('#formularios').css('display: none');
  180.     $('#formularios, #btn-finalizar').fadeOut();
  181.   }
  182. });
  183.  
  184. $('.btn-foto').click(function(e) {
  185.   var div = $(this).data('value');
  186.   Webcam.snap(function(data_uri) {
  187.     document.getElementById(div).innerHTML = '<img src="' + data_uri + '"/>';
  188.   });
  189. });
  190.  
  191. $('.btn-webcam').click(function(e) {
  192.   var divCam = $(this).data('value');
  193.   var divFoto = $(this).data('foto');
  194.   var estado = $(this).data('estado');
  195.   if (estado == 0) {
  196.     // se activa la webcam
  197.     $('#' + divCam).show();
  198.     $('#' + divFoto).hide();
  199.     Webcam.attach('#' + divCam);
  200.     $(this).data('estado', '1');
  201.  
  202.     $(this).html('<i class="icon-camera icon-white"></i> Tomar foto');
  203.     $(this).removeClass('btn-success');
  204.     $(this).addClass('btnrojo');
  205.   } else {
  206.     // se toma la foto
  207.     var datos_foto = '';
  208.     Webcam.snap(function(data_uri) {
  209.       document.getElementById(divFoto).innerHTML =
  210.         '<img src="' + data_uri + '"/>';
  211.       datos_foto = data_uri;
  212.     });
  213.     var input_foto = $(this).data('input');
  214.     var base64_foto = datos_foto.replace(/^data\:image\/\w+\;base64\,/, '');
  215.     $('#Formulario_' + input_foto).val(base64_foto);
  216.     $('#' + divCam).hide();
  217.     $('#' + divFoto).show();
  218.     $(this).data('estado', '0');
  219.     $(this).html('<i class="icon-off icon-white"></i> Activar Cámara');
  220.     Webcam.off('#' + divCam);
  221.     $(this).addClass('btn-success');
  222.     $(this).removeClass('btnrojo');
  223.   }
  224. });
  225.  
  226. function getAge(birthDateString) {
  227.   var today = new Date();
  228.   var birthDate = new Date(birthDateString);
  229.   var age = today.getFullYear() - birthDate.getFullYear();
  230.   var m = today.getMonth() - birthDate.getMonth();
  231.   if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
  232.     age--;
  233.   }
  234.   return age;
  235. }
  236.  
  237. $('#btn-finalizar').click(function(e) {
  238.   /*var firmaAnexo = $("#firma-anexo").jSignature("getData","base30");
  239.     console.log(firmaAnexo);
  240.     if(firmaAnexo != null){
  241.         if(firmaAnexo[1] != ''){
  242.             $('#input-firma-anexo').val(firmaAnexo[1]);
  243.         }
  244.     }*/
  245.   var dia = $('#day_start').val();
  246.   var mes = $('#month_start').val();
  247.   var anio = $('#year_start').val();
  248.  
  249.   var today = new Date();
  250.   var anionac = new Date(anio, mes - 1, dia);
  251.   var edad = today.getFullYear() - anionac.getFullYear();
  252.   var month = today.getMonth() - anionac.getMonth();
  253.   if (month < 0 || (month === 0 && today.getDate() < anionac.getDate())) {
  254.     edad--;
  255.   }
  256.   // console.log('la edad es +' + edad);
  257.  
  258.   if ($(":radio[value='1']:checked").length > 0) {
  259.     e.preventDefault();
  260.     //alert("Ud. no puede tatuarse si tiene una de las enfermedades listadas anteriormente");
  261.     $.Zebra_Dialog(
  262.       'Usted <strong>NO</strong> puede tatuarse si padece de esa condición.Consulte con el <strong>TATUADOR</strong>.',
  263.       {
  264.         type: 'warning',
  265.         title: 'Aviso',
  266.         position: ['center', 'top + 50']
  267.       }
  268.     );
  269.     $('html, body').animate(
  270.       {
  271.         scrollTop: $('#enfermedades').offset().top
  272.       },
  273.       1000
  274.     );
  275.   } else {
  276.     // juntando email
  277.     var email1 = $('#email1').val();
  278.     var email2 = $('#email2').val();
  279.  
  280.     if (email1 && email2) {
  281.       $('#Cliente_emailCliente').val(email1 + '@' + email2);
  282.     } else {
  283.       $('#Cliente_emailCliente').val('');
  284.     }
  285.     console.log('holi');
  286.  
  287.     var rutCliente = $('#Cliente_rutCliente').val();
  288.     var rutClienteSinNada = rutCliente.replace(/[\. ,:-\_]+/g, '');
  289.  
  290.     // console.log(rutCliente);
  291.     // console.log(rutClienteSinNada);
  292.  
  293.     // return;
  294.  
  295.     if (
  296.       // rutClienteSinNada.length > 10 ||
  297.       // $.validateRut(rutCliente) ||
  298.       // !rutCliente
  299.       rutClienteSinNada.length > 0
  300.     ) {
  301.       //e.preventDefault();
  302.       var anio = $('#year_start').val();
  303.       var hoy = new Date();
  304.  
  305.       //var diff = hoy.getFullYear() - anio;
  306.       var diff = edad;
  307.       // console.log($.validateRut($('#Formulario_rutTutor').val()));
  308.       // console.log('asdas');
  309.       // console.log($('#Formulario_rutTutor').val());
  310.  
  311.       if (edad < 18) {
  312.         if (
  313.           // $.validateRut($('#Formulario_rutTutor').val()) ||
  314.           // !$('#Formulario_rutTutor').val()
  315.           true
  316.         ) {
  317.           var haynombre = $('#Formulario_nombreTutor').val();
  318.           var hayrut = $('#Formulario_rutTutor').val();
  319.           var hayfirma = $('#Formulario_firmaTutor').val();
  320.           var hayfotoCFT = $('#Formulario_fotoCarnetFrontalTutor').val();
  321.           var hayfotoCTT = $('#Formulario_fotoCarnetTraseroTutor').val();
  322.           if (hayfirma && hayrut && haynombre && hayfotoCFT && hayfotoCTT) {
  323.             $('#modal-cargando').modal('show');
  324.           } else {
  325.             e.preventDefault();
  326.             $.Zebra_Dialog('Falta en la sección del tutor ', {
  327.               type: 'warning',
  328.               title: 'Aviso',
  329.               position: ['center', 'top + 50']
  330.             });
  331.             $('html, body').animate(
  332.               {
  333.                 scrollTop: $('#div-menor').offset().top
  334.               },
  335.               1000
  336.             );
  337.           }
  338.         } else {
  339.           e.preventDefault();
  340.           //alert("Ud. no puede tatuarse si tiene una de las enfermedades listadas anteriormente");
  341.           $.Zebra_Dialog(
  342.             '<strong>RUT TUTOR</strong> Incorrecto. Ingrese nuevamente el RUT ',
  343.             {
  344.               type: 'warning',
  345.               title: 'Aviso',
  346.               position: ['center', 'top + 50']
  347.             }
  348.           );
  349.           $('html, body').animate(
  350.             {
  351.               scrollTop: $('#div-menor').offset().top
  352.             },
  353.             1000
  354.           );
  355.         }
  356.       } else {
  357.         $('#modal-cargando').modal('show');
  358.       }
  359.     } else {
  360.       console.log('RUt Incorrecto');
  361.       e.preventDefault();
  362.       $('html, body').animate(
  363.         {
  364.           scrollTop: $('#formularios').offset().top
  365.         },
  366.         1000
  367.       );
  368.       //alert("Ud. no puede tatuarse si tiene una de las enfermedades listadas anteriormente");
  369.       $.Zebra_Dialog('Ingrese el R.U.T. ', {
  370.         type: 'warning',
  371.         title: 'Aviso',
  372.         position: ['center', 'top + 50']
  373.       });
  374.     }
  375.   }
  376. });
  377.  
  378. $('#firma, #firma-anexo, #firma-tutor').mouseout(function(e) {
  379.   var firma = $(this).jSignature('getData', 'base30');
  380.   var input = $(this).data('input');
  381.   console.log(input);
  382.   console.log(firma);
  383.   if (firma != null) {
  384.     if (firma[1] != '') {
  385.       $('#Formulario_' + input).val(firma[1]);
  386.       console.log(firma[1]);
  387.       console.log(input);
  388.     }
  389.   }
  390. });
Advertisement
Add Comment
Please, Sign In to add comment