{% extends 'base.html.twig' %}
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('plugins/datatables-bs4/css/dataTables.bootstrap4.min.css') }}">
<link rel="stylesheet" href="{{ asset('plugins/datatables-responsive/css/responsive.bootstrap4.min.css') }}">
<link rel="stylesheet" href="{{ asset('plugins/datatables-buttons/css/buttons.bootstrap4.min.css')}}">
<style>
td.descripcion {
max-width: 300px !important;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
</style>
{% endblock %}
{% block title %}Áreas{% endblock %}
{% block body %}
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="card">
<div class="card-header">
<h1 class="card-title">Ubicación</h1>
<div class="card-tools">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item">Lista</li>
<li class="breadcrumb-item active">Ubicaciones</li>
</ol>
</div>
</div>
</div>
</section>
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="card">
<div class="card-header">
<div class="row">
{{ form_start(form, {'attr': {'class': 'form-inline col-md-auto', 'id': 'form_unidad_filtro'}}) }}
{{ form_row(form.filtro) }}
{% if form.unidad is defined %}
{{ form_row(form.unidad) }}
{% endif %}
{{ form_end(form) }}
<div class="col text-right">
<button id="descargar_excel" type="button" class="btn btn-outline-success mr-2" onclick="descargarExcel()">
<i class="fas fa-file-excel mr-2"></i> Descargar
</button>
{% if nivel <= 2 %}{# Modificar #}
<a href="{{ path('app_ubicacion_new') }}" class="btn btn-outline-success">
<i class="fas fa-file mr-2"></i> Agregar Ubicación
</a>
{% endif %}
</div>
</div>
</div>
<div class="card-body">
<table class="table table-striped w-100" id="table-ubicacion">
<thead>
<tr>
<th>ID</th>
<th>Ubicación</th>
<th>Unidad</th>
<th class="text-center">Estatus</th>
<th class="text-center">Acciones</th>
</tr>
</thead>
<tbody>
{% for ubicacion in ubicacions %}
<tr id="idUbi-{{ ubicacion.idUbi }}">
<td class="id">{{ ubicacion.idUbi }}</td>
<td class="area">{{ ubicacion.area }}</td>
<td class="unidad">{{ ubicacion.unidad}}</td>
<td class="activo">
{% if ubicacion.activo == 1 %}
<span class="badge bg-gradient-primary d-block">Activo</span>
{% elseif ubicacion.activo == 0 %}
<span class="badge bg-gradient-yellow d-block">Inactivo</span>
{% endif %}
</td>
<td class="text-center">
<a href="#editar-ubicacion" onclick="editarInforUbicacion('{{ path('app_ubicacion_show', {'idUbi': ubicacion.idUbi}) }}')" data-toggle="modal"><i class="fas fa-eye"></i></a>
{% if nivel <= 2 %}{# modificar #}
|
{#<a href="{{ path('app_ubicacion_show', {'idUbi': ubicacion.idUbi}) }}"><i class="fas fa-eye"></i></a>
<a href="{{ path('app_ubicacion_edit', {'idUbi': ubicacion.idUbi}) }}"><i class="fas fa-file"></i></a>#}
<a href="#editar-ubicacion" onclick="editarInforUbicacion('{{ path('app_ubicacion_edit', {'idUbi': ubicacion.idUbi}) }}')" data-toggle="modal"><i class="fas fa-pen"></i></a>
{% endif %}
</td>
</tr>
{% else %}
<tr>
<td colspan="3">no records found</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<!-- /.card -->
</section>
<!-- /.content -->
</div>
<div class="modal hide" id="editar-ubicacion"></div>
{% endblock%}
{% block javascripts %}
<script src="{{ asset('plugins/datatables/jquery.dataTables.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-bs4/js/dataTables.bootstrap4.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-responsive/js/dataTables.responsive.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-responsive/js/responsive.bootstrap4.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-buttons/js/dataTables.buttons.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-buttons/js/buttons.bootstrap4.min.js') }}"></script>
<script src="{{ asset('plugins/jszip/jszip.min.js') }}"></script>
<script src="{{ asset('plugins/pdfmake/pdfmake.min.js') }}"></script>
<script src="{{ asset('plugins/pdfmake/vfs_fonts.js') }}"></script>
<script src="{{ asset('plugins/datatables-buttons/js/buttons.html5.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-buttons/js/buttons.print.min.js') }}"></script>
<script src="{{ asset('plugins/datatables-buttons/js/buttons.colVis.min.js') }}"></script>
<script type="text/javascript">
// Menu lateral
$("#catalogo").addClass("menu-open");
$("#catalogo").find('.nav-link:first').addClass("active");
$("#ubicacion").addClass("active");
$(function () {
/*$("#table-ubicacion").DataTable({
"responsive": true,
"lengthChange": true,
"autoWidth": true,
"language": {
url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
} ,
"buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
}) .buttons().container().appendTo('#table-ubicacion_wrapper .col-md-6:eq(0)');*/
$('#example2').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"responsive": true,
});
// DataTable
$('#table-ubicacion').DataTable({
"aaSorting": [],
orderCellsTop: true,
{# Define un valor predeterminado para LengthChange #}
"pageLength": 10,
"scrollX": true,
{# sDom: 'lrtip', #}
"bLengthChange" : true,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
},
});
{% if form.unidad is defined %}
$("#unidad_filtro_unidad").on('change', function () {
aplicarFiltro();
});
{% endif %}
});
function editarInforUbicacion(url){
$('#editar-ubicacion').load(url, function ()
{
// configuración del Modal
$("#editar-ubicacion").on('hide.bs.modal', function () {
$(this).html('Cargando');
});
$(".modal-dialog").draggable;
editarInforUbicacionAjax(url)
})
}
function editarInforUbicacionAjax(url){
let send = $("#btn_ubicacion_guardar");
$('#btn_ubicacion_guardar').on('click', function () {
let formData = new FormData(document.getElementById("form-editar-ubicacion"));
$.ajax({
type: "POST",
url: url,
data: formData, // Adjuntar los campos del formulario enviado.
dataType: "json",
cache: false,
contentType: false,
processData: false,
beforeSend: function () {
send.text("Actualizando "); // Para input de tipo button
send.append("<i class='fa fa-spinner fa-spin' style='font-size:16px'></i>");
send.prop("disabled", true);
},
success: function (data) {
console.log(data);
let datos = data;
let row = $('#idUbi-' + datos.idUbi);
row.find('.area').html(datos.area);
row.find('.unidad').html(datos.unidad.getNombre);
//row.find('.activo').html(datos.activo);
if (datos.activo === "Activo") {
row.find('.activo').html('<div class="badge bg-gradient-primary d-block">' + datos.activo + '</div>');
}
if(datos.activo === "Inactivo") {
row.find('.activo').html('<div class="badge bg-gradient-yellow d-block">' + datos.activo + '</div>');
}
$("#editar-ubicacion").modal('hide');
},
error: function (data, text, error) {
let datos = data.responseJSON;
$("#editar-ubicacion").html(datos.form);
editarInforUbicacionAjax(url);
},
complete: function (data) {
// Se ejecuta al termino de la petición
}
});
return false; // Evitar ejecutar el submit del formulario.
});
}
<!-- Actualizar tabla de bitácora -->
function actualizarUbicacion(data) {
$("#table-ubicacion").dataTable().fnClearTable();
$("#table-ubicacion").dataTable().fnDestroy();
var edit = "";
var html = "";
$.each(data, function (key, ubicacion) {
if (nivel in [2]){ {# modificar #}
edit = ' | <a href="#editar-ubicacion" onclick="editarInforUbicacion(\'' + ubicacion.editar + '\')" data-toggle="modal"><i class="fas fa-pen"></i></a>';
}
html += '<tr id="idUbi' + ubicacion.idUbi + '">' +
'<td>' + ubicacion.area + '</td>' +
'<td>' + ubicacion.unidad + '</td>' +
'<td class="activo">' + ubicacion.activo + '</td>' +
'<td class="text-right">' +
'<a href="' + ubicacion.ver + '"><i class="fas fa-eye"></i></a>' + edit +
'</td>' +
'</tr>';
});
$("#table-ubicacion").find($("tbody")).html(html);
$('#table-ubicacion').DataTable({
"aaSorting": [],
orderCellsTop: true,
{# Define un valor predeterminado para LengthChange #}
"pageLength": 10,
"scrollX": true,
{# sDom: 'lrtip', #}
"bLengthChange" : true,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.10.22/i18n/Spanish.json'
},
});
}
function cambiarEstatus(url, accion) {
$.ajax({
url: url,
dataType: "json",
cache: false,
contentType: false,
processData: false,
success: function (data) {
let datos = data;
let row = $('#idUbi-'+ datos.idUbi);
if (accion === "Activo"){
row.find('.activo').html('<div class="badge bg-gradient-primary d-block">' + datos.activo + '</div>');
} else {
row.find('.activo').html('<div class="badge bg-gradient-yellow d-block">' + datos.activo + '</div>');
}
//alertMessage(0, datos.mensaje);
},
error: function (data, text, error) {
alertMessage(1, error);
},
complete: function (data) {
// Se ejecuta al termino de la petición
}
});
}
function aplicarFiltro() {
$("#table-otro").find($("tbody")).html("<tr><td colspan='8' class='text-center'><i class='fas fa-spinner fa-pulse'></i></td></tr>");
let formData = new FormData(document.getElementById("form_unidad_filtro"));
$.ajax({
type: "POST",
url: '{{ path('app_ubicacion_index') }}',
data: formData, // Adjuntar los campos del formulario enviado.
dataType: "html",
cache: false,
contentType: false,
processData: false,
success: function (data) {
let datos = jQuery.parseJSON(data);
console.log(datos);
actualizarOtro(datos);
},
error: function (data, text, error) {
let datos = jQuery.parseJSON(data.responseText);
console.log(datos);
}
});
}
function descargarExcel() {
let btn = $("#descargar_excel");
let formData = new FormData(document.getElementById("form_unidad_filtro"));
$.ajax({
type: "POST",
url: '{{ path('app_reporte_ubicacion_excel') }}',
data: formData, // Adjuntar los campos del formulario enviado.
cache: false,
contentType: false,
processData: false,
xhrFields: {
responseType: 'blob'
},
beforeSend: function () {
btn.prop('disabled', true);
btn.html("<i class='fas fa-spinner fa-pulse'></i> Descargar");
},
success: function (data) {
let a = document.createElement('a');
a.href = window.URL.createObjectURL(data);
a.download = "Ubicaciones-Área.xlsx"
a.click();
},
complete: function () {
btn.prop('disabled', false);
btn.html("<i class='fas fa-file-excel mr-2'></i> Descargar");
}
});
}
</script>
{% endblock %}