From 14b69b52aebe61c625a680d11a472ead476c11ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Fri, 30 Jun 2023 13:22:25 +0200 Subject: [PATCH] =?UTF-8?q?falta=20funcionalidad=20tabla=20pivote.=20al=20?= =?UTF-8?q?pulsar=20isRotativa=20hay=20que=20a=C3=B1adir=20un=20dialog.=20?= =?UTF-8?q?actualizar=20tabla=20papeles=20con=20tarifas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Config/Routes.php | 1 + .../Maquinaspapelesimpresion.php | 68 ++++++++++++++++- .../maquinas/viewMaquinaForm.php | 75 +++++++++++++++++-- 3 files changed, 135 insertions(+), 9 deletions(-) diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index ae014d01..a90c3767 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -254,6 +254,7 @@ $routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\ $routes->group('maquinaspapelesimpresion', ['namespace' => 'App\Controllers\Configuracion'], function ($routes) { $routes->post('datatable', 'Maquinaspapelesimpresion::datatable', ['as' => 'dataTableOfMaquinasPapelesImpresion']); + $routes->post('datatable_editor', 'Maquinaspapelesimpresion::datatable_editor', ['as' => 'editorOfMaquinasPapelImpresion']); }); $routes->resource('maquinastarifasimpresion', ['namespace' => 'App\Controllers\Configuracion', 'controller' => 'Maquinastarifasimpresion', 'except' => 'show,new,create,update']); diff --git a/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php b/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php index 627285b8..b2aaef1d 100644 --- a/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php +++ b/ci4/app/Controllers/Configuracion/Maquinaspapelesimpresion.php @@ -80,7 +80,7 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController // Para saber si el papel que se tiene que mostrar es para rotativa $isRotativa= $reqData['isRotativa'] ?? 0; - $resourceData = $this->model->getResource("", $isRotativa)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); + $resourceData = $this->model->getResource($search, $isRotativa)->orderBy($order, $dir)->limit($length, $start)->get()->getResultObject(); return $this->respond(Collection::datatable( $resourceData, @@ -92,4 +92,70 @@ class Maquinaspapelesimpresion extends \App\Controllers\GoBaseResourceController } } + public function datatable_editor() { + if ($this->request->isAJAX()) { + + include(APPPATH . "ThirdParty/DatatablesEditor/DataTables.php"); + + // Build our Editor instance and process the data coming from _POST + $response = Editor::inst( $db, 'lg_maquinas_tarifas_impresion' ) + ->fields( + Field::inst( 'maquina_id' ), + Field::inst( 'papel_impresion_id' ), + Field::inst( 'active' ) + + ) + ->validator( function($editor, $action, $data){ + /*if ($action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT){ + foreach ($data['data'] as $pkey => $values ){ + // Si no se quiere borrar... + if($data['data'][$pkey]['is_deleted'] != 1) + { + // Cubierta y sobrecubierta sólo pueden ser en color + if($values['uso'] != 'interior' && $values['tipo'] != 'color'){ + return lang('MaquinasTarifasImpresions.validation.cubierta_sobrecubierta_color'); + } + + $builder = $this->model->select('*') + ->where(array( + 'maquina_id'=> $values['maquina_id'], + 'tipo'=> $values['tipo'], + 'uso'=> $values['uso'], + 'is_deleted'=> 0)); + + if ($builder->countAllResults() >= 1){ + if(($action === Editor::ACTION_EDIT && $builder->get()->getFirstRow()->id != $pkey) + || $action === Editor::ACTION_CREATE) + return lang('MaquinasTarifasImpresions.validation.duplicated_uso_tipo'); + + } + } + } + }*/ + }) + ->debug(true) + ->process( $_POST ) + ->data(); + + + /*// if unique key is set in DB + if(isset($response['error'])){ + if(str_contains($response['error'], "tirada_min_tirada_max") && + str_contains($response['error'], "Duplicate entry ")){ + $response['error'] = lang('TarifaAcabadoLineas.validation.duplicated_tirada'); + } + }*/ + $newTokenHash = csrf_hash(); + $csrfTokenName = csrf_token(); + + $response[$csrfTokenName] = $newTokenHash; + + echo json_encode($response); + + } else { + return $this->failUnauthorized('Invalid request', 403); + } + } + + } diff --git a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php index 1be5e5eb..872cf7e4 100644 --- a/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php +++ b/ci4/app/Views/themes/backend/vuexy/form/configuracion/maquinas/viewMaquinaForm.php @@ -277,6 +277,52 @@ }); + editor2 = new $.fn.dataTable.Editor( { + ajax: { + url: "", + headers: { + : v, + }, + }, + table : "#tableOfMaquinaspapelesimpresion", + fields: [ + { + "name": "maquina_id", + "type": "hidden" + },{ + "name": "papel_generico_id", + "type": "hidden" + },{ + "name": "active", + }, + ] + } ); + + + editor2.on( 'preSubmit', function ( e, d, type ) { + if ( type === 'create'){ + d.data[0]['maquina_id'] = id; + } + else if(type === 'edit' ) { + for (v in d.data){ + d.data[v]['maquina_id'] = id; + } + } + }); + + + editor2.on( 'postSubmit', function ( e, json, data, action ) { + + yeniden(json.); + }); + + /*editor2.on( 'submitSuccess', function ( e, json, data, action ) { + + theTable2.clearPipeline(); + theTable2.draw(); + });*/ + + var theTable = $('#tableOfMaquinastarifasimpresion').DataTable( { serverSide: true, processing: true, @@ -361,7 +407,7 @@ lengthChange: true, searching: true, paging: true, - info: false, + info: true, dom: "lftp", ajax : $.fn.dataTable.pipeline( { url: '', @@ -369,17 +415,20 @@ d.id_maquina = id; d.isRotativa = isRotativa.watch; }, - /*{ - id_maquina: id, - //tarifas: [{'uso':'interior', 'tipo':'negro'}], - isRotativa: isRotativa.watch, - },*/ method: 'POST', headers: {'X-Requested-With': 'XMLHttpRequest'}, async: true, }), columns: [ - { 'data': 'active'}, + { 'data': 'active', + render: function (data, type, row) { + if (type === 'display') { + return ''; + } + return data; + }, + className: 'dt-body-center' + }, { 'data': 'papel_generico'}, { 'data': 'papel_impresion'}, { 'data': 'gramaje'}, @@ -389,9 +438,19 @@ { 'data': 'sobrecubierta'}, { 'data': 'rotativa'} ], + rowCallback: function (row, data) { + // Set the checked state of the checkbox in the table + $('input.editor-active', row).prop('checked', data.active == 1); + }, language: { url: "//cdn.datatables.net/plug-ins/1.13.4/i18n/i18n ?>.json" - } + }, + columnDefs: [ + { + searchable: false, + targets: [0,3,4,5,6,7,8] + } + ], } );