mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
arreglados bugs en plantillas cliente
This commit is contained in:
@ -7,8 +7,10 @@ class ModalYesNo {
|
||||
this.btnCancelId = alias !== "" ? `btnCancelModal-${alias}` : 'btnCancelModal';
|
||||
this.btnConfirmId = alias !== "" ? `btnYesModal-${alias}` : 'btnYesModal';
|
||||
|
||||
this.callback = () => {};
|
||||
|
||||
this.modalHtml = `
|
||||
<div class="modal fade" id="${this.modalId}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="${this.modalId}Label" aria-hidden="true">
|
||||
<div class="modal modalYesNo fade" id="${this.modalId}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="${this.modalId}Label" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
@ -30,13 +32,22 @@ class ModalYesNo {
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
// Insertar el modal en el body del documento si no existe
|
||||
if (!document.getElementById(this.modalId)) {
|
||||
document.body.insertAdjacentHTML('beforeend', this.modalHtml);
|
||||
}
|
||||
document.getElementById(this.btnCancelId).addEventListener('click', () => {
|
||||
const modal = new bootstrap.Modal(document.getElementById(this.modalId));
|
||||
modal.hide();
|
||||
$('#' + this.btnCancelId).on('click', () => {
|
||||
|
||||
$('#' + self.modalId).modal('hide');
|
||||
});
|
||||
|
||||
$('#' + this.btnConfirmId).on('click', () => {
|
||||
|
||||
self.callback(); // Llamar al callback que el usuario haya proporcionado
|
||||
$('#' + self.modalId).modal('hide');
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -47,21 +58,15 @@ class ModalYesNo {
|
||||
// Método para mostrar el modal
|
||||
show(callback) {
|
||||
|
||||
// Mostrar el modal usando Bootstrap
|
||||
const modal = new bootstrap.Modal(document.getElementById(this.modalId));
|
||||
modal.show();
|
||||
this.callback = callback;
|
||||
|
||||
// Configurar el evento de confirmación de eliminación
|
||||
document.getElementById(this.btnConfirmId).addEventListener('click', () => {
|
||||
callback(); // Llamar al callback que el usuario haya proporcionado
|
||||
modal.hide(); // Cerrar el modal
|
||||
});
|
||||
// Mostrar el modal usando Bootstrap
|
||||
$('#' + this.modalId).modal('show');
|
||||
}
|
||||
|
||||
// Método para ocultar el modal si es necesario
|
||||
hide() {
|
||||
const modal = new bootstrap.Modal(document.getElementById(this.modalId));
|
||||
modal.hide();
|
||||
$('#' + this.modalId).modal('hide');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ let Table = function (
|
||||
autoWidth: true,
|
||||
responsive: true,
|
||||
scrollX: true,
|
||||
stateSave: true,
|
||||
stateSave: false,
|
||||
lengthMenu: [5, 10, 25, 50, 75, 100, 250, 500, 1000, 2500],
|
||||
order: order,
|
||||
orderCellsTop: true,
|
||||
|
||||
@ -23,6 +23,11 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
this.localEditor = null;
|
||||
this.ajaxEditor = null;
|
||||
|
||||
this.rows = [];
|
||||
this.rowsDeleted = [];
|
||||
this.rowsEdited = [];
|
||||
this.rowsCreated = [];
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -42,6 +47,20 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
this.#initTable();
|
||||
|
||||
new Ajax(
|
||||
'/clienteplantillaprecioslineas/getrows',
|
||||
{
|
||||
[this.csrf_token]: this.csrf_hash,
|
||||
plantilla_id: this.plantillaId
|
||||
},
|
||||
{},
|
||||
(response) => {
|
||||
self.rows = response.data;
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
).post();
|
||||
|
||||
// Editar en linea la fila
|
||||
this.tablePlantilla.table.on('click', 'tbody span.edit', function (e) {
|
||||
@ -62,10 +81,38 @@ class PlantillasTarifasClienteForm {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
this.tablePlantilla.table.on('draw.dt', function (e) {
|
||||
self.tablePlantilla.table.rows().every(function (rowIdx, tableLoop, rowLoop) {
|
||||
var row = this.data();
|
||||
if (self.rowsDeleted.includes(row.id)) {
|
||||
$('#' + row.id).css('background-color', '#ffcccc');
|
||||
$('#' + row.id).addClass('row-deleted');
|
||||
$('#' + row.id).find('span.edit').addClass('d-none');
|
||||
$('#' + row.id).find('.btn-delete-' + self.tablePlantilla.getAlias()).addClass('d-none');
|
||||
}
|
||||
else if (self.rowsEdited.includes(row.id)) {
|
||||
$('#' + row.id).css('background-color', '#E9DEAC');
|
||||
$('#' + row.id).addClass('row-edited');
|
||||
|
||||
}
|
||||
else if (row.id === '') {
|
||||
self.tablePlantilla.table.row(rowIdx).nodes().to$().addClass('row-created');
|
||||
self.tablePlantilla.table.row(rowIdx).nodes().to$().css('background-color', '#C9E2C7');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.tablePlantilla.table.on('click', '.btn-delete-' + this.tablePlantilla.getAlias(), function (e) {
|
||||
|
||||
self.tablePlantilla.table.settings()[0].oFeatures.bServerSide = false;
|
||||
|
||||
|
||||
if ($(this).closest('tr').hasClass('row-created')) {
|
||||
$(this).closest('tr').remove();
|
||||
}
|
||||
|
||||
const row = $(this).attr('data-id');
|
||||
self.btnApply.removeClass('d-none');
|
||||
self.btnUndo.removeClass('d-none');
|
||||
@ -76,6 +123,9 @@ class PlantillasTarifasClienteForm {
|
||||
// find closest span.edit
|
||||
$('#' + row).find('span.edit').addClass('d-none');
|
||||
$('#' + row).find('.btn-delete-' + self.tablePlantilla.getAlias()).addClass('d-none');
|
||||
|
||||
if (self.rowsDeleted.indexOf(row) == -1)
|
||||
self.rowsDeleted.push(row);
|
||||
});
|
||||
|
||||
this.btnApply.on('click', function (e) {
|
||||
@ -121,7 +171,7 @@ class PlantillasTarifasClienteForm {
|
||||
{
|
||||
name: "id",
|
||||
type: "readonly",
|
||||
def: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
def: ''
|
||||
}, {
|
||||
name: "tipo",
|
||||
type: "select",
|
||||
@ -192,6 +242,10 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
const row = self.tablePlantilla.table.row('#' + json.data[0].id);
|
||||
|
||||
if (row.length) {
|
||||
self.rowsCreated.push(row);
|
||||
}
|
||||
|
||||
let rowNode = row.node();
|
||||
|
||||
$(rowNode).addClass('row-created');
|
||||
@ -209,6 +263,9 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
let rowNode = row.node();
|
||||
|
||||
|
||||
|
||||
|
||||
// Añadir una clase usando jQuery
|
||||
if (!$(rowNode).hasClass('row-created')) {
|
||||
$(rowNode).addClass('row-edited');
|
||||
@ -234,6 +291,15 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
self.btnApply.removeClass('d-none');
|
||||
self.btnUndo.removeClass('d-none');
|
||||
|
||||
|
||||
// modificar la fila en rows que tenga el mismo id
|
||||
let index = self.rows.findIndex(r => r.id == data.id);
|
||||
if (index != -1) {
|
||||
self.rows[index] = data;
|
||||
}
|
||||
if (self.rowsEdited.indexOf(row.id) == -1)
|
||||
self.rowsEdited.push(row.id);
|
||||
}
|
||||
});
|
||||
|
||||
@ -251,12 +317,8 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
const self = this;
|
||||
|
||||
const deletedRows = self.tablePlantilla.table.rows('.row-deleted').data().toArray();
|
||||
const editedRows = self.tablePlantilla.table.rows('.row-edited').data().toArray();
|
||||
const createdRows = self.tablePlantilla.table.rows('.row-created').data().toArray();
|
||||
|
||||
if (editedRows.length != 0) {
|
||||
let error = self.#checkInterval(editedRows);
|
||||
if (this.rowsEdited.length != 0) {
|
||||
let error = self.#checkInterval(self.rowsEdited);
|
||||
if (error) {
|
||||
if (error == 1) {
|
||||
popErrorAlert('Hay filas EDITADAS con el tiempo mínimo mayor que el tiempo máximo');
|
||||
@ -268,8 +330,8 @@ class PlantillasTarifasClienteForm {
|
||||
}
|
||||
}
|
||||
|
||||
if (createdRows.length != 0) {
|
||||
let error = self.#checkInterval(editedRows);
|
||||
if (this.rowsCreated.length != 0) {
|
||||
let error = self.#checkInterval(self.rowsCreated.map(row => row.data()));
|
||||
if (error) {
|
||||
if (error == 1) {
|
||||
popErrorAlert('Hay filas CREADAS con el tiempo mínimo mayor que el tiempo máximo');
|
||||
@ -281,9 +343,9 @@ class PlantillasTarifasClienteForm {
|
||||
}
|
||||
}
|
||||
|
||||
if (deletedRows.length != 0) {
|
||||
if (this.rowsDeleted.length != 0) {
|
||||
|
||||
let rowIds = deletedRows.map(row => '#' + row.id);
|
||||
let rowIds = self.rowsDeleted.map(row => '#' + row);
|
||||
|
||||
// Iterar sobre cada fila y actualizar los campos necesarios
|
||||
self.ajaxEditor.editor
|
||||
@ -297,13 +359,15 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
|
||||
|
||||
if (editedRows.length != 0) {
|
||||
if (this.rowsEdited.length != 0) {
|
||||
|
||||
let rowIds = editedRows.map(row => '#' + row.id);
|
||||
let rowIds = this.rowsEdited.map(row => '#' + this.tablePlantilla.table.row(row).data().id);
|
||||
let updatedFields = {};
|
||||
|
||||
// Iterar sobre las filas editadas y construir el objeto actualizado
|
||||
editedRows.forEach(row => {
|
||||
this.rowsEdited.forEach(row2Edit => {
|
||||
|
||||
const row = this.tablePlantilla.table.row(row2Edit).data();
|
||||
|
||||
updatedFields['tipo'] = updatedFields['tipo'] || {};
|
||||
updatedFields['tipo'][row.id] = row.tipo;
|
||||
@ -332,13 +396,13 @@ class PlantillasTarifasClienteForm {
|
||||
}
|
||||
|
||||
|
||||
if (createdRows.length != 0) {
|
||||
if (this.rowsCreated.length != 0) {
|
||||
|
||||
let updatedFields = {};
|
||||
|
||||
let count = 0;
|
||||
// Iterar sobre las filas editadas y construir el objeto actualizado
|
||||
createdRows.forEach(row => {
|
||||
this.rowsCreated.forEach(row => {
|
||||
|
||||
updatedFields['id'] = updatedFields['id'] || {};
|
||||
updatedFields['id'][row.id] = count;
|
||||
@ -370,48 +434,68 @@ class PlantillasTarifasClienteForm {
|
||||
count++;
|
||||
});
|
||||
|
||||
self.ajaxEditor.editor.create(createdRows.length, false).multiSet(updatedFields)
|
||||
self.ajaxEditor.editor.create(self.rowsCreated.length, false).multiSet(updatedFields)
|
||||
.submit()
|
||||
}
|
||||
|
||||
if (deletedRows.length != 0 || editedRows.length != 0 || createdRows.length != 0) {
|
||||
|
||||
new Ajax(
|
||||
'/clienteprecios/update',
|
||||
{
|
||||
[self.csrf_token]: self.csrf_hash,
|
||||
plantilla_id: self.plantillaId
|
||||
},
|
||||
{},
|
||||
() => {
|
||||
window.location.reload();
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
).post();
|
||||
new Ajax(
|
||||
'/clienteprecios/update',
|
||||
{
|
||||
[self.csrf_token]: self.csrf_hash,
|
||||
plantilla_id: self.plantillaId
|
||||
},
|
||||
{},
|
||||
() => {
|
||||
self.tablePlantilla.table.settings()[0].oFeatures.bServerSide = true;
|
||||
|
||||
}
|
||||
new Ajax(
|
||||
'/clienteplantillaprecioslineas/getrows',
|
||||
{
|
||||
[self.csrf_token]: self.csrf_hash,
|
||||
plantilla_id: self.plantillaId
|
||||
},
|
||||
{},
|
||||
(response) => {
|
||||
self.rows = response.data;
|
||||
self.rowsDeleted = [];
|
||||
self.rowsEdited = [];
|
||||
self.rowsCreated = [];
|
||||
|
||||
self.tablePlantilla.table.clearPipeline();
|
||||
self.tablePlantilla.table.draw(true);
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}).post();
|
||||
|
||||
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
).post();
|
||||
|
||||
}
|
||||
|
||||
|
||||
#checkInterval(rows) {
|
||||
|
||||
// obtener todas las filas de la tabla que no tengan la clase row-deleted
|
||||
let rowsNotDeletedDT = this.tablePlantilla.table.rows(':not(.row-deleted)').nodes().toArray();
|
||||
for (let row of rowsNotDeletedDT) {
|
||||
let rowData = this.tablePlantilla.table.row(row).data();
|
||||
for (let rowEdited of rows) {
|
||||
if (rowEdited.tiempo_min > rowEdited.tiempo_max) {
|
||||
|
||||
for (let row of this.rows) {
|
||||
let rowData = this.tablePlantilla.table.row(row).data();
|
||||
for (let row2Check of rows) {
|
||||
let checkRow = this.tablePlantilla.table.row(row2Check).data();
|
||||
if (checkRow.tiempo_min > checkRow.tiempo_max) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
if (rowData.tipo == rowEdited.tipo && rowData.tipo_maquina == rowEdited.tipo_maquina && rowData.tipo_impresion == rowEdited.tipo_impresion) {
|
||||
if (checkRow.id == rowData.id) continue;
|
||||
if (rowData.tipo == checkRow.tipo && rowData.tipo_maquina == checkRow.tipo_maquina && rowData.tipo_impresion == checkRow.tipo_impresion) {
|
||||
// check overlapping intervals
|
||||
if (rowEdited.tiempo_min >= rowData.tiempo_min || rowEdited.tiempo_min <= rowData.tiempo_max) {
|
||||
if (Math.max(checkRow.tiempo_max, rowData.tiempo_max) - Math.min(checkRow.tiempo_min, rowData.tiempo_min)
|
||||
<= Math.min(checkRow.tiempo_max - checkRow.tiempo_min) + Math.min(rowData.tiempo_max - rowData.tiempo_min))
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -518,12 +602,38 @@ class PlantillasTarifasClienteForm {
|
||||
selector.append('<option value="sobrecubierta">Sobrecubierta</option>');
|
||||
|
||||
selector.on('change', function () {
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
|
||||
var val = $(this).val(); // El valor seleccionado
|
||||
var searchVal = "";
|
||||
|
||||
// Determinar el texto renderizado que debe buscarse
|
||||
if (val === "interior") {
|
||||
searchVal = window.language.ClientePrecios.interior;
|
||||
} else if (val === "cubierta") {
|
||||
searchVal = window.language.ClientePrecios.cubierta;
|
||||
} else if (val === "sobrecubierta") {
|
||||
searchVal = window.language.ClientePrecios.sobrecubierta;
|
||||
}
|
||||
|
||||
const allRows = [...self.rows, ...self.rowsCreated.map(row => row.data())];
|
||||
|
||||
// Actualizar los datos de la tabla
|
||||
self.tablePlantilla.table.clear().rows.add(allRows).draw();
|
||||
// Aplicar el filtro sobre los valores renderizados
|
||||
self.tablePlantilla.table.column(i).search(searchVal ? '^' + searchVal + '$' : '', true, false).draw();
|
||||
}
|
||||
else {
|
||||
// Aplicar el filtro sobre los valores renderizados
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
else if (i == 2) {
|
||||
@ -537,10 +647,35 @@ class PlantillasTarifasClienteForm {
|
||||
selector.append('<option value="inkjet">Inkjet</option>');
|
||||
|
||||
selector.on('change', function () {
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
|
||||
var val = $(this).val(); // El valor seleccionado
|
||||
var searchVal = "";
|
||||
|
||||
// Determinar el texto renderizado que debe buscarse
|
||||
if (val === "toner") {
|
||||
searchVal = window.language.ClientePrecios.toner;
|
||||
} else if (val === "inkjet") {
|
||||
searchVal = window.language.ClientePrecios.inkjet;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const allRows = [...self.rows, ...self.rowsCreated.map(row => row.data())];
|
||||
|
||||
// Actualizar los datos de la tabla
|
||||
self.tablePlantilla.table.clear().rows.add(allRows).draw();
|
||||
// Aplicar el filtro sobre los valores renderizados
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
}
|
||||
else {
|
||||
// Aplicar el filtro sobre los valores renderizados
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -557,17 +692,52 @@ class PlantillasTarifasClienteForm {
|
||||
selector.append('<option value="colorhq">' + window.language.ClientePrecios.colorhq + '</option>');
|
||||
|
||||
selector.on('change', function () {
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
|
||||
var val = $(this).val(); // El valor seleccionado
|
||||
var searchVal = "";
|
||||
|
||||
// Determinar el texto renderizado que debe buscarse
|
||||
if (val === "negro") {
|
||||
searchVal = window.language.ClientePrecios.negro;
|
||||
} else if (val === "negrohq") {
|
||||
searchVal = window.language.ClientePrecios.negrohq;
|
||||
} else if (val === "color") {
|
||||
searchVal = window.language.ClientePrecios.color;
|
||||
} else if (val === "colorhq") {
|
||||
searchVal = window.language.ClientePrecios.colorhq;
|
||||
}
|
||||
|
||||
const allRows = [...self.rows, ...self.rowsCreated.map(row => row.data())];
|
||||
|
||||
// Actualizar los datos de la tabla
|
||||
self.tablePlantilla.table.clear().rows.add(allRows).draw();
|
||||
self.tablePlantilla.table.column(i).search(searchVal ? '^' + searchVal + '$' : '', true, false).draw();
|
||||
}
|
||||
else {
|
||||
// Aplicar el filtro sobre los valores renderizados
|
||||
var val = $.fn.dataTable.util.escapeRegex(
|
||||
$(this).val()
|
||||
);
|
||||
self.tablePlantilla.table.column(i).search(val).draw();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
else {
|
||||
$(this).html('<input type="text" class="form-control " style="min-width:100px;max-width:120px;font-size:0.8rem !important;" />');
|
||||
|
||||
$('input', this).on('change clear', function () {
|
||||
|
||||
if (self.tablePlantilla.table.column(i).search() !== this.value) {
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
const allRows = [...self.rows, ...self.rowsCreated.map(row => row.data())];
|
||||
|
||||
// Actualizar los datos de la tabla
|
||||
self.tablePlantilla.table.clear().rows.add(allRows).draw();
|
||||
}
|
||||
|
||||
self.tablePlantilla.table
|
||||
.column(i)
|
||||
.search(this.value)
|
||||
|
||||
Reference in New Issue
Block a user