templates/almacen/articulo/index.html.twig line 1

Open in your IDE?
  1. {% extends 'navbar.html.twig' %}
  2. {% block title %}Articulos{% endblock %}
  3. {% block content_user %}
  4.     <h5>Articulos</h5>
  5.     <style>
  6.         select.form-select {
  7.            
  8.         }
  9.     </style>
  10.     {% set selectAplicaciones %}
  11.         <select class="form-control form-control-sm form-select change-aplication">
  12.             <option value=""></option>
  13.             {% for aplicacion in aplicaciones %}
  14.                 <option value="{{ aplicacion.id }}">{{ aplicacion.nombre }}</option>
  15.             {% endfor %}
  16.         </select>
  17.     {% endset %}
  18.     <table id="example" class="table table-striped table-bordered table-hover">
  19.         <thead>
  20.             <tr>
  21.                 <th>Activo</th>
  22.                 <th>Codigo</th>
  23.                 <th>Descripcion</th>
  24.                 <th>Categoria</th>
  25.                 <th>Unidad Medida</th>
  26.                 <th>Aplicacion</th>
  27.                 <th></th>
  28.                 <th></th>
  29.             </tr>
  30.         </thead>
  31.         <tbody>
  32.         {% for articulo in articulos %}
  33.             <tr>
  34.                 <td>
  35.                     <div class="custom-control custom-switch">
  36.                         <input data-id="{{ articulo.id }}" {{ articulo.activo ? "checked" : "" }} type="checkbox" class="status custom-control-input" id="chk{{ articulo.id }}"/>
  37.                       <label class="custom-control-label pt-1" for="chk{{ articulo.id }}"></label>
  38.                   </div>
  39.                      
  40.                 </td>
  41.                 <td>{{ articulo.codigo }}</td>
  42.                 <td>{{ articulo.descripcion }}</td>
  43.                 <td>{{ articulo.categoria }}</td>
  44.                 <td>{{ articulo.unidaMedida }}</td>
  45.                 <td id="art{{articulo.id}}" data-art="{{ articulo.id }}">{{ articulo.listaAplicaciones }}</td>
  46.                 <td>{{ selectAplicaciones }}</td>
  47.                 <td>
  48.                     <a href="{{ path('app_almacen_articulo_edit', {'id': articulo.id}) }}" class="btn btn-success btn-sm">Modificar</a>
  49.                 </td>
  50.             </tr>
  51.         {% else %}
  52.             <tr>
  53.                 <td colspan="5">no records found</td>
  54.             </tr>
  55.         {% endfor %}
  56.         </tbody>
  57.     </table>
  58.     <a href="{{ path('app_almacen_articulo_new') }}" class="btn btn-default">Nuevo Articulo</a>
  59. {% endblock %}
  60. {% block javascripts_footer %}
  61.     
  62.     {{ parent() }}
  63.     <script type="text/javascript">
  64.         const path = "{{ path('app_almacen_articulo_change_status', { id : '__ID__' }) }}";
  65.         $('.change-aplication').change(function(){
  66.                                         let select = $(this);
  67.                                         let idArticulo = select.closest('tr').find('td[data-art]').data('art');
  68.                                         let idAplicacion = select.val();
  69.                                         $.post("{{ path('app_almacen_articulo_add_aplicacion', { id : '__ID__' }) }}".replace('__ID__', idArticulo),
  70.                                                { aplicacion: idAplicacion },
  71.                                                function(data){
  72.                                                                 if (data.ok) {
  73.                                                                     select.css('border-color', 'green');
  74.                                                                     $('#art' + idArticulo).html(data.aplicacion);
  75.                                                                 } else {
  76.                                                                     select.css('border-color', 'red');
  77.                                                                 }
  78.                                                });
  79.                               
  80.         });
  81.         $('.status').change(function(){
  82.                                         let btn = $(this);
  83.                                         let id = btn.data('id');
  84.                                         $.post(path.replace('__ID__', id),
  85.                                                function(data){
  86.                                                                 console.log(data);
  87.                                                });
  88.                               
  89.         });
  90.         $('#example').DataTable({
  91.                                     fixedHeader: true,
  92.                                     paging: true,
  93.                                     responsive: true,
  94.                                     language: {
  95.                                         url: '{{ asset('i18n/spanish.json') }}'
  96.                                     }
  97.                                 });
  98.     </script>
  99. {% endblock %}