mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
falta editar
This commit is contained in:
@ -45,9 +45,7 @@ class ModalYesNo {
|
||||
|
||||
$('#' + this.btnConfirmId).on('click', () => {
|
||||
|
||||
self.callback(); // Llamar al callback que el usuario haya proporcionado
|
||||
$('#' + self.modalId).modal('hide');
|
||||
|
||||
self.callback(); // Llamar al callback que el usuario haya proporcionado
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -242,8 +242,8 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
const row = self.tablePlantilla.table.row('#' + json.data[0].id);
|
||||
|
||||
if (row.length) {
|
||||
self.rowsCreated.push(row);
|
||||
if (json.data[0]) {
|
||||
self.rowsCreated.push(json.data[0]);
|
||||
}
|
||||
|
||||
let rowNode = row.node();
|
||||
@ -263,9 +263,6 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
let rowNode = row.node();
|
||||
|
||||
|
||||
|
||||
|
||||
// Añadir una clase usando jQuery
|
||||
if (!$(rowNode).hasClass('row-created')) {
|
||||
$(rowNode).addClass('row-edited');
|
||||
@ -317,165 +314,179 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
const self = this;
|
||||
|
||||
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');
|
||||
try {
|
||||
|
||||
self.modalYesNo.hide();
|
||||
$('#loader').modal('show');
|
||||
|
||||
|
||||
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');
|
||||
}
|
||||
else if (error == 2) {
|
||||
popErrorAlert('Hay filas EDITADAS con intervalos [Tiempo min., Tiempo max] solapados');
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (error == 2) {
|
||||
popErrorAlert('Hay filas EDITADAS con intervalos [Tiempo min., Tiempo max] solapados');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
if (this.rowsCreated.length != 0) {
|
||||
let error = self.#checkInterval(self.rowsCreated);
|
||||
if (error) {
|
||||
if (error == 1) {
|
||||
popErrorAlert('Hay filas CREADAS con el tiempo mínimo mayor que el tiempo máximo');
|
||||
}
|
||||
else if (error == 2) {
|
||||
popErrorAlert('Hay filas CREADAS con intervalos [Tiempo min., Tiempo max] solapados');
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (error == 2) {
|
||||
popErrorAlert('Hay filas CREADAS con intervalos [Tiempo min., Tiempo max] solapados');
|
||||
}
|
||||
|
||||
if (this.rowsDeleted.length != 0) {
|
||||
|
||||
let rowIds = self.rowsDeleted.map(row => '#' + row);
|
||||
|
||||
// Iterar sobre cada fila y actualizar los campos necesarios
|
||||
self.ajaxEditor.editor
|
||||
.edit(rowIds, false) // Editar múltiples filas (acepta un array)
|
||||
.multiSet({
|
||||
deleted_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
is_deleted: 1
|
||||
}) // Establecer valores comunes para todas las filas
|
||||
.submit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.rowsEdited.length != 0) {
|
||||
|
||||
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
|
||||
this.rowsEdited.forEach(row2Edit => {
|
||||
|
||||
const row = this.tablePlantilla.table.row(row2Edit).data();
|
||||
|
||||
updatedFields['tipo'] = updatedFields['tipo'] || {};
|
||||
updatedFields['tipo'][row.id] = row.tipo;
|
||||
|
||||
updatedFields['tipo_maquina'] = updatedFields['tipo_maquina'] || {};
|
||||
updatedFields['tipo_maquina'][row.id] = row.tipo_maquina;
|
||||
|
||||
updatedFields['tipo_impresion'] = updatedFields['tipo_impresion'] || {};
|
||||
updatedFields['tipo_impresion'][row.id] = row.tipo_impresion;
|
||||
|
||||
updatedFields['tiempo_min'] = updatedFields['tiempo_min'] || {};
|
||||
updatedFields['tiempo_min'][row.id] = row.tiempo_min;
|
||||
|
||||
updatedFields['tiempo_max'] = updatedFields['tiempo_max'] || {};
|
||||
updatedFields['tiempo_max'][row.id] = row.tiempo_max;
|
||||
|
||||
updatedFields['precio_hora'] = updatedFields['precio_hora'] || {};
|
||||
updatedFields['precio_hora'][row.id] = row.precio_hora;
|
||||
|
||||
updatedFields['margen'] = updatedFields['margen'] || {};
|
||||
updatedFields['margen'][row.id] = row.margen;
|
||||
});
|
||||
|
||||
self.ajaxEditor.editor.edit(rowIds, false).multiSet(updatedFields)
|
||||
.submit()
|
||||
}
|
||||
|
||||
|
||||
if (this.rowsCreated.length != 0) {
|
||||
|
||||
let updatedFields = {};
|
||||
|
||||
let count = 0;
|
||||
// Iterar sobre las filas editadas y construir el objeto actualizado
|
||||
this.rowsCreated.forEach(row => {
|
||||
|
||||
updatedFields['id'] = updatedFields['id'] || {};
|
||||
updatedFields['id'][row.id] = count;
|
||||
|
||||
updatedFields['tipo'] = updatedFields['tipo'] || {};
|
||||
updatedFields['tipo'][count] = row.tipo;
|
||||
|
||||
updatedFields['tipo_maquina'] = updatedFields['tipo_maquina'] || {};
|
||||
updatedFields['tipo_maquina'][count] = row.tipo_maquina;
|
||||
|
||||
updatedFields['tipo_impresion'] = updatedFields['tipo_impresion'] || {};
|
||||
updatedFields['tipo_impresion'][count] = row.tipo_impresion;
|
||||
|
||||
updatedFields['tiempo_min'] = updatedFields['tiempo_min'] || {};
|
||||
updatedFields['tiempo_min'][count] = row.tiempo_min;
|
||||
|
||||
updatedFields['tiempo_max'] = updatedFields['tiempo_max'] || {};
|
||||
updatedFields['tiempo_max'][count] = row.tiempo_max;
|
||||
|
||||
updatedFields['precio_hora'] = updatedFields['precio_hora'] || {};
|
||||
updatedFields['precio_hora'][count] = row.precio_hora;
|
||||
|
||||
updatedFields['margen'] = updatedFields['margen'] || {};
|
||||
updatedFields['margen'][count] = row.margen;
|
||||
|
||||
updatedFields['plantilla_id'] = updatedFields['plantilla_id'] || {};
|
||||
updatedFields['plantilla_id'][count] = self.plantillaId;
|
||||
|
||||
count++;
|
||||
});
|
||||
|
||||
self.ajaxEditor.editor.create(self.rowsCreated.length, false).multiSet(updatedFields)
|
||||
.submit()
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
$('#loader').modal('hide');
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
$('#loader').modal('hide');
|
||||
}).post();
|
||||
|
||||
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
$('#loader').modal('hide');
|
||||
}
|
||||
return;
|
||||
}
|
||||
).post();
|
||||
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
$('#loader').modal('hide');
|
||||
|
||||
}
|
||||
|
||||
if (this.rowsDeleted.length != 0) {
|
||||
|
||||
let rowIds = self.rowsDeleted.map(row => '#' + row);
|
||||
|
||||
// Iterar sobre cada fila y actualizar los campos necesarios
|
||||
self.ajaxEditor.editor
|
||||
.edit(rowIds, false) // Editar múltiples filas (acepta un array)
|
||||
.multiSet({
|
||||
deleted_at: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
is_deleted: 1
|
||||
}) // Establecer valores comunes para todas las filas
|
||||
.submit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (this.rowsEdited.length != 0) {
|
||||
|
||||
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
|
||||
this.rowsEdited.forEach(row2Edit => {
|
||||
|
||||
const row = this.tablePlantilla.table.row(row2Edit).data();
|
||||
|
||||
updatedFields['tipo'] = updatedFields['tipo'] || {};
|
||||
updatedFields['tipo'][row.id] = row.tipo;
|
||||
|
||||
updatedFields['tipo_maquina'] = updatedFields['tipo_maquina'] || {};
|
||||
updatedFields['tipo_maquina'][row.id] = row.tipo_maquina;
|
||||
|
||||
updatedFields['tipo_impresion'] = updatedFields['tipo_impresion'] || {};
|
||||
updatedFields['tipo_impresion'][row.id] = row.tipo_impresion;
|
||||
|
||||
updatedFields['tiempo_min'] = updatedFields['tiempo_min'] || {};
|
||||
updatedFields['tiempo_min'][row.id] = row.tiempo_min;
|
||||
|
||||
updatedFields['tiempo_max'] = updatedFields['tiempo_max'] || {};
|
||||
updatedFields['tiempo_max'][row.id] = row.tiempo_max;
|
||||
|
||||
updatedFields['precio_hora'] = updatedFields['precio_hora'] || {};
|
||||
updatedFields['precio_hora'][row.id] = row.precio_hora;
|
||||
|
||||
updatedFields['margen'] = updatedFields['margen'] || {};
|
||||
updatedFields['margen'][row.id] = row.margen;
|
||||
});
|
||||
|
||||
self.ajaxEditor.editor.edit(rowIds, false).multiSet(updatedFields)
|
||||
.submit()
|
||||
}
|
||||
|
||||
|
||||
if (this.rowsCreated.length != 0) {
|
||||
|
||||
let updatedFields = {};
|
||||
|
||||
let count = 0;
|
||||
// Iterar sobre las filas editadas y construir el objeto actualizado
|
||||
this.rowsCreated.forEach(row => {
|
||||
|
||||
updatedFields['id'] = updatedFields['id'] || {};
|
||||
updatedFields['id'][row.id] = count;
|
||||
|
||||
updatedFields['tipo'] = updatedFields['tipo'] || {};
|
||||
updatedFields['tipo'][count] = row.tipo;
|
||||
|
||||
updatedFields['tipo_maquina'] = updatedFields['tipo_maquina'] || {};
|
||||
updatedFields['tipo_maquina'][count] = row.tipo_maquina;
|
||||
|
||||
updatedFields['tipo_impresion'] = updatedFields['tipo_impresion'] || {};
|
||||
updatedFields['tipo_impresion'][count] = row.tipo_impresion;
|
||||
|
||||
updatedFields['tiempo_min'] = updatedFields['tiempo_min'] || {};
|
||||
updatedFields['tiempo_min'][count] = row.tiempo_min;
|
||||
|
||||
updatedFields['tiempo_max'] = updatedFields['tiempo_max'] || {};
|
||||
updatedFields['tiempo_max'][count] = row.tiempo_max;
|
||||
|
||||
updatedFields['precio_hora'] = updatedFields['precio_hora'] || {};
|
||||
updatedFields['precio_hora'][count] = row.precio_hora;
|
||||
|
||||
updatedFields['margen'] = updatedFields['margen'] || {};
|
||||
updatedFields['margen'][count] = row.margen;
|
||||
|
||||
updatedFields['plantilla_id'] = updatedFields['plantilla_id'] || {};
|
||||
updatedFields['plantilla_id'][count] = self.plantillaId;
|
||||
|
||||
count++;
|
||||
});
|
||||
|
||||
self.ajaxEditor.editor.create(self.rowsCreated.length, false).multiSet(updatedFields)
|
||||
.submit()
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -693,35 +704,35 @@ class PlantillasTarifasClienteForm {
|
||||
|
||||
selector.on('change', function () {
|
||||
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
if (!self.tablePlantilla.table.settings()[0].oFeatures.bServerSide) {
|
||||
|
||||
var val = $(this).val(); // El valor seleccionado
|
||||
var searchVal = "";
|
||||
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();
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user