 <div class="container col d-flex justify-content-center">
   <div class="row">
      <div class="col-lg-12">
         <div class="card shadow-lg p-3 mb-5 bg-white ">
            <div class="card-header">
               <h3> Trabajadores </h3>
            </div>
            <div class="card-body">
               <!-- COMIENZO DEL FORMULARIO -->
               <form id="createform" action="/links/edit-trabajadores" method="POST" class="needs-validation" enctype="multipart/form-data" novalidate>
                  <div class="form-row">
                    <div class="col-md-2 mb-3">
                      <label class="font-weight-bold" for="desformula">Codigo</label> 
                      <div class="input-group">
                        <input class="form-control" type="text"  id="id-codigo"  value="{{lista.1.newParam.codigo}}"  name="codigo"     >                     
                      </div>
                    </div>


                    <div class="col-md-4 mb-3">
                      <label class="font-weight-bold" for="desformula">Nombres</label> 
                      <div class="input-group">
                        <input class="form-control" type="text"  id="idnombres"   name="nombres"  value="{{lista.1.newParam.nombres}}"  required>                     
                      </div>
                    </div>

                    <div class="col-md-4 mb-3">
                      <label class="font-weight-bold" for="desformula">Apellidos</label> 
                      <div class="input-group">
                        <input class="form-control" type="text"  id="idapellidos"   name="apellidos"  value="{{lista.1.newParam.apellidos}}"  required>                     
                      </div>
                    </div>

                    <div class="col-md-2 mb-3">
                      <label class="font-weight-bold" for="desformula">Cédula</label> 
                      <div class="input-group">
                        <input class="form-control" type="number"  id="idcedula"   name="cedula"  value="{{lista.1.newParam.cedula}}"  required>                     
                      </div>
                    </div>


                      <div class="input-group">
                        <input type="hidden"  class="form-control"  name="tipo_de_submit"  value=0 >
                        <input type="hidden"  class="form-control"  name="id_reg"  value="{{lista.1.newParam.idreg}}" >
                        <input type="hidden"   name="imagen1"  id="imagen1"  value = "{{lista.1.newParam.imagen}}" > 
                        <input type="hidden"   name="imagen2"  id="imagen2"  value = "{{lista.1.newParam.originalnameimg}}" > 
                      </div>

                  </div> <!-- FIN DE LABELS E INPUTS DEL LA PRIMERA FILA  -->
                   <div class="form-row">
                        <div class="col-md-3 mb-3">
                            <label class="font-weight-bold" for="fecha">Fecha Ingreso</label>
                            <input name="fecha_ingreso" type="date" class="form-control" id="id-fecha" value="{{lista.1.newParam.fecha_ingreso}}">
                        </div>

                       <div class="col-md-3 mb-3">
                           <label class="font-weight-bold"  for="cargo">Cargo</label>
                           <select name="cargo" class="custom-select"     >
                               <option value="{{lista.1.newParam.id_cargo}}"   selected="selected">{{lista.1.newParam.nomb_cargo}}</option>
                              {{#each lista}}
                              {{#each lista_cargos}}
                                <option value="{{id_cargo}}"  >{{descripcion}}</option>
                              {{/each}}
                              {{/each}} 
                           </select>
                        </div>

                       <div class="col-md-3 mb-3">
                           <label class="font-weight-bold"  for="status">Status</label>
                           <select name="status" class="custom-select"     >
                                <option value="{{lista.1.newParam.status}}"   selected="selected">{{lista.1.newParam.status}}</option>
                                <option value="Activo"   >Activo</option>
                                <option value="Vacaciones"   >Vacaciones</option>
                                <option value="Inactivo"   >Inactivo</option>
                           </select>
                        </div>

                <div class="form-row">
                      <div class="col-md-10 mb-3">
                            <label class="font-weight-bold" for="descliente">Foto</label> 
                            <div class="input-group">
                                <input   name  ="image" id="file" type="file"  accept=".jpg, .png, .jpeg, .gif, .bmp, .tif, .tiff|image/*" />
                                    <hr>      
                                    <div id="preview"></div>
                            </div>
                       </div>
                </div>


                   </div> <!-- FIN DE LABELS E INPUTS DEL LA SEGUNDA FILA  -->
                  <div class="form-row">
                     <!-- COMIENZO DE la CUARTA linea ROW-->
                            <div class="col-md-8 mb-3">
                              <div class="input-group">                               

                              </div>
                            </div>
                            <div class="col-md-2 mb-3">
                              <div class="input-group">                               
                               <button class="btn btn-success"  onclick= "cambiarstatus(0)"  type="submit">Save</button>
                              </div>
                            </div>
                            <div class="col-md-2 mb-3">
                              <div class="input-group">                               
                                <button id="btnCrear"    class="btn btn-danger" onclick= "cambiarstatus(1)"  >Close</button>
                              </div>
                            </div>
                  </div>


               </form>
            </div>
         </div>
      </div>
   </div>
</div>

<script src= "/jquery/dist/jquery.js"  ></script> 

<script>
document.getElementById("file").onchange = function(e) {
	let reader = new FileReader();
      reader.onload = function(){
    let  preview = document.getElementById('preview'),
    		image = document.createElement('img');
    image.src = reader.result;
    preview.innerHTML = '';
    preview.append(image);
};
 
  reader.readAsDataURL(e.target.files[0]);
}
//**************
function cargarimagen1(){
    let  preview = document.getElementById('preview'),
    		image = document.createElement('img');
    image.src = document.getElementsByName('imagen1')[0].value ;
    preview.innerHTML = '';
    preview.append(image);

}
//*****
</script>

<script>
    $(document).ready(function() {   
        cargarimagen1();
    });    
</script>


<script>
   function cambiarstatus(valor) {
      document.getElementsByName('tipo_de_submit')[0].value = valor;
   }
</script>

<script>

   (function () {
      'use strict';
      window.addEventListener('load', function () {
         // Fetch all the forms we want to apply custom Bootstrap validation styles to
         var forms = document.getElementsByClassName('needs-validation');
         // Loop over them and prevent submission
         var validation = Array.prototype.filter.call(forms, function (form) {
            form.addEventListener('submit', function (event) {
               if (form.checkValidity() === false) {
                  if (parseInt(document.getElementsByName('tipo_de_submit')[0].value) <= 0) {
                      event.preventDefault();
                      event.stopPropagation();
                  }
               }
               form.classList.add('was-validated');
            }, false);
         });
      }, false);
   });


</script>
