templates/Seguridades/admin/addPerson/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Registro{% endblock %}
  3. {% block body %}
  4. <div class="accordion" id="moduloSeguridades_Profile" style="margin-bottom: 2.1rem !important;">
  5.     <div class="accordion-item">
  6.         <h2 class="accordion-header">
  7.             <button class="accordion-button active" type="button" data-bs-toggle="collapse" data-bs-target="#perfil"></button>
  8.         </h2>
  9.         <div id="perfil" class="accordion-collapse collapse show">
  10.             <div class="accordion-body">
  11.                 <div class="fieldsetForm">
  12.                     {{ form_start(form) }}
  13.                     <div class="row g-2">
  14.                         
  15.                         <div class="col-lg-10">
  16.                             <div class="row">
  17.                                 <div class="col-lg-4">
  18.                                     {{ form_label(form.mailPersonal )}}
  19.                                     {{form_widget(form.mailPersonal ,{'attr':{'disabled':false}})}}
  20.                                 </div>
  21.                             </div>
  22.                             <div class="row mt-2">
  23.                                 <div class="col-lg-4">
  24.                                     {{ form_label(form.nombres )}}
  25.                                     {{form_widget(form.nombres )}}
  26.                                 </div>
  27.                             </div>
  28.                             <div class="row mt-2">
  29.                                 <div class="col-lg-4">
  30.                                     {{ form_label(form.apellidos )}}
  31.                                     {{form_widget(form.apellidos )}}
  32.                                 </div>
  33.                             </div>
  34.                             <div class="row mt-2">
  35.                                 <div class="col-lg-4">
  36.                                     {{ form_label(form.tipoIdentificacion )}}
  37.                                     {{form_widget(form.tipoIdentificacion )}}
  38.                                 </div>
  39.                             </div>
  40.                             <div class="row mt-2">
  41.                                 <div class="col-lg-4">
  42.                                     {{ form_label(form.numeroIdentificacion )}}
  43.                                     {{form_widget(form.numeroIdentificacion )}}
  44.                                 </div>
  45.                             </div>
  46.                             <div class="row mt-2">
  47.                                 <div class="col-lg-4">
  48.                                     {{ form_label(form.telCelular )}}
  49.                                     {{form_widget(form.telCelular )}}
  50.                                 </div>
  51.                             </div>
  52.                             <div class="row mt-2">
  53.                                 <div class="col-lg-4">
  54.                                 {{ form_label(form.direccionSector )}}
  55.                                 {{form_widget(form.direccionSector )}}
  56.                                 </div>
  57.                             </div>
  58.                             <div class="row mt-2">
  59.                                 <div class="col-lg-3">
  60.                                     {{ form_label(form.fechaNacimiento )}}
  61.                                     {{form_widget(form.fechaNacimiento )}}
  62.                                 </div>
  63.                             </div>
  64.                             <div class="row mt-2">
  65.                                 <div class="col-lg-3">
  66.                                     {{ form_label(form.idProvincias )}}
  67.                                     {{form_widget(form.idProvincias )}}
  68.                                 </div>
  69.                             </div>
  70.                             <div class="row mt-2">
  71.                                 <div class="col-lg-3">
  72.                                     {{ form_label(form.idCantones )}}
  73.                                     {{form_widget(form.idCantones )}}
  74.                                 </div>
  75.                             </div>
  76.                             <div class="row mt-2">
  77.                                 <div class="col-lg-3">
  78.                                     {{ form_label(form.idParroquias )}}
  79.                                     {{form_widget(form.idParroquias )}}
  80.                                 </div>
  81.                             </div>
  82.                         </div>
  83.                     </div>
  84.                     <div class="row justify-content-center mt-5">
  85.                         <div class="col-auto">
  86.                         {{form_widget(form.guardar )}}
  87.                         </div>
  88.                     </div>
  89.                     {{ form_end(form) }}
  90.                 </div>
  91.             </div>
  92.         </div>
  93.     </div>
  94. </div>
  95. {% endblock %} 
  96. {% block javascripts %}
  97.     <script>
  98.         //Selectores
  99.         const $form = document.forms.form;
  100.         const $provinciasS = $form.form_idProvincias
  101.         const $cantonesS = $form.form_idCantones
  102.         const $parroquiasS = $form.form_idParroquias
  103.         //Events
  104.         $form.form_tipoIdentificacion.addEventListener('change',() => {
  105.             $form.form_numeroIdentificacion.value = ''
  106.            // $form.form_id.value = ''
  107.             if($form.form_tipoIdentificacion.value === 'CÉDULA'){
  108.                 $form.form_numeroIdentificacion.onkeypress = () => { soloNumeros(event) }
  109.                 $form.form_numeroIdentificacion.onblur = () => { validaCI() }
  110.             }else{
  111.                 $form.form_numeroIdentificacion.onkeypress = () => { soloNumerosLetras(event) }
  112.                 $form.form_numeroIdentificacion.onblur = () => { validaExistNumeroIdentificacion() }
  113.             }
  114.         })
  115.         $form.form_nombres.onkeypress = () => { soloLetras(event) }
  116.         $form.form_apellidos.onkeypress = () => { soloLetras(event) }
  117.         $form.form_telCelular.onkeypress = () => { soloNumeros(event) }
  118.         $form.addEventListener('submit', async(event) => {
  119.             event.preventDefault()
  120.             const validateDate = validaFechaNacimiento($form.form_fechaNacimiento.value)
  121.             if(!validateDate){
  122.                 return ToastError('Datos Inválidos', 'Fecha de Nacimiento Incorrecta')
  123.             }
  124.             const data = new FormData($form)
  125.             const response = await getDataPost('addPersonInSystemExternal',data)
  126.             if(response.response){
  127.                 Swal.fire({
  128.                     title: 'Registro guardado',
  129.                     text: 'Su información personal se agregó con éxito.',
  130.                     icon: 'success',
  131.                     footer: '<span>Centro de capacitación Nival</span>',
  132.                     confirmButtonColor: '#3085d6',
  133.                     confirmButtonText: 'Confirmar',
  134.                     allowOutsideClick: false,
  135.                     allowEscapeKey: false,
  136.                     allowEnterKey: false,
  137.                     stopKeydownPropagation: false
  138.                 }).then((result) => {
  139.                     if (result.value) {
  140.                         setTimeout(function () { location.href = '/' }, 1000);
  141.                     }
  142.                 })
  143.             }else{
  144.                 ToastError('Error',response.message)
  145.             }
  146.         })
  147.         $form.form_idProvincias.addEventListener('change',async () => {
  148.             const idProvincia = $form.form_idProvincias.value
  149.             if(!idProvincia){
  150.                 ToastError('Datos Inválidos', 'debe seleccionar una Provincia')
  151.                 $cantonesS.value = ''; $cantonesS.disabled = true
  152.                 $parroquiasS.value = ''; $parroquiasS.disabled = true;return
  153.             }
  154.             const cantones = await getDataPost('getCantones', new URLSearchParams(`idProvincia=${idProvincia}`))
  155.             clearSelect($cantonesS, cantones.length != 0 ? false:true )
  156.             cantones.forEach((item)=>{
  157.                 $cantonesS.append(createTemplate(`<option value='${item.id}'>${item.nombre}</option>`))
  158.                 clearSelect($parroquiasS, true)
  159.             })
  160.         })
  161.         $form.form_idCantones.addEventListener('change',async () => {
  162.             const idCanton = $form.form_idCantones.value
  163.             if(!idCanton){
  164.                 ToastError('Datos Inválidos', 'debe seleccionar un Cantón')
  165.                 $parroquiasS.value = ''; $parroquiasS.disabled = true;return
  166.             }
  167.             const parroquias = await getDataPost('getParroquias', new URLSearchParams(`idCanton=${idCanton}`))
  168.             clearSelect($parroquiasS, parroquias.length != 0 ? false:true )
  169.             parroquias.forEach((item)=>{
  170.                 $parroquiasS.append(createTemplate(`<option value='${item.id}'>${item.nombre}</option>`))
  171.             })
  172.         })
  173.     </script>
  174.     {# <script src="{{ asset('assets/js/seguridades/profile.js')}}"></script> #}
  175.         {{ include('Seguridades/admin/menu/menuJs.html.twig')}}
  176.       <script type="text/javascript" src="{{ asset('assets/js/gijgo/gijgo.min.js') }}"></script>
  177.     <script type="text/javascript">
  178.         async function load(){
  179.             await datePicker()
  180.         }
  181.         function clearSelect($select, disabled=false){
  182.             $select.innerHTML = ''
  183.             $select.append(createTemplate(`<option value=''>SELECCIONAR</option>`))
  184.             $select.disabled = disabled
  185.         }
  186.         
  187.         async function validaCI(){
  188.             const ci = $form.form_numeroIdentificacion
  189.             if(!ci.value){
  190.                 return ToastError('Campos Vacíos','Tiene que ingresar un número de Identificación')
  191.             }
  192.             const response = await getDataPost('validateCI', new URLSearchParams(`ci=${ci.value}`))
  193.             if(!response){
  194.                 ci.value = ''
  195.                 $form.form_guardar.disabled = true
  196.                 return ToastError('Datos Inválidos','El número de identificación que ingreso no es correcto')
  197.             }
  198.             await validaExistNumeroIdentificacion()
  199.         }
  200.         async function validaExistNumeroIdentificacion(){
  201.             const ci = $form.form_numeroIdentificacion
  202.             const existCi = await getDataPost('getExistNumeroIdentificacion', new URLSearchParams(`ci=${ci.value}`))
  203.             if(existCi){
  204.                 ci.value = ''
  205.                 $form.form_guardar.disabled = true
  206.                 return ToastError('Datos Inválidos','El número de identificación que ingreso ya existe')
  207.             }
  208.             $form.form_guardar.disabled = false
  209.         }
  210.         load()
  211.     </script>
  212.     
  213. {% endblock %}