feat: bolinha de status ativo/inativo clicavel na lista de clientes
This commit is contained in:
@@ -195,6 +195,7 @@ def listar(
|
||||
|
||||
primeiro_item = offset + 1 if total > 0 else 0
|
||||
ultimo_item = min(offset + por_pagina_efetivo, total)
|
||||
redirecionar_para = request.url.path + (f"?{request.url.query}" if request.url.query else "")
|
||||
|
||||
resposta = templates.TemplateResponse(
|
||||
request,
|
||||
@@ -207,6 +208,7 @@ def listar(
|
||||
"primeiro_item": primeiro_item, "ultimo_item": ultimo_item,
|
||||
"janela_paginas": _janela_paginas(pagina, total_paginas),
|
||||
"csrf_token": token_do_contexto(request),
|
||||
"redirecionar_para": redirecionar_para,
|
||||
},
|
||||
)
|
||||
if por_pagina in OPCOES_POR_PAGINA:
|
||||
@@ -408,3 +410,16 @@ def excluir(cliente_id: int, usuario: str = Depends(exigir_login)):
|
||||
|
||||
db_log.registrar(usuario, "excluir", "cliente", str(cliente_id), True)
|
||||
return _redirect_com_mensagem("/clientes", "Cliente excluído.")
|
||||
|
||||
|
||||
@router.post("/{cliente_id}/alternar-ativo", dependencies=[Depends(exigir_csrf)])
|
||||
def alternar_ativo(cliente_id: int, redirecionar_para: str = Form(""), usuario: str = Depends(exigir_login)):
|
||||
destino = redirecionar_para if redirecionar_para.startswith("/clientes") else "/clientes"
|
||||
|
||||
alternado = db_clientes.alternar_ativo(cliente_id)
|
||||
if not alternado:
|
||||
db_log.registrar(usuario, "alternar_ativo", "cliente", str(cliente_id), False, "cliente não encontrado")
|
||||
return _redirect_com_mensagem(destino, "Cliente não encontrado.", "danger")
|
||||
|
||||
db_log.registrar(usuario, "alternar_ativo", "cliente", str(cliente_id), True)
|
||||
return _redirect_com_mensagem(destino, "Status do cliente atualizado.")
|
||||
|
||||
@@ -246,6 +246,12 @@ a.botao:hover { border-color: var(--cor-acento); color: var(--cor-acento); }
|
||||
.chave-feedback-erro { color: var(--cor-perigo); }
|
||||
.botao-gerar-chave { margin-left: 6px; }
|
||||
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
||||
|
||||
.status-dot { display: inline-block; width: 12px; height: 12px; padding: 0; margin: 0; border: none; border-radius: 50%; cursor: pointer; vertical-align: middle; }
|
||||
.status-dot-ativo { background: var(--cor-sucesso); }
|
||||
.status-dot-inativo { background: var(--cor-perigo); }
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { transition: none !important; }
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
</a>
|
||||
</th>
|
||||
{% endfor %}
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for c in clientes %}
|
||||
@@ -45,6 +46,20 @@
|
||||
<td>{{ c.RAZAO }}</td>
|
||||
<td>{{ c.FANTASIA }}</td>
|
||||
<td>{{ c.CNPJ }}</td>
|
||||
<td>
|
||||
<form method="post" action="/clientes/{{ c.ID }}/alternar-ativo" style="display:inline">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
|
||||
<input type="hidden" name="redirecionar_para" value="{{ redirecionar_para }}">
|
||||
<button
|
||||
type="submit"
|
||||
class="status-dot {{ 'status-dot-ativo' if c.ATIVO else 'status-dot-inativo' }}"
|
||||
title="{{ 'Ativo — clique para desativar' if c.ATIVO else 'Inativo — clique para ativar' }}"
|
||||
onclick='return confirm({{ ((("Desativar" if c.ATIVO else "Reativar") + " o cliente " + c.RAZAO + "?")) | tojson }})'
|
||||
>
|
||||
<span class="sr-only">{{ "Ativo" if c.ATIVO else "Inativo" }}</span>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<a class="botao" href="/clientes/{{ c.ID }}">Abrir</a>
|
||||
<button type="button" class="botao botao-gerar-chave" data-codigo="{{ c.CODIGO }}" onclick="gerarChaveReativacao(this)">Gerar chave</button>
|
||||
|
||||
Reference in New Issue
Block a user