Correção da função filtro de Operções exemplo UBS***
This commit is contained in:
@@ -69,12 +69,12 @@
|
|||||||
<div class="bg-[#0a0a0a] border border-[#2a2a2a] rounded-lg p-3 max-h-64 overflow-y-auto space-y-1">
|
<div class="bg-[#0a0a0a] border border-[#2a2a2a] rounded-lg p-3 max-h-64 overflow-y-auto space-y-1">
|
||||||
<% if @motoristas.any? %>
|
<% if @motoristas.any? %>
|
||||||
<label class="flex items-center gap-2 text-orange-400 text-sm font-semibold pb-2 border-b border-[#2a2a2a] cursor-pointer">
|
<label class="flex items-center gap-2 text-orange-400 text-sm font-semibold pb-2 border-b border-[#2a2a2a] cursor-pointer">
|
||||||
<input type="checkbox" onclick="document.querySelectorAll('.chk-motorista').forEach(c => c.checked = this.checked)"
|
<input type="checkbox" onclick="document.querySelectorAll('.motorista-row').forEach(r => { if (!r.classList.contains('hidden')) r.querySelector('.chk-motorista').checked = this.checked; })"
|
||||||
class="rounded text-orange-500 bg-[#1a1a1a] border-[#2a2a2a]">
|
class="rounded text-orange-500 bg-[#1a1a1a] border-[#2a2a2a]">
|
||||||
Selecionar todos
|
Selecionar todos
|
||||||
</label>
|
</label>
|
||||||
<% @motoristas.each do |m| %>
|
<% @motoristas.each do |m| %>
|
||||||
<label class="flex items-center gap-2 text-white hover:bg-[#1a1a1a] rounded px-2 py-2 cursor-pointer min-h-[44px]">
|
<label class="motorista-row flex items-center gap-2 text-white hover:bg-[#1a1a1a] rounded px-2 py-2 cursor-pointer min-h-[44px]">
|
||||||
<%= check_box_tag 'motoristas[]', m, false, class: 'chk-motorista rounded text-orange-500 bg-[#1a1a1a] border-[#2a2a2a]', id: nil %>
|
<%= check_box_tag 'motoristas[]', m, false, class: 'chk-motorista rounded text-orange-500 bg-[#1a1a1a] border-[#2a2a2a]', id: nil %>
|
||||||
<%= m %>
|
<%= m %>
|
||||||
</label>
|
</label>
|
||||||
@@ -189,9 +189,23 @@
|
|||||||
return Array.from(document.querySelectorAll('.chk-operacao:checked')).map(c => c.value);
|
return Array.from(document.querySelectorAll('.chk-operacao:checked')).map(c => c.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mostra todos os motoristas e desmarca tudo (estado sem operação).
|
||||||
|
function resetarMotoristas() {
|
||||||
|
document.querySelectorAll('.motorista-row').forEach(r => {
|
||||||
|
r.classList.remove('hidden');
|
||||||
|
r.querySelector('.chk-motorista').checked = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function aplicarOperacoes() {
|
async function aplicarOperacoes() {
|
||||||
const ops = operacoesSelecionadas();
|
const ops = operacoesSelecionadas();
|
||||||
if (!ops.length) { if (opStatus) opStatus.textContent = ''; return; }
|
|
||||||
|
// Sem operação: volta a mostrar a lista completa de motoristas.
|
||||||
|
if (!ops.length) {
|
||||||
|
resetarMotoristas();
|
||||||
|
if (opStatus) opStatus.textContent = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (opStatus) opStatus.textContent = 'Carregando dados da operação…';
|
if (opStatus) opStatus.textContent = 'Carregando dados da operação…';
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
@@ -204,16 +218,22 @@
|
|||||||
if (data.inicio && dataIni) dataIni.value = data.inicio;
|
if (data.inicio && dataIni) dataIni.value = data.inicio;
|
||||||
if (data.fim && dataFim) dataFim.value = data.fim;
|
if (data.fim && dataFim) dataFim.value = data.fim;
|
||||||
|
|
||||||
|
// Filtra a lista: mostra só os motoristas da operação (já marcados). O
|
||||||
|
// admin pode desmarcar e deixar só um, ou manter todos.
|
||||||
const motset = new Set(data.motoristas || []);
|
const motset = new Set(data.motoristas || []);
|
||||||
document.querySelectorAll('.chk-motorista').forEach(c => { if (motset.has(c.value)) c.checked = true; });
|
document.querySelectorAll('.motorista-row').forEach(r => {
|
||||||
|
const chk = r.querySelector('.chk-motorista');
|
||||||
|
const naOperacao = motset.has(chk.value);
|
||||||
|
r.classList.toggle('hidden', !naOperacao);
|
||||||
|
chk.checked = naOperacao;
|
||||||
|
});
|
||||||
|
|
||||||
await atualizarVeiculos();
|
await atualizarVeiculos();
|
||||||
const vehset = new Set(data.veiculos || []);
|
const vehset = new Set(data.veiculos || []);
|
||||||
lista.querySelectorAll('input[name="consolidacao[vehicle_ids][]"]').forEach(c => { if (vehset.has(c.value)) c.checked = true; });
|
lista.querySelectorAll('input[name="consolidacao[vehicle_ids][]"]').forEach(c => { if (vehset.has(c.value)) c.checked = true; });
|
||||||
|
|
||||||
if (opStatus) {
|
if (opStatus) {
|
||||||
opStatus.textContent = (data.motoristas || []).length + ' motorista(s) e ' +
|
opStatus.textContent = (data.motoristas || []).length + ' motorista(s) na operação — desmarque para fazer de um só, ou mantenha todos.';
|
||||||
(data.veiculos || []).length + ' veículo(s) nesta(s) operação(ões).';
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (opStatus) opStatus.textContent = 'Erro ao carregar dados da operação.';
|
if (opStatus) opStatus.textContent = 'Erro ao carregar dados da operação.';
|
||||||
|
|||||||
Reference in New Issue
Block a user