trabajando en el datatable

This commit is contained in:
2024-11-30 13:59:05 +01:00
parent c9c462ab92
commit d870fca64d
4 changed files with 122 additions and 30 deletions

View File

@ -21,9 +21,22 @@ class Language extends BaseController
public function getTranslation()
{
$translationFile = $this->request->getPost('translationFile');
$locale = $this->request->getPost('locale');
$path = "Language/{$locale}/$translationFile.php";
$lang = require APPPATH.$path;
return json_encode($lang);
$data = [];
if(is_array($translationFile)){
foreach($translationFile as $file){
$locale = $this->request->getPost('locale');
$path = "Language/{$locale}/$file.php";
$lang = require APPPATH.$path;
$data[$file] = $lang;
}
return json_encode($data);
}
else{
$locale = $this->request->getPost('locale');
$path = "Language/{$locale}/$translationFile.php";
$lang = require APPPATH.$path;
return json_encode($lang);
}
}
}

View File

@ -1046,6 +1046,8 @@ $(document).on('click', '.btn-remove', function(e) {
})
})
/*
var theTablePrecios = $('#tableOfPrecios').DataTable( {
serverSide: true,
processing: true,
@ -1143,7 +1145,7 @@ $(document).on('click', '.btn-remove', function(e) {
}
} ]
} );
*/
const initPrecioTemplate = <?php echo json_encode($precioTemplate);?>;
if(initPrecioTemplate != null){
@ -1151,7 +1153,7 @@ $(document).on('click', '.btn-remove', function(e) {
$('#plantillas').append(newOption);
}
/*
// Activate an inline edit on click of a table cell
$('#tableOfPrecios').on( 'click', 'tbody span.edit', function (e) {
editorPrecios.inline(
@ -1165,7 +1167,7 @@ $(document).on('click', '.btn-remove', function(e) {
}
);
} );
*/
// Delete row
$(document).on('click', '.btn-delete', function(e) {

View File

@ -1,14 +1,12 @@
import ClassSelect from '../../components/select2.js';
import tarifasClienteView from './tarifasCliente.js';
import Ajax from '../../components/ajax.js';
class Cliente {
constructor() {
this.csrf_token = this.getToken();
this.csrf_hash = $('#clienteForm').find('input[name="' + this.csrf_token + '"]').val();
this.tarifas = new tarifasClienteView();
this.tarifas = new tarifasClienteView($('#tarifascliente'));
this.pais = new ClassSelect($("#paisId"), '/paises/menuitems2', "Seleccione un país", {[this.csrf_token]: this.csrf_hash});
this.soporte = new ClassSelect($("#soporteId"), '/users/getMenuComerciales', "Seleccione un usuario", {[this.csrf_token]: this.csrf_hash});
@ -17,7 +15,6 @@ class Cliente {
this.provincia = new ClassSelect($("#provinciaId"), '/provincias/menuitems2', "Seleccione una provincia", {[this.csrf_token]: this.csrf_hash});
this.comunidadAutonoma = new ClassSelect($("#comunidadAutonomaId"), '/comunidades-autonomas/menuitems2', "Seleccione una comunidad autónoma", {[this.csrf_token]: this.csrf_hash});
this.init();
}
init() {
@ -54,18 +51,21 @@ class Cliente {
});
}
getToken(){
const scriptUrl = new URL(import.meta.url);
const params = new URLSearchParams(scriptUrl.search);
const paramsObject = Object.fromEntries(params.entries());
return paramsObject.token;
}
}
document.addEventListener('DOMContentLoaded', function () {
new Cliente().init();
});
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['ClienteContactos', 'ClientePrecios'] }, {},
function(translations) {
window.language = JSON.parse(translations);
new Cliente().init();
},
function (error) {
console.log("Error getting translations:", error);
}
).post();
});

View File

@ -1,14 +1,91 @@
import { getToken } from "../../utils/common";
import Table from '../../components/table.js';
import { getToken } from '../../common/common.js';
class tarifasClienteView{
class tarifasClienteView {
constructor(domItem) {
this.csrf_token = document.querySelector('meta[name="csrf-token"]').content;
this.csrf_hash = document.querySelector('meta[name="csrf-hash"]').content;
this.token = getToken();
this.domItem = domItem;
this.csrf_token = getToken();
this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val();
this.clienteId = window.location.href.split("/").pop();
this.actions = ['edit', 'delete'];
}
init() {
const self = this;
const columns = [
{
'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' },
{ 'data': 'plantilla_id' },
];
this.tableTarifas = new Table(
$('#tableOfPrecios'),
'tarifasCliente',
'/clienteprecios/datatable',
columns,
[
{ name: 'cliente_id', value: window.location.href.split("/").pop() },
{ name: this.csrf_token, value: this.csrf_hash },
]
);
this.tableTarifas.init({
actions: ['edit', 'delete'],
buttonsNewEditor: true,
});
$('button[data-bs-target="#tarifascliente"]').on('shown.bs.tab', function(event) {
setTimeout(() => {
self.tableTarifas.table.columns.adjust().draw();
}, 100); // Usamos setTimeout para asegurar que se dibuje después del renderizado
});
}
}
}
export default tarifasClienteView;