import ClassSelect from '../../../components/select2.js';
import { getToken } from '../../../common/common.js';
import Ajax from '../../../components/ajax.js';
class LineasPresupuesto {
constructor(domItem, functions = {}) {
this.domItem = domItem;
this.getDimensionLibro = functions.getDimensionLibro;
this.table = null;
this.csrf_token = getToken();
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
this.addLineaManual = this.domItem.find("#btn_addLinea");
}
init() {
const self = this;
this.#initTable();
this.addLineaManual.on('click', this.#insertLineaManual.bind(this));
// Botones de borrar de las lineas de presupuesto
$(document).on('click', '.btn-delete-lp', function (e) {
const row = $(this).closest('tr');
const data = self.table.row(row).data()
self.table.row(row)
.remove()
.draw();
// TO-DO
/*updatePresupuesto({
update_lineas: false,
update_servicios: true,
update_envios: true,
update_resumen: true,
update_tiradas_alternativas: true
})
if (data.row_id == 'lp_guardas')
servicioGuardas(false)
*/
// Si existe cubierta, hay que actualizar con el valor del lomo
if (self.table.row('#lp_cubierta').length > 0) {
self.obtenerLinea('lp_cubierta', false, false);
}
});
// Evento para recalcular las lineas de presupuesto
$(document).on('update-lineas-presupuesto', this.updateLineasPresupuesto.bind(this));
$('.insertarLinea').on("click", this.#insertarLineaComparador.bind(this));
$('.paginas-lp').on('change', this.checkPaginasLineasPresupuesto.bind(this));
}
#initTable() {
const self = this;
const lastColNr_lp = $('#tableLineasPresupuesto').find("tr:first th").length - 1;
const actionBtns_lp = function (data) {
return `
`;
};
this.table = new DataTable('#tableLineasPresupuesto', {
scrollX: true,
searching: false,
paging: false,
info: false,
ordering: true,
responsive: true,
select: false,
rowId: 'row_id',
language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
},
columnDefs: [
{
targets: 0,
className: 'dt-control',
orderable: false,
data: null,
defaultContent: ''
},
{
targets: [1, 2, 3, 4, 5, 6, 7, 8, 9],
orderable: false,
visible: false,
},
{
targets: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
orderable: false,
},
{
targets: [10],
orderable: true,
visible: false,
},
{
orderable: false,
searchable: false,
targets: [lastColNr_lp]
},
],
columns: [
{ data: null },
{ data: 'tarifa_impresion_id' },
{ data: 'maquina_ancho' },
{ data: 'maquina_alto' },
{ data: 'maquina_impresion_ancho' },
{ data: 'maquina_impresion_alto' },
{ data: 'formas' },
{ data: 'formas_v' },
{ data: 'formas_h' },
{ data: 'formas_orientacion' },
{
data: 'position',
type: "num",
render: function (data, type, row, meta) {
if (row.row_id.includes('_bn')) {
return 0;
}
else if (row.row_id.includes('_color')) {
return 1;
}
else if (row.row_id.includes('_cubierta')) {
return 2;
}
else if (row.row_id.includes('_sobrecubierta')) {
return 3;
}
else if (row.row_id.includes('_guardas')) {
return 4;
}
}
},
{
data: 'icon',
render: function (data, type, row, meta) {
return '
'
}
},
{
data: 'paginas',
render: function (data, type, row, meta) {
if (row.row_id != "lp_cubierta" && row.row_id != "lp_sobrecubierta" && row.row_id != "lp_guardas")
return '
| ';
else if (row.row_id == "lp_cubierta") {
let select = ''
return select;
}
else if (row.row_id == "lp_guardas") {
let select = ''
return select;
}
else {
return '';
}
}
},
{
data: 'papel',
render: function (data, type, row, meta) {
var select = $('