Añadido configurador

This commit is contained in:
imnavajas
2025-07-25 13:41:40 +02:00
parent 200e45c898
commit e642f0520a
9 changed files with 308 additions and 249 deletions

View File

@ -272,7 +272,7 @@ class ImportadorCatalogo extends BaseResourceController
'gramajeCubierta' => $libro->cubierta_gramaje, 'gramajeCubierta' => $libro->cubierta_gramaje,
'solapas' => $libro->cubierta_ancho_solapas, 'solapas' => $libro->cubierta_ancho_solapas,
'acabado' => $libro->cubierta_acabado_id, 'acabado' => $libro->cubierta_acabado_id,
'cabezada' => 'WHI', 'cabezada' => model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
'lomoRedondo' => 0 'lomoRedondo' => 0
], ],

View File

@ -460,6 +460,8 @@ class Presupuestoadmin extends \App\Controllers\BaseResourceController
$this->viewData['tipo_impresion_id'] = $presupuestoEntity->tipo_impresion_id; // Cosido tapa blanda JJO $this->viewData['tipo_impresion_id'] = $presupuestoEntity->tipo_impresion_id; // Cosido tapa blanda JJO
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
$this->viewData = array_merge($this->viewData, $this->getStringsFromTipoImpresion($presupuestoEntity->tipo_impresion_id)); $this->viewData = array_merge($this->viewData, $this->getStringsFromTipoImpresion($presupuestoEntity->tipo_impresion_id));
$this->viewData['formAction'] = route_to('updatePresupuestoAdmin', $id); $this->viewData['formAction'] = route_to('updatePresupuestoAdmin', $id);

View File

@ -133,6 +133,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value; $this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value; $this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
$this->viewData['eb'] = 0; $this->viewData['eb'] = 0;
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
$this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . $this->viewData['pageTitle'] . ' ' . lang('Basic.global.addNewSuffix'); $this->viewData['boxTitle'] = lang('Basic.global.addNew') . ' ' . $this->viewData['pageTitle'] . ' ' . lang('Basic.global.addNewSuffix');
@ -178,6 +179,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
$this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value; $this->viewData['lomo_maximo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_maximo_fresado_cosido')->value;
$this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value; $this->viewData['lomo_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
$this->viewData['eb'] = $presupuestoEntity->envio_base; $this->viewData['eb'] = $presupuestoEntity->envio_base;
$this->viewData['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
// Si se ha llamado a esta funcion porque se ha duplicado el presupuesto // Si se ha llamado a esta funcion porque se ha duplicado el presupuesto
// se actualiza la bbdd para que sólo ejecute algunas funciones una vez // se actualiza la bbdd para que sólo ejecute algunas funciones una vez
@ -1103,7 +1105,7 @@ class Presupuestocliente extends \App\Controllers\BaseResourceController
'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0, 'solapasCubierta' => intval($cubierta['solapas'] ?? 0) == 1 ? intval($cubierta['tamanioSolapas']) : 0,
'acabado' => $cubierta['acabado'] ?? 0, 'acabado' => $cubierta['acabado'] ?? 0,
'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0, 'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0,
'cabezada' => $cubierta['cabezada'] ?? 'WHI', 'cabezada' => $cubierta['cabezada'] ?? model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
]; ];
// Sobrecubierta // Sobrecubierta

View File

@ -56,4 +56,40 @@ class ConfigVariableModel extends Model
return $builder->get()->getFirstRow(); return $builder->get()->getFirstRow();
} }
/**
* Devuelve solo el valor de la variable por nombre
*/
public function getValue(string $name): ?string
{
$row = $this->getVariable($name);
return $row ? $row->value : null;
}
/**
* Devuelve el valor decodificado (JSON) si aplica
*/
public function getDecodedValue(string $name): ?array
{
$value = $this->getValue($name);
$decoded = json_decode($value, true);
return (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) ? $decoded : null;
}
/**
* Devuelve las opciones disponibles de cabezadas (como array clave => langKey)
*/
public function getCabezadasDisponibles(): array
{
return $this->getDecodedValue('cabezadas_disponibles') ?? [];
}
/**
* Devuelve la cabezada por defecto, o 'WHI' si no está definida
*/
public function getCabezadaDefault(): string
{
return $this->getValue('cabezada_default') ?? 'WHI';
}
} }

View File

@ -15,7 +15,7 @@
<?= view('themes/_commonPartialsBs/_alertBoxes'); ?> <?= view('themes/_commonPartialsBs/_alertBoxes'); ?>
<table id="tableConfigVariables" class="table table-striped table-hover" style="width: 100%;"> <table id="tableConfigVariables" class="table table-striped table-hover table-responsive" style="width: 100%; word-break: break-word;">
<thead> <thead>
<tr> <tr>
<th><?= lang('ConfigVariables.datatable.columns.name') ?></th> <th><?= lang('ConfigVariables.datatable.columns.name') ?></th>
@ -55,11 +55,13 @@
<div class="row g-4"> <div class="row g-4">
<div class="col-12 mb-0"> <div class="col-12 mb-0">
<label for="value" class="form-label"><?= lang('ConfigVariables.form.value') ?></label> <label for="value" class="form-label"><?= lang('ConfigVariables.form.value') ?></label>
<input type="number" min=0 id="value" class="form-control"> <div id="value-wrapper">
</div>
</div> </div>
<div class="col-12 mb-0"> <div class="col-12 mb-0">
<label for="description" class="form-label"><?= lang('ConfigVariables.form.description') ?></label> <label for="description" class="form-label"><?= lang('ConfigVariables.form.description') ?></label>
<textarea type="text" rows="4" cols="10" id="description" class="form-control"></textarea> <textarea type="text" rows="4" cols="10" id="description" class="form-control"></textarea>
</div> </div>
</div> </div>
</div> </div>
@ -75,4 +77,13 @@
<?= $this->endSection() ?> <?= $this->endSection() ?>
<?= $this->section("additionalExternalJs") ?> <?= $this->section("additionalExternalJs") ?>
<script type="module" src="<?= versioned_asset('assets/js/safekat/pages/configuracion/variables.js') ?>"></script> <script type="module" src="<?= versioned_asset('assets/js/safekat/pages/configuracion/variables.js') ?>"></script>
<script>
// Pasamos las opciones al frontend desde PHP
window.CABEZADAS_OPCIONES = <?= json_encode([
'WHI' => lang('Presupuestos.blanca'),
'GRE' => lang('Presupuestos.verde'),
'BLUE' => lang('Presupuestos.azul'),
'REDYEL' => lang('Presupuestos.rojaAmarilla'),
]) ?>;
</script>
<?= $this->endSection() ?> <?= $this->endSection() ?>

View File

@ -222,46 +222,39 @@
</div> </div>
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3): ?> <?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3): ?>
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
</div> </div>
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<label id="label_compLomoRedondo" for="compLomoRedondo" class="form-label"> <label id="label_compLomoRedondo" for="compLomoRedondo" class="form-label">
<?= lang('Presupuestos.lomoRedondo') ?>* <?= lang('Presupuestos.lomoRedondo') ?>*
</label> </label>
<select id="compLomoRedondo" name="lomo_redondo" service-id="<?= $serviciosAutomaticos['lomo_redondo'] ?>" <select id="compLomoRedondo" name="lomo_redondo" service-id="<?= $serviciosAutomaticos['lomo_redondo'] ?>"
class="form-control select2bs2 comp_cubierta_items" style="width: 100%;"> class="form-control select2bs2 comp_cubierta_items" style="width: 100%;">
<option value="0"> <option value="0">
<p> <p>
<?= lang('Presupuestos.no') ?> <?= lang('Presupuestos.no') ?>
</p> </p>
</option> </option>
<option value="1"> <option value="1">
<p> <p>
<?= lang('Presupuestos.si') ?> <?= lang('Presupuestos.si') ?>
</p> </p>
</option> </option>
</select> </select>
</div> </div>
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<label for="cabezada" class="form-label"> <label for="cabezada" class="form-label">
<?= lang('Presupuestos.cabezada') ?> <?= lang('Presupuestos.cabezada') ?>
</label> </label>
<select class="form-select select2bs2" id="cabezada" name="cabezada"> <select class="form-select" name="cabezada" id="cabezada">
<option value="WHI"> <?php foreach ($cabezadas as $key => $langKey): ?>
<?= lang('Presupuestos.blanca') ?> <option value="<?= esc($key) ?>">
</option> <?= lang($langKey) ?>
<option value="GRE"> </option>
<?= lang('Presupuestos.verde') ?> <?php endforeach; ?>
</option> </select>
<option value="BLUE"> </div>
<?= lang('Presupuestos.azul') ?>
</option>
<option value="REDYEL">
<?= lang('Presupuestos.rojaAmarilla') ?>
</option>
</select>
</div>
<?php endif; ?> <?php endif; ?>
<div> <div>
<hr class="my-1"> <hr class="my-1">
@ -269,83 +262,83 @@
</div> </div>
<?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8 && $tipo_impresion_id != 21): ?> <?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8 && $tipo_impresion_id != 21): ?>
<div class="row"> <div class="row">
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<p> <p>
<?= lang('PapelImpresion.sobrecubierta') ?> <?= lang('PapelImpresion.sobrecubierta') ?>
</p> </p>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compSobrecubierta" name="comp_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
<option value="0">
<?= lang('Presupuestos.no') ?>
</option>
<option value="1">
<?= lang('Presupuestos.si') ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select disabled id="compPapelSobrecubierta" name="comp_papel_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select disabled id="compGramajeSobrecubierta" name="comp_gramaje_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div>
<hr class="my-1">
</div>
</div> </div>
<div class="col-md-12 col-lg-2 px-4">
<select id="compSobrecubierta" name="comp_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
<option value="0">
<?= lang('Presupuestos.no') ?>
</option>
<option value="1">
<?= lang('Presupuestos.si') ?>
</option>
</select>
</div>
<div class="col-md-12 col-lg-6 px-4">
<select disabled id="compPapelSobrecubierta" name="comp_papel_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div class="col-md-12 col-lg-2 px-4">
<select disabled id="compGramajeSobrecubierta" name="comp_gramaje_sobrecubierta"
class="form-control select2bs2 comp_sobrecubierta_items" style="width: 100%;">
</select>
</div>
<div>
<hr class="my-1">
</div>
</div>
<?php endif; ?> <?php endif; ?>
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?> <?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?>
<div class="row"> <div class="row">
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<p> <p>
<?= lang('PapelImpresion.guardas') ?> <?= lang('PapelImpresion.guardas') ?>
</p> </p>
</div> </div>
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<select id="compCarasGuardas" name="comp_paginas_guardas" <select id="compCarasGuardas" name="comp_paginas_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;"> class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
<option value="0"> <option value="0">
<p> <p>
<?= lang('Presupuestos.sinImpresion') ?> <?= lang('Presupuestos.sinImpresion') ?>
</p> </p>
</option> </option>
<option value="4"> <option value="4">
<p> <p>
<?= lang('Presupuestos.unaCara') ?> <?= lang('Presupuestos.unaCara') ?>
</p> </p>
</option> </option>
<option value="8"> <option value="8">
<?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8): ?> <?php if ($tipo_impresion_id != 5 && $tipo_impresion_id != 6 && $tipo_impresion_id != 7 && $tipo_impresion_id != 8): ?>
<p> <p>
<?= lang('Presupuestos.dosCaras') ?> <?= lang('Presupuestos.dosCaras') ?>
</p> </p>
<?php endif ?> <?php endif ?>
</option> </option>
</select> </select>
</div> </div>
<div class="col-md-12 col-lg-6 px-4"> <div class="col-md-12 col-lg-6 px-4">
<select id="compPapelGuardas" name="comp_papel_guardas" <select id="compPapelGuardas" name="comp_papel_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;"> class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select> </select>
</div> </div>
<div class="col-md-12 col-lg-2 px-4"> <div class="col-md-12 col-lg-2 px-4">
<select id="compGramajeGuardas" name="comp_gramaje_guardas" <select id="compGramajeGuardas" name="comp_gramaje_guardas"
class="form-control select2bs2 comp_guardas_items" style="width: 100%;"> class="form-control select2bs2 comp_guardas_items" style="width: 100%;">
</select> </select>
</div> </div>
<div> <div>
<hr class="my-1"> <hr class="my-1">
</div>
</div> </div>
</div>
<?php endif; ?> <?php endif; ?>
<div class="row"> <div class="row">
@ -733,102 +726,102 @@
<!-----------------------------------------------------------------------------> <!----------------------------------------------------------------------------->
<?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?> <?php if ($tipo_impresion_id == 1 || $tipo_impresion_id == 3 || $tipo_impresion_id == 5 || $tipo_impresion_id == 7): ?>
<div class="accordion mt-3" id="accordionCompGuardas"> <div class="accordion mt-3" id="accordionCompGuardas">
<div class="card accordion-item active"> <div class="card accordion-item active">
<h2 class="accordion-header" id="headingOne"> <h2 class="accordion-header" id="headingOne">
<button id="accordion-button-int-guardas" type="button" class="accordion-button" <button id="accordion-button-int-guardas" type="button" class="accordion-button"
data-bs-toggle="collapse" data-bs-target="#accordionCompGuardasTip" data-bs-toggle="collapse" data-bs-target="#accordionCompGuardasTip"
aria-expanded="false" aria-controls="accordionCompGuardasTip"> aria-expanded="false" aria-controls="accordionCompGuardasTip">
<h6 id="title_guardas"> <h6 id="title_guardas">
<?= lang("Presupuestos.Guardas") ?> <?= lang("Presupuestos.Guardas") ?>
</h6> </h6>
</button> </button>
</h2> </h2>
<div id="accordionCompGuardasTip" class="accordion-collapse collapse" <div id="accordionCompGuardasTip" class="accordion-collapse collapse"
data-bs-parent="#accordionCompGuardasTip"> data-bs-parent="#accordionCompGuardasTip">
<div class="accordion-body"> <div class="accordion-body">
<table id="tableCompGuardas" class="comparator-table table dt-responsive dataTable" <table id="tableCompGuardas" class="comparator-table table dt-responsive dataTable"
style="width: 100%;"> style="width: 100%;">
<thead> <thead>
<tr> <tr>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.tipo') ?> <?= lang('Presupuestos.tipo') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.paginas') ?> <?= lang('Presupuestos.paginas') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.papel') ?> <?= lang('Presupuestos.papel') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.gramaje') ?> <?= lang('Presupuestos.gramaje') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.marca') ?> <?= lang('Presupuestos.marca') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.maquina') ?> <?= lang('Presupuestos.maquina') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.numeroPliegos') ?> <?= lang('Presupuestos.numeroPliegos') ?>
</th> </th>
<th style="padding-right: 0.75em; max-width:80px"> <th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.pliegosPedido') ?> <?= lang('Presupuestos.pliegosPedido') ?>
</th> </th>
<th style="padding-right: 0.75em; max-width:80px"> <th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioPliego') ?> <?= lang('Presupuestos.precioPliego') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.libro') ?> <?= lang('Presupuestos.libro') ?>
</th> </th>
<th style="padding-right: 0.75em; max-width:80px"> <th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.totalPapelPedido') ?> <?= lang('Presupuestos.totalPapelPedido') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.lomo') ?> <?= lang('Presupuestos.lomo') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.peso') ?> <?= lang('Presupuestos.peso') ?>
</th> </th>
<th style="padding-right: 0.75em; max-width:80px"> <th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.horas') ?> <?= lang('Presupuestos.horas') ?>
</th> </th>
<th style="padding-right: 0.75em; max-width:80px"> <th style="padding-right: 0.75em; max-width:80px">
<?= lang('Presupuestos.precioImpresion') ?> <?= lang('Presupuestos.precioImpresion') ?>
</th> </th>
<th style="padding-right: 0.75em;"> <th style="padding-right: 0.75em;">
<?= lang('Presupuestos.total') ?> <?= lang('Presupuestos.total') ?>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<td class="dt-result dt-result-text" colspan="14"> <td class="dt-result dt-result-text" colspan="14">
<?= lang('Presupuestos.total') ?> <?= lang('Presupuestos.total') ?>
<?= lang("Presupuestos.Guardas") ?>: <?= lang("Presupuestos.Guardas") ?>:
</td> </td>
<td id="total_comp_guardas" class="dt-result dt-result-value" colspan="2"> <td id="total_comp_guardas" class="dt-result dt-result-value" colspan="2">
0.00 </td> 0.00 </td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
<div> <div>
<button type="button" name="insertarGuardasBtn" id="insertarGuardasBtn" <button type="button" name="insertarGuardasBtn" id="insertarGuardasBtn"
class="btn btn-primary float-end me-sm-3 me-1 mb-3 insertarLinea d-none"> class="btn btn-primary float-end me-sm-3 me-1 mb-3 insertarLinea d-none">
<?= lang('Presupuestos.insertarLinea') . ' ' . strtoupper(lang('Presupuestos.Guardas')) ?> <?= lang('Presupuestos.insertarLinea') . ' ' . strtoupper(lang('Presupuestos.Guardas')) ?>
</button> </button>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
<?php endif; ?> <?php endif; ?>
<div class="accordion mt-3" id="accordionCompFaja"> <div class="accordion mt-3" id="accordionCompFaja">

View File

@ -136,10 +136,11 @@
<?= lang('Presupuestos.cabezada') ?> <?= lang('Presupuestos.cabezada') ?>
</label> </label>
<select class="form-select select2bs2" id="cabezada" name="cabezada"> <select class="form-select select2bs2" id="cabezada" name="cabezada">
<option value="WHI"><?= lang('Presupuestos.blanca') ?></option> <?php foreach ($cabezadas as $key => $langKey): ?>
<option value="GRE"><?= lang('Presupuestos.verde') ?></option> <option value="<?= esc($key) ?>">
<option value="BLUE"><?= lang('Presupuestos.azul') ?></option> <?= lang($langKey) ?>
<option value="REDYEL"><?= lang('Presupuestos.rojaAmarilla') ?></option> </option>
<?php endforeach; ?>
</select> </select>
</div> </div>

View File

@ -1,10 +1,8 @@
import Modal from "./modal.js"; import Modal from "./modal.js";
import Ajax from "./ajax.js"; import Ajax from "./ajax.js";
class ConfigVariableDatatable class ConfigVariableDatatable {
{ constructor(domItem) {
constructor(domItem)
{
this.domItem = domItem this.domItem = domItem
this.datatableItem = this.domItem this.datatableItem = this.domItem
this.modalItem = $("#modalConfigVariableForm") this.modalItem = $("#modalConfigVariableForm")
@ -14,76 +12,69 @@ class ConfigVariableDatatable
this.formEdit = this.modalItem.find("#formEditConfigVariable") this.formEdit = this.modalItem.find("#formEditConfigVariable")
} }
init(){ init() {
this.datatable = this.datatableItem.DataTable({ this.datatable = this.datatableItem.DataTable({
processing: true, processing: true,
dom: 'Blrtip', dom: 'Blrtip',
serverSide: true, serverSide: true,
lengthMenu: [ 25, 50, 100, 200 ], lengthMenu: [25, 50, 100, 200],
pageLength: 50, pageLength: 50,
language: { language: {
url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json" url: "/themes/vuexy/vendor/libs/datatables-sk/plugins/i18n/es-ES.json"
}, },
columns : [ columns: [
{data : 'name',searchable:true,sortable:false}, { data: 'name', searchable: true, sortable: false },
{data : 'value',searchable:true,sortable:false}, { data: 'value', searchable: true, sortable: false },
{data : 'description',searchable:true,sortable:false}, { data: 'description', searchable: true, sortable: false },
{data : 'action',sortable:false,searchable:false, {
render : (d,t) =>{ data: 'action', sortable: false, searchable: false,
render: (d, t) => {
return ` return `
<div class="btn-group btn-group-sm"> <div class="btn-group btn-group-sm">
<a href="javascript:void(0)" data-id="${d}" class="edit-variable"><i class="ti ti-pencil ti-sm mx-2"></i></a> <a href="javascript:void(0)" data-id="${d}" class="edit-variable"><i class="ti ti-pencil ti-sm mx-2"></i></a>
</div> </div>
` `
} }
}, },
], ],
ajax: '/configuracion/variables/datatable' ajax: '/configuracion/variables/datatable'
}); });
} }
events() events() {
{ this.modalItem.on("click", ".btn-update-variable", this.handleUpdateVariable.bind(this))
this.modalItem.on("click",".btn-update-variable",this.handleUpdateVariable.bind(this)) this.datatableItem.on("click", ".edit-variable", (e) => {
this.datatableItem.on("click",".edit-variable",(e)=> {
e.preventDefault() e.preventDefault()
this.variableId = $(e.currentTarget).data("id") this.variableId = $(e.currentTarget).data("id")
this.handleGetVariable() this.handleGetVariable()
}) })
} }
handleGetVariable() handleGetVariable() {
{
const url = `/configuracion/variables/find/${this.variableId}` const url = `/configuracion/variables/find/${this.variableId}`
let ajax = new Ajax( let ajax = new Ajax(
url,null,null, url, null, null,
this.handleGetVariableSuccess.bind(this), this.handleGetVariableSuccess.bind(this),
this.handleGetVariableError.bind(this) this.handleGetVariableError.bind(this)
) )
ajax.get() ajax.get()
} }
handleGetVariableSuccess(data){ handleGetVariableSuccess(data) {
this.formEdit[0].reset() this.formEdit[0].reset()
this.modalEdit.toggle() this.modalEdit.toggle()
this.nameInput = this.formEdit this.nameInput = this.formEdit.find("#name")
.find("#name")
this.nameInput.val(data.name) this.nameInput.val(data.name)
this.valueInput = this.formEdit this.renderValueField(data.name, data.value)
.find("#value") this.descriptionInput = this.formEdit.find("#description")
this.valueInput.val(data.value)
this.descriptionInput = this.formEdit
.find("#description")
this.descriptionInput.val(data.description) this.descriptionInput.val(data.description)
} }
handleGetVariableError(err){} handleGetVariableError(err) { }
handleUpdateVariable() handleUpdateVariable() {
{
const url = `/configuracion/variables/edit/${this.variableId}` const url = `/configuracion/variables/edit/${this.variableId}`
const data = { const data = {
value : this.valueInput.val(), value: this.valueInput.val(),
description : this.descriptionInput.val(), description: this.descriptionInput.val(),
} }
let ajax = new Ajax( let ajax = new Ajax(
url, url,
@ -94,26 +85,49 @@ class ConfigVariableDatatable
) )
ajax.post() ajax.post()
} }
handleUpdateVariableSucess(data){ handleUpdateVariableSucess(data) {
this.modalEdit.toggle() this.modalEdit.toggle()
this.datatable.ajax.reload() this.datatable.ajax.reload()
} }
handleUpdateVariableError(err){} handleUpdateVariableError(err) { }
handleDeleteVariable() handleDeleteVariable() {
{
const url = `/configuracion/variables/delete/${this.variableId}` const url = `/configuracion/variables/delete/${this.variableId}`
let ajax = new Ajax( let ajax = new Ajax(
url,null,null, url, null, null,
this.handleDeleteVariableSucess.bind(this), this.handleDeleteVariableSucess.bind(this),
this.handleDeleteVariableError.bind(this) this.handleDeleteVariableError.bind(this)
) )
ajax.post() ajax.post()
} }
handleDeleteVariableSucess(data){ handleDeleteVariableSucess(data) {
this.datatable.reload() this.datatable.reload()
} }
handleDeleteVariableError(err){} handleDeleteVariableError(err) { }
renderValueField(name, currentValue) {
const wrapper = this.formEdit.find("#value-wrapper");
let html = '';
if (name === 'cabezadas_disponibles') {
html = `<textarea id="value" rows="6" class="form-control">${currentValue}</textarea>`;
} else if (name === 'cabezada_default') {
const options = window.CABEZADAS_OPCIONES || {};
html = `<select id="value" class="form-select">`;
for (const [key, label] of Object.entries(options)) {
const selected = key === currentValue ? 'selected' : '';
html += `<option value="${key}" ${selected}>${label}</option>`;
}
html += `</select>`;
} else {
html = `<input type="text" id="value" class="form-control" value="${currentValue}">`;
}
wrapper.html(html);
this.valueInput = this.formEdit.find("#value"); // Actualiza referencia
}
} }
export default ConfigVariableDatatable; export default ConfigVariableDatatable;

View File

@ -2,4 +2,4 @@ import ConfigVariableDatatable from "../../components/configVariableDatatable.js
const item = new ConfigVariableDatatable($("#tableConfigVariables")) const item = new ConfigVariableDatatable($("#tableConfigVariables"))
item.init() item.init()
item.events() item.events()