templates/ubicacion/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block stylesheets %}
  3.     <link rel="stylesheet" href="{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css') }}">
  4.     <link rel="stylesheet" href="{{ asset('plugins/datatables-responsive/css/responsive.bootstrap4.min.css') }}">
  5.     <link rel="stylesheet" href="{{ asset('plugins/datatables-buttons/css/buttons.bootstrap4.min.css')}}">
  6.     <style>
  7.         td.descripcion {
  8.             max-width: 300px !important;
  9.             text-overflow: ellipsis;
  10.             white-space: nowrap;
  11.             overflow: hidden;
  12.         }
  13.     </style>
  14. {% endblock %}
  15. {% block title %}Áreas{% endblock %}
  16. {% block body %}
  17.     <div class="content-wrapper">
  18.         <!-- Content Header (Page header) -->
  19.         <section class="content-header">
  20.             <div class="card">
  21.                 <div class="card-header">
  22.                     <h1 class="card-title">Ubicación</h1>
  23.                     <div class="card-tools">
  24.                         <ol class="breadcrumb float-sm-right">
  25.                             <li class="breadcrumb-item">Lista</li>
  26.                             <li class="breadcrumb-item active">Ubicaciones</li>
  27.                         </ol>
  28.                     </div>
  29.                 </div>
  30.             </div>
  31.         </section>
  32.         <!-- Main content -->
  33.         <section class="content">
  34.             <!-- Default box -->
  35.             <div class="card">
  36.                 <div class="card-header">
  37.                     <div class="row">
  38.                         {{ form_start(form, {'attr': {'class': 'form-inline col-md-auto', 'id': 'form_unidad_filtro'}}) }}
  39.                         {{ form_row(form.filtro) }}
  40.                         {% if form.unidad is defined %}
  41.                             {{ form_row(form.unidad) }}
  42.                         {% endif %}
  43.                         {{ form_end(form) }}
  44.                         <div class="col text-right">
  45.                             <button id="descargar_excel" type="button" class="btn btn-outline-success mr-2" onclick="descargarExcel()">
  46.                                 <i class="fas fa-file-excel mr-2"></i> Descargar
  47.                             </button>
  48.                             {% if nivel <= 2 %}{# Modificar #}
  49.                                 <a href="{{ path('app_ubicacion_new') }}" class="btn btn-outline-success">
  50.                                     <i class="fas fa-file mr-2"></i> Agregar Ubicación
  51.                                 </a>
  52.                             {% endif %}
  53.                         </div>
  54.                     </div>
  55.                 </div>
  56.                 <div class="card-body">
  57.                       <table class="table table-striped w-100" id="table-ubicacion">
  58.                         <thead>
  59.                         <tr>
  60.                             <th>ID</th>
  61.                             <th>Ubicación</th>
  62.                             <th>Unidad</th>
  63.                             <th class="text-center">Estatus</th>
  64.                             <th class="text-center">Acciones</th>
  65.                         </tr>
  66.                         </thead>
  67.                         <tbody>
  68.                         {% for ubicacion in ubicacions %}
  69.                             <tr id="idUbi-{{ ubicacion.idUbi }}">
  70.                                 <td class="id">{{ ubicacion.idUbi }}</td>
  71.                                 <td class="area">{{ ubicacion.area }}</td>
  72.                                 <td class="unidad">{{ ubicacion.unidad}}</td>
  73.                                 <td class="activo">
  74.                                     {% if ubicacion.activo  == 1 %}
  75.                                         <span class="badge bg-gradient-primary d-block">Activo</span>
  76.                                     {% elseif ubicacion.activo  == 0 %}
  77.                                         <span class="badge bg-gradient-yellow d-block">Inactivo</span>
  78.                                     {% endif %}
  79.                                 </td>
  80.                                 <td class="text-center">
  81.                                     <a href="#editar-ubicacion" onclick="editarInforUbicacion('{{ path('app_ubicacion_show', {'idUbi': ubicacion.idUbi}) }}')" data-toggle="modal"><i class="fas fa-eye"></i></a>
  82.                                     {% if nivel <= 2 %}{# modificar #}
  83.                                         &nbsp;|&nbsp;
  84.                                         {#<a href="{{ path('app_ubicacion_show', {'idUbi': ubicacion.idUbi}) }}"><i class="fas fa-eye"></i></a>
  85.                                     <a href="{{ path('app_ubicacion_edit', {'idUbi': ubicacion.idUbi}) }}"><i class="fas fa-file"></i></a>#}
  86.                                         <a href="#editar-ubicacion" onclick="editarInforUbicacion('{{ path('app_ubicacion_edit', {'idUbi': ubicacion.idUbi}) }}')" data-toggle="modal"><i class="fas fa-pen"></i></a>
  87.                                     {% endif %}
  88.                                 </td>
  89.                             </tr>
  90.                         {% else %}
  91.                             <tr>
  92.                                 <td colspan="3">no records found</td>
  93.                             </tr>
  94.                         {% endfor %}
  95.                         </tbody>
  96.                     </table>
  97.                 </div>
  98.             </div>
  99.             <!-- /.card -->
  100.         </section>
  101.         <!-- /.content -->
  102.     </div>
  103.     <div class="modal hide" id="editar-ubicacion"></div>
  104. {% endblock%}
  105. {% block javascripts %}
  106.     <script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
  107.     <script src="{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
  108.     <script src="{{ asset('plugins/datatables-responsive/js/dataTables.responsive.min.js') }}"></script>
  109.     <script src="{{ asset('plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }}"></script>
  110.     <script src="{{ asset('plugins/datatables-buttons/js/dataTables.buttons.min.js') }}"></script>
  111.     <script src="{{ asset('plugins/datatables-buttons/js/buttons.bootstrap4.min.js') }}"></script>
  112.     <script src="{{ asset('plugins/jszip/jszip.min.js') }}"></script>
  113.     <script src="{{ asset('plugins/pdfmake/pdfmake.min.js') }}"></script>
  114.     <script src="{{ asset('plugins/pdfmake/vfs_fonts.js') }}"></script>
  115.     <script src="{{ asset('plugins/datatables-buttons/js/buttons.html5.min.js') }}"></script>
  116.     <script src="{{ asset('plugins/datatables-buttons/js/buttons.print.min.js') }}"></script>
  117.     <script src="{{ asset('plugins/datatables-buttons/js/buttons.colVis.min.js') }}"></script>
  118.     <script type="text/javascript">
  119.         // Menu lateral
  120.         $("#catalogo").addClass("menu-open");
  121.         $("#catalogo").find('.nav-link:first').addClass("active");
  122.         $("#ubicacion").addClass("active");
  123.         $(function () {
  124.              /*$("#table-ubicacion").DataTable({
  125.                 "responsive": true,
  126.                 "lengthChange": true,
  127.                 "autoWidth": true,
  128.                 "language": {
  129.                     url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
  130.                 } ,
  131.                 "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
  132.             }) .buttons().container().appendTo('#table-ubicacion_wrapper .col-md-6:eq(0)');*/
  133.             $('#example2').DataTable({
  134.                 "paging": true,
  135.                 "lengthChange": true,
  136.                 "searching": true,
  137.                 "ordering": true,
  138.                 "info": true,
  139.                 "autoWidth": true,
  140.                 "responsive": true,
  141.             });
  142.             // DataTable
  143.             $('#table-ubicacion').DataTable({
  144.                 "aaSorting": [],
  145.                 orderCellsTop: true,
  146.                 {# Define un valor predeterminado para LengthChange #}
  147.                 "pageLength": 10,
  148.                 "scrollX": true,
  149.                 {# sDom: 'lrtip', #}
  150.                 "bLengthChange" : true,
  151.                 language: {
  152.                     url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
  153.                 },
  154.             });
  155.             {% if form.unidad is defined %}
  156.             $("#unidad_filtro_unidad").on('change', function () {
  157.                 aplicarFiltro();
  158.             });
  159.             {% endif %}
  160.         });
  161.         function editarInforUbicacion(url){
  162.             $('#editar-ubicacion').load(url, function ()
  163.             {
  164.                 // configuración del Modal
  165.                 $("#editar-ubicacion").on('hide.bs.modal', function () {
  166.                     $(this).html('Cargando');
  167.                 });
  168.                 $(".modal-dialog").draggable;
  169.                 editarInforUbicacionAjax(url)
  170.             })
  171.         }
  172.         function editarInforUbicacionAjax(url){
  173.             let send = $("#btn_ubicacion_guardar");
  174.             $('#btn_ubicacion_guardar').on('click', function () {
  175.                 let formData = new FormData(document.getElementById("form-editar-ubicacion"));
  176.                 $.ajax({
  177.                     type: "POST",
  178.                     url: url,
  179.                     data: formData, // Adjuntar los campos del formulario enviado.
  180.                     dataType: "json",
  181.                     cache: false,
  182.                     contentType: false,
  183.                     processData: false,
  184.                     beforeSend: function () {
  185.                         send.text("Actualizando "); // Para input de tipo button
  186.                         send.append("<i class='fa fa-spinner fa-spin' style='font-size:16px'></i>");
  187.                         send.prop("disabled", true);
  188.                     },
  189.                     success: function (data) {
  190.                         console.log(data);
  191.                         let datos = data;
  192.                         let row = $('#idUbi-' + datos.idUbi);
  193.                         row.find('.area').html(datos.area);
  194.                         row.find('.unidad').html(datos.unidad.getNombre);
  195.                         //row.find('.activo').html(datos.activo);
  196.                         if (datos.activo === "Activo") {
  197.                             row.find('.activo').html('<div class="badge bg-gradient-primary d-block">' + datos.activo + '</div>');
  198.                         }
  199.                         if(datos.activo === "Inactivo") {
  200.                             row.find('.activo').html('<div class="badge bg-gradient-yellow d-block">' + datos.activo + '</div>');
  201.                         }
  202.                         $("#editar-ubicacion").modal('hide');
  203.                     },
  204.                     error: function (data, text, error) {
  205.                         let datos = data.responseJSON;
  206.                         $("#editar-ubicacion").html(datos.form);
  207.                         editarInforUbicacionAjax(url);
  208.                     },
  209.                     complete: function (data) {
  210.                         // Se ejecuta al termino de la petición
  211.                     }
  212.                 });
  213.                 return false; // Evitar ejecutar el submit del formulario.
  214.             });
  215.         }
  216.         <!-- Actualizar tabla de bitácora -->
  217.         function actualizarUbicacion(data) {
  218.             $("#table-ubicacion").dataTable().fnClearTable();
  219.             $("#table-ubicacion").dataTable().fnDestroy();
  220.             var edit = "";
  221.             var html = "";
  222.             $.each(data, function (key, ubicacion) {
  223.                 if (nivel in [2]){ {# modificar #}
  224.                     edit = '&nbsp;|&nbsp;<a href="#editar-ubicacion" onclick="editarInforUbicacion(\'' + ubicacion.editar + '\')" data-toggle="modal"><i class="fas fa-pen"></i></a>';
  225.                 }
  226.                 html += '<tr id="idUbi' + ubicacion.idUbi + '">' +
  227.                     '<td>' + ubicacion.area + '</td>' +
  228.                     '<td>' + ubicacion.unidad + '</td>' +
  229.                     '<td class="activo">' + ubicacion.activo + '</td>' +
  230.                     '<td class="text-right">' +
  231.                     '<a href="' + ubicacion.ver + '"><i class="fas fa-eye"></i></a>' + edit +
  232.                     '</td>' +
  233.                     '</tr>';
  234.             });
  235.             $("#table-ubicacion").find($("tbody")).html(html);
  236.             $('#table-ubicacion').DataTable({
  237.                 "aaSorting": [],
  238.                 orderCellsTop: true,
  239.                 {# Define un valor predeterminado para LengthChange #}
  240.                 "pageLength": 10,
  241.                 "scrollX": true,
  242.                 {# sDom: 'lrtip', #}
  243.                 "bLengthChange" : true,
  244.                 language: {
  245.                     url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
  246.                 },
  247.             });
  248.         }
  249.         function cambiarEstatus(url, accion) {
  250.             $.ajax({
  251.                 url: url,
  252.                 dataType: "json",
  253.                 cache: false,
  254.                 contentType: false,
  255.                 processData: false,
  256.                 success: function (data) {
  257.                     let datos = data;
  258.                     let row = $('#idUbi-'+ datos.idUbi);
  259.                     if (accion === "Activo"){
  260.                         row.find('.activo').html('<div class="badge bg-gradient-primary d-block">' + datos.activo + '</div>');
  261.                     } else {
  262.                         row.find('.activo').html('<div class="badge bg-gradient-yellow d-block">' + datos.activo + '</div>');
  263.                     }
  264.                     //alertMessage(0, datos.mensaje);
  265.                 },
  266.                 error: function (data, text, error) {
  267.                     alertMessage(1, error);
  268.                 },
  269.                 complete: function (data) {
  270.                     // Se ejecuta al termino de la petición
  271.                 }
  272.             });
  273.         }
  274.         function aplicarFiltro() {
  275.             $("#table-otro").find($("tbody")).html("<tr><td colspan='8' class='text-center'><i class='fas fa-spinner fa-pulse'></i></td></tr>");
  276.             let formData = new FormData(document.getElementById("form_unidad_filtro"));
  277.             $.ajax({
  278.                 type: "POST",
  279.                 url: '{{ path('app_ubicacion_index') }}',
  280.                 data: formData, // Adjuntar los campos del formulario enviado.
  281.                 dataType: "html",
  282.                 cache: false,
  283.                 contentType: false,
  284.                 processData: false,
  285.                 success: function (data) {
  286.                     let datos = jQuery.parseJSON(data);
  287.                     console.log(datos);
  288.                     actualizarOtro(datos);
  289.                 },
  290.                 error: function (data, text, error) {
  291.                     let datos = jQuery.parseJSON(data.responseText);
  292.                     console.log(datos);
  293.                 }
  294.             });
  295.         }
  296.         function descargarExcel() {
  297.             let btn = $("#descargar_excel");
  298.             let formData = new FormData(document.getElementById("form_unidad_filtro"));
  299.             $.ajax({
  300.                 type: "POST",
  301.                 url: '{{ path('app_reporte_ubicacion_excel') }}',
  302.                 data: formData, // Adjuntar los campos del formulario enviado.
  303.                 cache: false,
  304.                 contentType: false,
  305.                 processData: false,
  306.                 xhrFields: {
  307.                     responseType: 'blob'
  308.                 },
  309.                 beforeSend: function () {
  310.                     btn.prop('disabled', true);
  311.                     btn.html("<i class='fas fa-spinner fa-pulse'></i> Descargar");
  312.                 },
  313.                 success: function (data) {
  314.                     let a = document.createElement('a');
  315.                     a.href = window.URL.createObjectURL(data);
  316.                     a.download = "Ubicaciones-Área.xlsx"
  317.                     a.click();
  318.                 },
  319.                 complete: function () {
  320.                     btn.prop('disabled', false);
  321.                     btn.html("<i class='fas fa-file-excel mr-2'></i> Descargar");
  322.                 }
  323.             });
  324.         }
  325.     </script>
  326. {% endblock %}