implementado calles en maquinas

This commit is contained in:
Jaime Jimenez
2023-09-22 12:52:20 +02:00
parent dee333dc41
commit ef7f249cd6
10 changed files with 692 additions and 39 deletions

View File

@ -63,6 +63,39 @@
</div> <!-- //.accordion -->
<?php endif; ?>
<?php if(str_contains($formAction,'edit')): ?>
<div class="accordion mt-3" id="accordianPapelesCalles">
<div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne">
<button type="button" class="accordion-button" data-bs-toggle="collapse" data-bs-target="#accordionTip3" aria-expanded="false" aria-controls="accordionTip3">
<h3><?= lang("MaquinasCalles.moduleTitle") ?></h3>
</button>
</h2>
<div id="accordionTip3" class="accordion-collapse collapse show" data-bs-parent="#accordianPapelesCalles">
<div class="accordion-body">
<table id="tableOfCalles" class="table table-striped table-hover" style="width: 100%;">
<thead>
<tr>
<th><?= lang('MaquinasCalles.formas_min') ?></th>
<th><?= lang('MaquinasCalles.formas_max') ?></th>
<th><?= lang('MaquinasCalles.internas') ?></th>
<th><?= lang('MaquinasCalles.externas') ?></th>
<th class="text-nowrap"><?= lang('Basic.global.Action') ?></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div> <!-- //.accordion -->
<?php endif; ?>
<?php if(str_contains($formAction,'edit')): ?>
<div class="accordion mt-3" id="accordianPapelesImpresion">
@ -110,6 +143,9 @@
<?= $this->endSection() ?>
<?= $this->section("additionalInlineJs") ?>
const lastColNr2 = $('#tableOfPapelesImpresion').find("tr:first th").length - 1;
@ -223,9 +259,9 @@
const actionBtns = function(data) {
return `
<span class="edit"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></span>
<span class="edit"><a href="javascript:void(0);"><i class="ti ti-pencil ti-sm btn-edit mx-2" data-id="${data.id}"></i></a></span>
<a href="javascript:void(0);"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}" data-bs-toggle="modal" data-bs-target="#confirm2delete"></i></a>
<span class="cancel"></span>
<span class="remove"><i class="ti ti-trash ti-sm btn-delete mx-2" data-id="${data.id}"></i></span>
`;
};
@ -432,7 +468,7 @@
editor: editor,
formOptions: {
submitTrigger: -1,
submitHtml: '<i class="ti ti-device-floppy"/>'
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
}
} ]
} );
@ -520,9 +556,9 @@
editor.inline(
theTable.cells(this.parentNode.parentNode, '*').nodes(),
{
cancelHtml: '<i class="ti ti-x"></i>',
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<i class="ti ti-device-floppy"></i>',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
submitTrigger: 'span.edit',
submit: 'allIfChanged'
}
@ -539,37 +575,199 @@
});
// Delete row
$('#tableOfMaquinastarifasimpresion').on( 'click', 'tbody span.remove', function (e) {
$(document).on('click', '.btn-delete', function(e) {
$(".btn-remove").attr('data-id', $(this).attr('data-id'));
const row = $(this).closest('tr')[0]._DT_RowIndex;
Swal.fire({
title: '<?= lang('Basic.global.sweet.sureToDeleteTitle', [mb_strtolower(lang('Basic.global.sweet.line'))]) ?>',
text: '<?= lang('Basic.global.sweet.sureToDeleteText') ?>',
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
confirmButtonText: '<?= lang('Basic.global.sweet.deleteConfirmationButton') ?>',
cancelButtonText: '<?= lang('Basic.global.Cancel') ?>',
cancelButtonColor: '#d33'
})
.then((result) => {
const dataId = $(this).data('id');
const row = $(this).closest('tr');
if (result.value) {
editor
.create( false )
.edit( this.parentNode, false)
.set( 'deleted_at', new Date().toISOString().slice(0, 19).replace('T', ' ') )
.set( 'is_deleted', 1 )
.submit();
}
});
if($(this).closest('table').attr('id').includes('tarifas')){
$(".btn-remove").attr('table', "tarifas");
$(".btn-remove").attr('row_index', row);
}
else if($(this).closest('table').attr('id').includes('Calles')){
$(".btn-remove").attr('table', "calles");
$(".btn-remove").attr('row_index', row);
}
else{
$(".btn-remove").attr('table', );
}
});
$(document).on('click', '.btn-remove', function(e) {
const dataId = $(this).attr('data-id');
const row = $(this).attr('row_index');
if ($.isNumeric(dataId)) {
if($(this).attr('table').includes('tarifas')){
remove_tarifas(dataId, row);
}
else if ($(this).attr('table').includes('calles')){
remove_calles(dataId, row);
}
}
});
function remove_calles(dataId, row){
$.ajax({
url: `/maquinascalles/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');
theTable3.clearPipeline();
theTable3.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
});
};
function remove_tarifas(dataId, row){
$.ajax({
url: `/maquinastarifasimpresion/delete/${dataId}`,
method: 'GET',
}).done((data, textStatus, jqXHR) => {
$('#confirm2delete').modal('toggle');
theTable.clearPipeline();
theTable.row($(row)).invalidate().draw();
popSuccessAlert(data.msg ?? jqXHR.statusText);
}).fail((jqXHR, textStatus, errorThrown) => {
popErrorAlert(jqXHR.responseJSON.messages.error)
});
}
<?= $this->endSection() ?>
<!------------------------------------------->
<!-- Código JS para tabla calles -->
<!------------------------------------------->
<?= $this->section("additionalInlineJs") ?>
var editor3 = new $.fn.dataTable.Editor( {
ajax: {
url: "<?= route_to('editorOfMaquinascalles') ?>",
headers: {
<?= csrf_token() ?? "token" ?> : <?= csrf_token() ?>v,
},
},
table : "#tableOfCalles",
idSrc: 'id',
fields: [ {
name: "formas_min"
}, {
name: "formas_max"
}, {
name: "internas"
}, {
name: "externas"
}, {
"name": "maquina_id",
"type": "hidden"
},{
"name": "deleted_at",
"type": "hidden"
},{
"name": "is_deleted",
"type": "hidden"
},
]
} );
editor3.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['maquina_id'] = id;
}
else if(type === 'edit' ) {
for (v in d.data){
d.data[v]['maquina_id'] = id;
}
}
});
editor3.on( 'postSubmit', function ( e, json, data, action ) {
yeniden(json.<?= csrf_token() ?>);
});
editor3.on( 'submitSuccess', function ( e, json, data, action ) {
theTable3.clearPipeline();
theTable3.draw();
});
theTable3 = $('#tableOfCalles').DataTable({
processing: true,
serverSide: true,
autoWidth: true,
responsive: true,
scrollX: true,
lengthMenu: [ 5],
pageLength: 10,
lengthChange: false,
searching: false,
info: false,
"dom": '<"mt-4"><"float-end"B><"float-start"l><t><"mt-4 mb-3"p>',
stateSave: true,
language: {
url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/<?= config('Basics')->i18n ?>.json"
},
ajax : $.fn.dataTable.pipeline( {
url: '<?= route_to('dataTableOfMaquinascalles') ?>',
data: {
maquina_id: id,
},
method: 'POST',
headers: {'X-Requested-With': 'XMLHttpRequest'},
async: true,
}),
columns : [
{ 'data': 'formas_min' },
{ 'data': 'formas_max' },
{ 'data': 'internas' },
{ 'data': 'externas' },
{ data: actionBtns,
className: 'row-edit dt-center'}
],
buttons: [ {
className: 'btn btn-primary float-end me-sm-3 me-1',
extend: "createInline",
editor: editor3,
formOptions: {
submitTrigger: -1,
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>'
}
} ]
});
// Activate an inline edit on click of a table cell
$('#tableOfCalles').on( 'click', 'tbody span.edit', function (e) {
editor3.inline(
theTable3.cells(this.parentNode.parentNode, '*').nodes(),
{
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
cancelTrigger: 'span.cancel',
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
submitTrigger: 'span.edit',
submit: 'allIfChanged'
}
);
} );
<?= $this->endSection() ?>
<?=$this->section('css') ?>
<link rel="stylesheet" href="<?= site_url('themes/vuexy/css/datatables-editor/editor.dataTables.min.css') ?>">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.bootstrap5.min.css">