update form veh 27nov
This commit is contained in:
Vendored
BIN
Binary file not shown.
+108
-19
@@ -71,11 +71,13 @@
|
||||
|
||||
<div class="page-header">
|
||||
<div class="page-eyebrow">Vehículos</div>
|
||||
<div class="page-title">{{ 'Editar vehículo ' ~ vehiculo['m_oficial'] if vehiculo else 'Nuevo vehículo' }}</div>
|
||||
|
||||
<div class="page-subtitle">
|
||||
<div class="page-title" style="float:left; opacity: 0.7;">{{ 'Editar vehículo ' ~ vehiculo['m_oficial'] if vehiculo else 'Nuevo vehículo' }}</div>
|
||||
<div class="page-title" style="float:right; opacity: 0.5;">{{ vehiculo['marca'] ~ ' ' ~ vehiculo['modelo'] if vehiculo else '' }}</div>
|
||||
<div class="page-subtitle" style="clear: both;">
|
||||
{{ 'Modifica los datos del vehículo.' if vehiculo else 'Completa el formulario para registrar un nuevo vehículo.' }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-card">
|
||||
<form method="POST" id="formVehiculo">
|
||||
@@ -131,14 +133,14 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="viat">Via-T</label>
|
||||
<input class="form-input" type="text" id="viat" name="viat" style="width: 210px; padding-left: 10px;"
|
||||
<input class="form-input" type="text" id="viat" name="viat" style="width: 210px;"
|
||||
oninput="this.value = this.value.toUpperCase();"
|
||||
value="{{ (vehiculo['viat'] or '') if vehiculo else request.form.get('viat', '') }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group" >
|
||||
<label class="form-label" for="legajo">Legajo</label>
|
||||
<input class="form-input" id="legajo" name="legajo"
|
||||
<input class="form-input" id="legajo" name="legajo" style="width: 130px"
|
||||
placeholder=""
|
||||
value="{{ (vehiculo['legajo'] or '') if vehiculo else request.form.get('legajo', '') }}">
|
||||
</div>
|
||||
@@ -199,7 +201,7 @@
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="plazas">Plazas</label>
|
||||
<input class="form-input" type="text" id="plazas" name="plazas"
|
||||
<input class="form-input" type="number" id="plazas" name="plazas" min="0"
|
||||
placeholder="Nº de plazas"
|
||||
value="{{ (vehiculo['plazas'] or '') if vehiculo else request.form.get('plazas', '') }}">
|
||||
</div>
|
||||
@@ -375,17 +377,17 @@
|
||||
|
||||
<div class="form-actions" style="margin:25px">
|
||||
<button type="submit" class="btn btn-primary" id="btnGuardar" form="formVehiculo"> <i class="bi bi-floppy" style="font-size: 1rem;"></i>
|
||||
{{ 'GUARDAR CAMBIOS' if vehiculo else ' Registrar vehículo' }}
|
||||
{{ 'GUARDAR CAMBIOS' if vehiculo else ' REGISTRAR VEHÍCULO' }}
|
||||
</button>
|
||||
|
||||
{# Cancelar #}
|
||||
|
||||
{% if origen == 'viat' %}
|
||||
<a href="/viat?q={{ q_viat }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>VOLVER</a>
|
||||
<a href="/viat?q={{ q_viat }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>SALIR</a>
|
||||
{% elif desde or hasta or q_itv %}
|
||||
<a href="/itv?desde={{ desde }}&hasta={{ hasta }}&q_itv={{ q_itv }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>VOLVER</a>
|
||||
<a href="/itv?desde={{ desde }}&hasta={{ hasta }}&q_itv={{ q_itv }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>SALIR</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('vehiculos_list', q=q) if q else url_for('vehiculos_list') }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>VOLVER</a>
|
||||
<a href="{{ url_for('vehiculos_list', q=q) if q else url_for('vehiculos_list') }}" class="btn btn-ghost" id="btnCancelar" style="background-color: gray; color: white;"><i class="bi bi-box-arrow-left"></i>SALIR</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- <div style="display:flex;justify-content:space-between;align-items:center;margin-top:12px;"> -->
|
||||
@@ -395,17 +397,16 @@
|
||||
Ficha - Imprimir/PDF
|
||||
</button>
|
||||
{% endif %}
|
||||
<!-- </div> -->
|
||||
|
||||
</div>
|
||||
|
||||
</form> {# ← CIERRE del formulario principal #}
|
||||
|
||||
|
||||
<div class="form-card">
|
||||
|
||||
{# ── HISTORIAL (fuera del form principal) ── #}
|
||||
{% if vehiculo %}
|
||||
<div class="form-card">
|
||||
<div class="section-title" style="margin-top:0px">Historial</div>
|
||||
|
||||
{% if historial %}
|
||||
@@ -660,14 +661,14 @@
|
||||
|
||||
<div class="modal-backdrop" id="modalCambios" role="dialog" aria-modal="true"
|
||||
aria-labelledby="modalCambiosTitulo">
|
||||
<div class="modal-box" style="max-width: 400px; text-align:center;">
|
||||
<h3 id="modalCambiosTitulo">Hay cambios sin guardar</h3>
|
||||
<p>Has modificado datos de este vehículo.</p>
|
||||
<p>¿Qué quieres hacer con los cambios?</p>
|
||||
<div class="modal-actions">
|
||||
<button type="button" class="btn btn-ghost" id="mcSeguir">Seguir editando</button>
|
||||
<button type="button" class="btn btn-danger" id="mcDescartar">Descartar</button>
|
||||
<div class="modal-box" style="max-width: 440px; text-align:center;">
|
||||
<!-- <h3 id="modalCambiosTitulo">Hay cambios sin guardar</h3> -->
|
||||
<h4 style="font-weight: bold">¿Quiere guardar los cambios efectuados en {{ vehiculo['m_oficial'] }}?</h4>
|
||||
<p style="color: red">Los cambios se perderán si no los guarda.</p>
|
||||
<div class="modal-actions" style="text-align:center;"></div>
|
||||
<button type="button" class="btn btn-primary" id="mcGuardar">Guardar</button>
|
||||
<button type="button" class="btn" id="mcDescartar">No guardar</button>
|
||||
<button type="button" class="btn" id="mcSeguir">Cancelar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -914,11 +915,18 @@ checkbox.addEventListener('change', function () {
|
||||
guardar();
|
||||
});
|
||||
|
||||
|
||||
/* ── Interceptar todo lo que haga salir de la página o recargarla ──
|
||||
Cancelar, enlaces del menú lateral y los botones de los otros formularios
|
||||
(añadir/eliminar historial, subir/eliminar documento, eliminar vehículo…) */
|
||||
// Botones/enlaces que recargan o abandonan la página
|
||||
var OTROS = 'form:not(#formVehiculo) ';
|
||||
var SALIDAS = '#btnCancelar, nav a[href], ' +
|
||||
'form:not(#formVehiculo) button, form:not(#formVehiculo) input[type="submit"]';
|
||||
OTROS + 'button[type="submit"], ' + OTROS + 'input[type="submit"], ' +
|
||||
OTROS + 'button[onclick*="submit"], ' + OTROS + 'button[onclick*="confirmarEliminar"]';
|
||||
|
||||
// Estos dos guardan los cambios del vehículo SIN preguntar y después continúan
|
||||
var AUTOGUARDAR = 'form[action*="/historial/nuevo"], form[action*="/documentos/upload"]';
|
||||
|
||||
document.addEventListener('click', function(e) {
|
||||
if (saltar || !hayCambios()) return;
|
||||
@@ -928,6 +936,25 @@ checkbox.addEventListener('change', function () {
|
||||
var h = el.getAttribute('href') || '';
|
||||
if (h.charAt(0) === '#' || /^javascript:/i.test(h) || el.target === '_blank') return;
|
||||
}
|
||||
|
||||
/* Añadir al historial / Subir documento: guardar primero, sin modal */
|
||||
var fAuto = EDITANDO ? el.closest(AUTOGUARDAR) : null;
|
||||
if (fAuto) {
|
||||
if (!fAuto.checkValidity()) return; // falta algo en ese formulario: que el navegador lo indique
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
if (!form.checkValidity()) { // campos obligatorios del vehículo sin rellenar
|
||||
toast('Completa los campos obligatorios del vehículo antes de continuar.', 'error');
|
||||
form.reportValidity();
|
||||
return;
|
||||
}
|
||||
guardar().then(function(ok) {
|
||||
if (ok) { saltar = true; el.click(); saltar = false; } // ahora sí: añadir / subir
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
/* Resto de salidas: preguntar qué hacer con los cambios */
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation(); // evita que corra el onclick/confirm del botón
|
||||
abrir(function() { saltar = true; el.click(); saltar = false; }); // se relanza tras decidir
|
||||
@@ -962,6 +989,68 @@ checkbox.addEventListener('change', function () {
|
||||
if (e.target === modal) { pendiente = null; cerrar(); }
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ── Interceptar todo lo que haga salir de la página o recargarla ──
|
||||
Cancelar, enlaces del menú lateral y los botones de los otros formularios
|
||||
(añadir/eliminar historial, subir/eliminar documento, eliminar vehículo…) */
|
||||
// var SALIDAS = '#btnCancelar, nav a[href], ' +
|
||||
// 'form:not(#formVehiculo) button, form:not(#formVehiculo) input[type="submit"]';
|
||||
|
||||
// document.addEventListener('click', function(e) {
|
||||
// if (saltar || !hayCambios()) return;
|
||||
// var el = e.target.closest(SALIDAS);
|
||||
// if (!el) return;
|
||||
// if (el.matches('a')) { // enlaces que no abandonan la página
|
||||
// var h = el.getAttribute('href') || '';
|
||||
// if (h.charAt(0) === '#' || /^javascript:/i.test(h) || el.target === '_blank') return;
|
||||
// }
|
||||
// e.preventDefault();
|
||||
// e.stopImmediatePropagation(); // evita que corra el onclick/confirm del botón
|
||||
// abrir(function() { saltar = true; el.click(); saltar = false; }); // se relanza tras decidir
|
||||
// }, true);
|
||||
|
||||
// /* ── Botones del modal ── */
|
||||
// document.getElementById('mcSeguir').addEventListener('click', function() {
|
||||
// pendiente = null; cerrar();
|
||||
// });
|
||||
|
||||
// document.getElementById('mcDescartar').addEventListener('click', function() {
|
||||
// cerrar(); continuar(); // se descartan los cambios y se hace lo que se pedía
|
||||
// });
|
||||
|
||||
// document.getElementById('mcGuardar').addEventListener('click', function() {
|
||||
// cerrar();
|
||||
// if (!EDITANDO) { // alta nueva: envío normal
|
||||
// if (form.requestSubmit) form.requestSubmit(); else form.submit();
|
||||
// return;
|
||||
// }
|
||||
// if (form.checkValidity && !form.checkValidity()) { // respeta los campos obligatorios
|
||||
// pendiente = null; form.reportValidity(); return;
|
||||
// }
|
||||
// guardar().then(function(ok) { if (ok) continuar(); else pendiente = null; });
|
||||
// });
|
||||
|
||||
// // Escape o clic fuera del cuadro = seguir editando
|
||||
// document.addEventListener('keydown', function(e) {
|
||||
// if (e.key === 'Escape' && modal.classList.contains('open')) { pendiente = null; cerrar(); }
|
||||
// });
|
||||
// modal.addEventListener('click', function(e) {
|
||||
// if (e.target === modal) { pendiente = null; cerrar(); }
|
||||
// });
|
||||
// })();
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
(function() {
|
||||
var estado = { col: -1, asc: true };
|
||||
document.querySelectorAll('#tablaViat thead th').forEach(function(th, idx) {
|
||||
th.style.cursor = 'pointer'; th.style.userSelect = 'none';
|
||||
th.style.cursor = 'pointer'; th.style.userSelect = 'none'; th.title = 'Pulsa para ordenar';
|
||||
var icon = document.createElement('span');
|
||||
icon.style.cssText = 'margin-left:5px;opacity:.3;font-size:10px;';
|
||||
icon.textContent = '⇅'; icon.className = 'sort-icon';
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user