mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
378 lines
14 KiB
JavaScript
378 lines
14 KiB
JavaScript
import Table from '../../components/table.js';
|
|
import TableEditor from '../../components/tableEditor.js';
|
|
import ConfirmDeleteModal from '../../components/ConfirmDeleteModal.js';
|
|
import Ajax from '../../components/ajax.js';
|
|
import { getToken } from '../../common/common.js';
|
|
|
|
class PlantillasTarifasClienteForm {
|
|
|
|
constructor() {
|
|
|
|
this.domItem = $('.card-body');
|
|
|
|
this.plantillaId = window.location.href.split("/").pop();
|
|
|
|
this.csrf_token = getToken();
|
|
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
|
|
|
|
this.btnApply = $('#btnApply');
|
|
|
|
this.tablePlantilla = null;
|
|
this.deleteModal = null;
|
|
|
|
this.localEditor = null;
|
|
this.ajaxEditor = null;
|
|
|
|
this.changedRows = [];
|
|
this.deletedRows = [];
|
|
}
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
this.headerSearcher();
|
|
|
|
this.deleteModal = new ConfirmDeleteModal('plantillasTarifasCliente');
|
|
this.deleteModal.init();
|
|
|
|
this.#initTable();
|
|
|
|
this.#initEditor();
|
|
|
|
// Editar en linea la fila
|
|
this.tablePlantilla.table.on('click', 'tbody span.edit', function (e) {
|
|
|
|
const row = $(this).closest('tr');
|
|
|
|
// Iniciar la edición en línea para todas las celdas de la fila
|
|
self.localEditor.editor.inline(
|
|
self.tablePlantilla.table.cells(row, '*').nodes(),
|
|
{
|
|
cancelHtml: '<a href="javascript:void(0);"><i class="ti ti-x"></i></a>',
|
|
submitHtml: '<a href="javascript:void(0);"><i class="ti ti-device-floppy"></i></a>',
|
|
cancelTrigger: row.find('span.cancel')[0],
|
|
submitTrigger: row.find('span.edit')[0],
|
|
submit: 'allIfChanged',
|
|
drawType: 'none'
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
#initEditor() {
|
|
|
|
const self = this;
|
|
|
|
const tipo_linea = [
|
|
{ label: window.language.ClientePrecios.interior, value: 'interior' },
|
|
{ label: window.language.ClientePrecios.cubierta, value: 'cubierta' },
|
|
{ label: window.language.ClientePrecios.sobrecubierta, value: 'sobrecubierta' }
|
|
];
|
|
|
|
const tipo_maquina = [
|
|
{ label: window.language.ClientePrecios.toner, value: 'toner' },
|
|
{ label: window.language.ClientePrecios.inkjet, value: 'inkjet' },
|
|
];
|
|
|
|
const tipo_impresion = [
|
|
{ label: window.language.ClientePrecios.negro, value: 'negro' },
|
|
{ label: window.language.ClientePrecios.negrohq, value: 'negrohq' },
|
|
{ label: window.language.ClientePrecios.color, value: 'color' },
|
|
{ label: window.language.ClientePrecios.colorhq, value: 'colorhq' },
|
|
];
|
|
|
|
const editorFields = [
|
|
{
|
|
name: "id",
|
|
type: "readonly"
|
|
}, {
|
|
name: "tipo",
|
|
type: "select",
|
|
options: tipo_linea
|
|
}, {
|
|
name: "tipo_maquina",
|
|
type: "select",
|
|
options: tipo_maquina
|
|
}, {
|
|
name: "tipo_impresion",
|
|
type: "select",
|
|
options: tipo_impresion
|
|
}, {
|
|
name: "tiempo_min"
|
|
}, {
|
|
name: "tiempo_max"
|
|
}, {
|
|
name: "precio_hora"
|
|
}, {
|
|
name: "margen"
|
|
},
|
|
];
|
|
this.localEditor = new TableEditor(
|
|
$('#tableOfPlantillasPreciosLineas'),
|
|
'',
|
|
{},
|
|
'id',
|
|
editorFields);
|
|
|
|
this.localEditor.init();
|
|
|
|
this.ajaxEditor = new TableEditor(
|
|
$('#tableOfPlantillasPreciosLineas'),
|
|
'/clienteplantillaprecioslineas/datatable_editor',
|
|
{ [this.csrf_token]: this.csrf_hash },
|
|
'id',
|
|
editorFields);
|
|
|
|
this.ajaxEditor.init();
|
|
|
|
this.localEditor.editor.on('postEdit', function (e, json, data) {
|
|
|
|
let row = self.tablePlantilla.table.row('#' + data.id);
|
|
|
|
if (row.length) {
|
|
|
|
let rowData = row.data();
|
|
|
|
// Actualizar los datos de la fila
|
|
self.tablePlantilla.table.row('#' + data.id).data({
|
|
id: data.id,
|
|
tipo: data.tipo,
|
|
tipo_maquina: data.tipo_maquina,
|
|
tipo_impresion: data.tipo_impresion,
|
|
tiempo_min: data.tiempo_min,
|
|
tiempo_max: data.tiempo_max,
|
|
precio_hora: data.precio_hora,
|
|
margen: "150",
|
|
user_updated_id: data.user_updated,
|
|
user_updated: data.user_updated,
|
|
updated_at: data.updated_at
|
|
});
|
|
|
|
// check if this id exists
|
|
if (!self.changedRows.includes(data.id))
|
|
self.changedRows.push(data.id);
|
|
}
|
|
});
|
|
|
|
/*
|
|
this.editorTarifas.editor.on('preSubmit', function (e, d, type) {
|
|
if (type === 'create') {
|
|
d.data[0]['cliente_id'] = self.clienteId;
|
|
}
|
|
});
|
|
|
|
this.editorTarifas.editor.on('submitSuccess', function (e, json, data, action) {
|
|
|
|
self.tablePlantilla.table.clearPipeline();
|
|
self.tablePlantilla.table.draw();
|
|
});
|
|
|
|
|
|
this.editorTarifas.editor.on('postEdit', function (e, json, data, action) {
|
|
self.#borrarPlantillaTarifa(self.clienteId);
|
|
self.selectorPlantilla.offChange();
|
|
self.selectorPlantilla.setOption(0, 'Personalizado');
|
|
self.selectorPlantilla.onChange(self.#changePlantilla.bind(this));
|
|
})
|
|
|
|
this.editorTarifas.editor.on('postCreate', function (e, json, data, action) {
|
|
self.#borrarPlantillaTarifa(self.clienteId);
|
|
self.selectorPlantilla.offChange();
|
|
self.selectorPlantilla.setOption(0, 'Personalizado');
|
|
self.selectorPlantilla.onChange(self.#changePlantilla.bind(this));
|
|
})
|
|
|
|
this.editorTarifas.editor.on('postCancel', function (e, json, data) {
|
|
// Restaurar botones de acción por fila
|
|
self.tablePlantilla.table.rows().nodes().each(function (node) {
|
|
$(node).find('span.edit').removeClass('d-none');
|
|
$(node).find('span.cancel, span.submit').addClass('d-none');
|
|
});
|
|
});*/
|
|
}
|
|
|
|
|
|
#initTable() {
|
|
|
|
const self = this;
|
|
|
|
const columns =
|
|
[
|
|
{ 'data': 'id' },
|
|
{
|
|
'data': 'tipo',
|
|
'render': function (data, type, row, meta) {
|
|
if (data == 'interior')
|
|
return window.language.ClientePrecios.interior;
|
|
else if (data == 'cubierta')
|
|
return window.language.ClientePrecios.cubierta;
|
|
else if (data == 'sobrecubierta')
|
|
return window.language.ClientePrecios.sobrecubierta;
|
|
}
|
|
},
|
|
{
|
|
'data': 'tipo_maquina',
|
|
'render': function (data, type, row, meta) {
|
|
if (data == 'toner')
|
|
return window.language.ClientePrecios.toner;
|
|
else if (data == 'inkjet')
|
|
return window.language.ClientePrecios.inkjet;
|
|
}
|
|
},
|
|
{
|
|
'data': 'tipo_impresion',
|
|
'render': function (data, type, row, meta) {
|
|
if (data == 'negro')
|
|
return window.language.ClientePrecios.negro;
|
|
else if (data == 'negrohq')
|
|
return window.language.ClientePrecios.negrohq;
|
|
else if (data == 'color')
|
|
return window.language.ClientePrecios.color;
|
|
else if (data == 'colorhq')
|
|
return window.language.ClientePrecios.colorhq;
|
|
}
|
|
},
|
|
{ 'data': 'tiempo_min' },
|
|
{ 'data': 'tiempo_max' },
|
|
{ 'data': 'precio_hora' },
|
|
{ 'data': 'margen' },
|
|
{ 'data': 'user_updated' },
|
|
{ 'data': 'updated_at' },
|
|
|
|
];
|
|
|
|
const actions = ['edit', 'delete', 'cancel'];
|
|
|
|
this.tablePlantilla = new Table(
|
|
$('#tableOfPlantillasPreciosLineas'),
|
|
'plantillaTarifasCliente',
|
|
'/clienteplantillaprecioslineas/datatable',
|
|
columns,
|
|
[
|
|
{ name: 'plantilla_id', value: this.plantillaId }
|
|
],'id'
|
|
);
|
|
|
|
|
|
this.tablePlantilla.init({
|
|
actions: actions,
|
|
colVisibility: false,
|
|
buttonsExport: true,
|
|
});
|
|
|
|
|
|
this.tablePlantilla.table.on('init.dt', function () {
|
|
self.tablePlantilla.table.page.len(50).draw();
|
|
});
|
|
|
|
}
|
|
|
|
headerSearcher() {
|
|
|
|
const self = this;
|
|
|
|
$('#tableOfPlantillasPreciosLineas thead tr').clone(false).appendTo('#tableOfPlantillasPreciosLineas thead');
|
|
$('#tableOfPlantillasPreciosLineas thead tr:eq(1) th').each(function (i) {
|
|
|
|
if (!$(this).hasClass("noFilter")) {
|
|
|
|
if (i == 1) {
|
|
|
|
// Agregar un selector en la segunda columna
|
|
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
|
|
|
|
// Agregar opciones al selector
|
|
var selector = $('select', this);
|
|
selector.append('<option value="">Todos</option>'); // Opción vacía
|
|
selector.append('<option value="interior">Interior</option>');
|
|
selector.append('<option value="cubierta">Cubierta</option>');
|
|
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();
|
|
});
|
|
|
|
}
|
|
|
|
else if (i == 2) {
|
|
// Agregar un selector en la tercera columna
|
|
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
|
|
|
|
// Agregar opciones al selector
|
|
var selector = $('select', this);
|
|
selector.append('<option value="">Todos</option>'); // Opción vacía
|
|
selector.append('<option value="toner">Toner</option>');
|
|
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();
|
|
});
|
|
}
|
|
|
|
else if (i == 3) {
|
|
// Agregar un selector en la cuarta columna
|
|
$(this).html('<select class="form-control" style="min-width:100px;max-width:120px;font-size:0.8rem !important;"></select>');
|
|
|
|
// Agregar opciones al selector
|
|
var selector = $('select', this);
|
|
selector.append('<option value="">Todos</option>'); // Opción vacía
|
|
selector.append('<option value="negro">' + window.language.ClientePrecios.negro + '</option>');
|
|
selector.append('<option value="color">' + window.language.ClientePrecios.color + '</option>');
|
|
selector.append('<option value="negrohq">' + window.language.ClientePrecios.negrohq + '</option>');
|
|
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();
|
|
});
|
|
}
|
|
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) {
|
|
self.tablePlantilla.table
|
|
.column(i)
|
|
.search(this.value)
|
|
.draw();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
else {
|
|
$(this).html('<span></span>');
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
|
|
|
|
|
|
|
|
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['ClientePrecios'] }, {},
|
|
function (translations) {
|
|
window.language = JSON.parse(translations);
|
|
new PlantillasTarifasClienteForm().init();
|
|
},
|
|
function (error) {
|
|
console.log("Error getting translations:", error);
|
|
}
|
|
).post();
|
|
|
|
});
|