mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadido configurador
This commit is contained in:
@ -272,7 +272,7 @@ class ImportadorCatalogo extends BaseResourceController
|
||||
'gramajeCubierta' => $libro->cubierta_gramaje,
|
||||
'solapas' => $libro->cubierta_ancho_solapas,
|
||||
'acabado' => $libro->cubierta_acabado_id,
|
||||
'cabezada' => 'WHI',
|
||||
'cabezada' => model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
|
||||
'lomoRedondo' => 0
|
||||
],
|
||||
|
||||
|
||||
@ -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['cabezadas'] = model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadasDisponibles();
|
||||
|
||||
$this->viewData = array_merge($this->viewData, $this->getStringsFromTipoImpresion($presupuestoEntity->tipo_impresion_id));
|
||||
|
||||
$this->viewData['formAction'] = route_to('updatePresupuestoAdmin', $id);
|
||||
|
||||
@ -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_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
|
||||
$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');
|
||||
|
||||
@ -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_minimo_fresado_cosido'] = model('App\Models\Configuracion\ConfigVariableModel')->getVariable('lomo_minimo_fresado_cosido')->value;
|
||||
$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
|
||||
// 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,
|
||||
'acabado' => $cubierta['acabado'] ?? 0,
|
||||
'lomoRedondo' => $cubierta['lomoRedondo'] ?? 0,
|
||||
'cabezada' => $cubierta['cabezada'] ?? 'WHI',
|
||||
'cabezada' => $cubierta['cabezada'] ?? model('\App\Models\Configuracion\ConfigVariableModel')->getCabezadaDefault(),
|
||||
];
|
||||
|
||||
// Sobrecubierta
|
||||
|
||||
@ -56,4 +56,40 @@ class ConfigVariableModel extends Model
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
<?= 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>
|
||||
<tr>
|
||||
<th><?= lang('ConfigVariables.datatable.columns.name') ?></th>
|
||||
@ -55,7 +55,9 @@
|
||||
<div class="row g-4">
|
||||
<div class="col-12 mb-0">
|
||||
<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 class="col-12 mb-0">
|
||||
<label for="description" class="form-label"><?= lang('ConfigVariables.form.description') ?></label>
|
||||
@ -75,4 +77,13 @@
|
||||
<?= $this->endSection() ?>
|
||||
<?= $this->section("additionalExternalJs") ?>
|
||||
<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() ?>
|
||||
@ -247,19 +247,12 @@
|
||||
<label for="cabezada" class="form-label">
|
||||
<?= lang('Presupuestos.cabezada') ?>
|
||||
</label>
|
||||
<select class="form-select select2bs2" id="cabezada" name="cabezada">
|
||||
<option value="WHI">
|
||||
<?= lang('Presupuestos.blanca') ?>
|
||||
</option>
|
||||
<option value="GRE">
|
||||
<?= lang('Presupuestos.verde') ?>
|
||||
</option>
|
||||
<option value="BLUE">
|
||||
<?= lang('Presupuestos.azul') ?>
|
||||
</option>
|
||||
<option value="REDYEL">
|
||||
<?= lang('Presupuestos.rojaAmarilla') ?>
|
||||
<select class="form-select" name="cabezada" id="cabezada">
|
||||
<?php foreach ($cabezadas as $key => $langKey): ?>
|
||||
<option value="<?= esc($key) ?>">
|
||||
<?= lang($langKey) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@ -136,10 +136,11 @@
|
||||
<?= lang('Presupuestos.cabezada') ?>
|
||||
</label>
|
||||
<select class="form-select select2bs2" id="cabezada" name="cabezada">
|
||||
<option value="WHI"><?= lang('Presupuestos.blanca') ?></option>
|
||||
<option value="GRE"><?= lang('Presupuestos.verde') ?></option>
|
||||
<option value="BLUE"><?= lang('Presupuestos.azul') ?></option>
|
||||
<option value="REDYEL"><?= lang('Presupuestos.rojaAmarilla') ?></option>
|
||||
<?php foreach ($cabezadas as $key => $langKey): ?>
|
||||
<option value="<?= esc($key) ?>">
|
||||
<?= lang($langKey) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
|
||||
import Modal from "./modal.js";
|
||||
import Ajax from "./ajax.js";
|
||||
class ConfigVariableDatatable
|
||||
{
|
||||
constructor(domItem)
|
||||
{
|
||||
class ConfigVariableDatatable {
|
||||
constructor(domItem) {
|
||||
this.domItem = domItem
|
||||
this.datatableItem = this.domItem
|
||||
this.modalItem = $("#modalConfigVariableForm")
|
||||
@ -28,7 +26,8 @@ class ConfigVariableDatatable
|
||||
{ data: 'name', searchable: true, sortable: false },
|
||||
{ data: 'value', searchable: true, sortable: false },
|
||||
{ data: 'description', searchable: true, sortable: false },
|
||||
{data : 'action',sortable:false,searchable:false,
|
||||
{
|
||||
data: 'action', sortable: false, searchable: false,
|
||||
render: (d, t) => {
|
||||
return `
|
||||
<div class="btn-group btn-group-sm">
|
||||
@ -42,8 +41,7 @@ class ConfigVariableDatatable
|
||||
});
|
||||
|
||||
}
|
||||
events()
|
||||
{
|
||||
events() {
|
||||
this.modalItem.on("click", ".btn-update-variable", this.handleUpdateVariable.bind(this))
|
||||
this.datatableItem.on("click", ".edit-variable", (e) => {
|
||||
e.preventDefault()
|
||||
@ -52,8 +50,7 @@ class ConfigVariableDatatable
|
||||
})
|
||||
|
||||
}
|
||||
handleGetVariable()
|
||||
{
|
||||
handleGetVariable() {
|
||||
const url = `/configuracion/variables/find/${this.variableId}`
|
||||
let ajax = new Ajax(
|
||||
url, null, null,
|
||||
@ -66,20 +63,14 @@ class ConfigVariableDatatable
|
||||
handleGetVariableSuccess(data) {
|
||||
this.formEdit[0].reset()
|
||||
this.modalEdit.toggle()
|
||||
this.nameInput = this.formEdit
|
||||
.find("#name")
|
||||
this.nameInput = this.formEdit.find("#name")
|
||||
this.nameInput.val(data.name)
|
||||
this.valueInput = this.formEdit
|
||||
.find("#value")
|
||||
this.valueInput.val(data.value)
|
||||
this.descriptionInput = this.formEdit
|
||||
.find("#description")
|
||||
this.renderValueField(data.name, data.value)
|
||||
this.descriptionInput = this.formEdit.find("#description")
|
||||
this.descriptionInput.val(data.description)
|
||||
|
||||
}
|
||||
handleGetVariableError(err) { }
|
||||
handleUpdateVariable()
|
||||
{
|
||||
handleUpdateVariable() {
|
||||
const url = `/configuracion/variables/edit/${this.variableId}`
|
||||
const data = {
|
||||
value: this.valueInput.val(),
|
||||
@ -100,8 +91,7 @@ class ConfigVariableDatatable
|
||||
}
|
||||
handleUpdateVariableError(err) { }
|
||||
|
||||
handleDeleteVariable()
|
||||
{
|
||||
handleDeleteVariable() {
|
||||
const url = `/configuracion/variables/delete/${this.variableId}`
|
||||
let ajax = new Ajax(
|
||||
url, null, null,
|
||||
@ -114,6 +104,30 @@ class ConfigVariableDatatable
|
||||
this.datatable.reload()
|
||||
}
|
||||
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;
|
||||
Reference in New Issue
Block a user