From d870fca64d7e9668531f58c79c1e319250d24ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Sat, 30 Nov 2024 13:59:05 +0100 Subject: [PATCH] trabajando en el datatable --- ci4/app/Controllers/Language.php | 21 ++++- .../clientes/cliente/_clienteFormItems.php | 8 +- .../js/safekat/pages/cliente/cliente.js | 32 +++---- .../safekat/pages/cliente/tarifasCliente.js | 91 +++++++++++++++++-- 4 files changed, 122 insertions(+), 30 deletions(-) diff --git a/ci4/app/Controllers/Language.php b/ci4/app/Controllers/Language.php index 437f18eb..f9c32e5d 100755 --- a/ci4/app/Controllers/Language.php +++ b/ci4/app/Controllers/Language.php @@ -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); + } + } } diff --git a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php index 3a741867..f66999c1 100644 --- a/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php +++ b/ci4/app/Views/themes/vuexy/form/clientes/cliente/_clienteFormItems.php @@ -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 = ; 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) { diff --git a/httpdocs/assets/js/safekat/pages/cliente/cliente.js b/httpdocs/assets/js/safekat/pages/cliente/cliente.js index 286be4ec..0bd83277 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/cliente.js +++ b/httpdocs/assets/js/safekat/pages/cliente/cliente.js @@ -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(); -}); \ No newline at end of file + + 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(); +}); + diff --git a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js index d6d7a423..55d61ad0 100644 --- a/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js +++ b/httpdocs/assets/js/safekat/pages/cliente/tarifasCliente.js @@ -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 + }); } -} \ No newline at end of file + + +} + +export default tarifasClienteView; \ No newline at end of file