reset de modal rendiciones + visualizacion de part time v1
This commit is contained in:
@@ -330,7 +330,7 @@ def register_admin_routes(app):
|
||||
r_completa = r + (items, total_calculado, comision_total)
|
||||
rendiciones_completas.append(r_completa)
|
||||
|
||||
c.execute("SELECT id, name FROM workers WHERE is_admin = 0 ORDER BY name")
|
||||
c.execute("SELECT id, name, tipo FROM workers WHERE is_admin = 0 ORDER BY name")
|
||||
workers = c.fetchall()
|
||||
|
||||
c.execute("SELECT id, name FROM modulos ORDER BY name")
|
||||
|
||||
@@ -86,5 +86,42 @@
|
||||
|
||||
document.getElementById(`display_nuevo_total_${id}`).innerText = '$' + total.toLocaleString('es-CL');
|
||||
}
|
||||
|
||||
function updateComisionToggle(selectElement, toggleId) {
|
||||
const selectedOption = selectElement.options[selectElement.selectedIndex];
|
||||
const tipoJornada = selectedOption.getAttribute('data-tipo');
|
||||
const toggleSwitch = document.getElementById(toggleId);
|
||||
|
||||
if (toggleSwitch && tipoJornada) {
|
||||
// Si es Full Time, lo enciende (true). Si es Part Time, lo apaga (false).
|
||||
toggleSwitch.checked = (tipoJornada === 'Full Time');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Escuchar el evento de cierre de cualquier modal que empiece con 'editRendicion'
|
||||
const editModals = document.querySelectorAll('[id^="editRendicion"]');
|
||||
|
||||
editModals.forEach(modal => {
|
||||
modal.addEventListener('hidden.bs.modal', function () {
|
||||
const form = this.querySelector('form');
|
||||
if (form) {
|
||||
// 1. Resetear campos estándar (inputs, selects, textareas)
|
||||
form.reset();
|
||||
|
||||
// 2. Forzar la actualización del total visual (el que calculas por JS)
|
||||
const rendicionId = this.id.replace('editRendicion', '');
|
||||
calcTotalEdit(rendicionId);
|
||||
|
||||
// 3. Manejo especial para el div del acompañante (si aplica)
|
||||
const companionSelect = form.querySelector('select[name="companion_id"]');
|
||||
const compDiv = document.getElementById(`comp_com_div_${rendicionId}`);
|
||||
if (companionSelect && compDiv) {
|
||||
compDiv.style.display = companionSelect.value ? 'block' : 'none';
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -321,9 +321,9 @@
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Trabajador</label>
|
||||
<select class="form-select" name="worker_id" required>
|
||||
<select class="form-select" name="worker_id" onchange="updateComisionToggle(this, 'wc_{{ rendicion[0] }}')" required>
|
||||
{% for w in workers %}
|
||||
<option value="{{ w[0] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }}</option>
|
||||
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[11] %}selected{% endif %}>{{ w[1] }} ({{ w[2] }})</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-check form-switch mt-2">
|
||||
@@ -333,10 +333,10 @@
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Acompañante</label>
|
||||
<select class="form-select" name="companion_id" onchange="document.getElementById('comp_com_div_{{ rendicion[0] }}').style.display = this.value ? 'block' : 'none';">
|
||||
<option value="">Sin acompañante</option>
|
||||
<select class="form-select" name="companion_id" onchange="document.getElementById('comp_com_div_{{ rendicion[0] }}').style.display = this.value ? 'block' : 'none'; updateComisionToggle(this, 'cc_{{ rendicion[0] }}');">
|
||||
<option value="" data-tipo="">Sin acompañante</option>
|
||||
{% for w in workers %}
|
||||
<option value="{{ w[0] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }}</option>
|
||||
<option value="{{ w[0] }}" data-tipo="{{ w[2] }}" {% if w[0] == rendicion[12] %}selected{% endif %}>{{ w[1] }} ({{ w[2] }})</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<div class="form-check form-switch mt-2" id="comp_com_div_{{ rendicion[0] }}" {% if not rendicion[12] %}style="display:none;"{% endif %}>
|
||||
|
||||
Reference in New Issue
Block a user