241 lines
11 KiB
HTML
241 lines
11 KiB
HTML
{% extends "base.html" %}
|
|
|
|
{% block title %}Militantes{% endblock %}
|
|
|
|
{% block content %}
|
|
<div class="row mb-4">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<h1 class="mb-0">
|
|
<i class="fas fa-users me-2"></i>Militantes
|
|
</h1>
|
|
{% if current_user.has_permission('gerenciar_militantes') %}
|
|
<a href="{{ url_for('criar_militante') }}" class="btn btn-primary">
|
|
<i class="fas fa-user-plus me-2"></i>Novo Militante
|
|
</a>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<div class="row mb-4">
|
|
<div class="col-md-6">
|
|
<div class="input-group">
|
|
<span class="input-group-text">
|
|
<i class="fas fa-search"></i>
|
|
</span>
|
|
<input type="text" class="form-control" id="searchInput" placeholder="Pesquisar militantes...">
|
|
</div>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<div class="d-flex justify-content-end gap-2">
|
|
<div class="btn-group">
|
|
<button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown">
|
|
<i class="fas fa-filter me-1"></i>Filtrar
|
|
</button>
|
|
<ul class="dropdown-menu">
|
|
<li><a class="dropdown-item" href="#" data-filter="todos">Todos</a></li>
|
|
<li><a class="dropdown-item" href="#" data-filter="filiados">Filiados</a></li>
|
|
<li><a class="dropdown-item" href="#" data-filter="nao-filiados">Não Filiados</a></li>
|
|
</ul>
|
|
</div>
|
|
<button type="button" class="btn btn-outline-secondary" id="btnExportar">
|
|
<i class="fas fa-download me-1"></i>Exportar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-hover" id="militantesTable">
|
|
<thead>
|
|
<tr>
|
|
<th data-sort="nome">Nome <i class="fas fa-sort"></i></th>
|
|
<th data-sort="cpf">CPF <i class="fas fa-sort"></i></th>
|
|
<th data-sort="email">Email <i class="fas fa-sort"></i></th>
|
|
<th data-sort="telefone">Telefone <i class="fas fa-sort"></i></th>
|
|
<th data-sort="celula">Célula <i class="fas fa-sort"></i></th>
|
|
<th>Responsabilidades</th>
|
|
<th class="text-end">Ações</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for militante in militantes %}
|
|
<tr data-militante="{{ militante.id }}" data-filiado="{{ 'sim' if militante.filiado else 'nao' }}">
|
|
<td data-nome="{{ militante.nome }}">{{ militante.nome }}</td>
|
|
<td data-cpf="{{ militante.cpf }}">{{ militante.cpf }}</td>
|
|
<td data-email="{{ militante.email }}">{{ militante.email }}</td>
|
|
<td data-telefone="{{ militante.telefone }}">{{ militante.telefone }}</td>
|
|
<td data-celula="{{ militante.celula.nome }}">{{ militante.celula.nome }}</td>
|
|
<td>
|
|
{% if militante.responsabilidades & Militante.RESPONSAVEL_FINANCAS %}
|
|
<span class="badge bg-primary">Finanças</span>
|
|
{% endif %}
|
|
{% if militante.responsabilidades & Militante.RESPONSAVEL_IMPRENSA %}
|
|
<span class="badge bg-info">Imprensa</span>
|
|
{% endif %}
|
|
{% if militante.responsabilidades & Militante.QUADRO_ORIENTADOR %}
|
|
<span class="badge bg-success">Quadro-Orientador</span>
|
|
{% endif %}
|
|
</td>
|
|
<td class="text-end">
|
|
<div class="btn-group">
|
|
{% if current_user.has_permission('gerenciar_militantes') %}
|
|
<a href="{{ url_for('editar_militante', id=militante.id) }}"
|
|
class="btn btn-sm btn-outline-primary"
|
|
title="Editar">
|
|
<i class="fas fa-edit"></i>
|
|
</a>
|
|
<button type="button"
|
|
class="btn btn-sm btn-outline-danger"
|
|
data-bs-toggle="modal"
|
|
data-bs-target="#deleteModal"
|
|
data-militante-id="{{ militante.id }}"
|
|
data-militante-nome="{{ militante.nome }}"
|
|
title="Excluir">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
{% endif %}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="d-flex justify-content-between align-items-center mt-4">
|
|
<div class="text-muted">
|
|
Mostrando <span id="countMilitantes">{{ militantes|length }}</span> militantes
|
|
</div>
|
|
<nav aria-label="Navegação de páginas">
|
|
<ul class="pagination mb-0">
|
|
<li class="page-item disabled" id="prevPage">
|
|
<a class="page-link" href="#"><i class="fas fa-chevron-left"></i></a>
|
|
</li>
|
|
<li class="page-item active"><a class="page-link" href="#">1</a></li>
|
|
<li class="page-item"><a class="page-link" href="#">2</a></li>
|
|
<li class="page-item"><a class="page-link" href="#">3</a></li>
|
|
<li class="page-item" id="nextPage">
|
|
<a class="page-link" href="#"><i class="fas fa-chevron-right"></i></a>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal de Confirmação de Exclusão -->
|
|
<div class="modal fade" id="deleteModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Confirmar Exclusão</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Tem certeza que deseja excluir o militante <strong id="militanteNome"></strong>?</p>
|
|
<p class="text-danger mb-0">Esta ação não pode ser desfeita.</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
|
|
<form action="" method="POST" id="deleteForm" class="d-inline">
|
|
<button type="submit" class="btn btn-danger">
|
|
<i class="fas fa-trash me-2"></i>Excluir
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block extra_js %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Configuração do modal de exclusão
|
|
const deleteModal = document.getElementById('deleteModal');
|
|
deleteModal.addEventListener('show.bs.modal', function(event) {
|
|
const button = event.relatedTarget;
|
|
const militanteId = button.getAttribute('data-militante-id');
|
|
const militanteNome = button.getAttribute('data-militante-nome');
|
|
|
|
document.getElementById('militanteNome').textContent = militanteNome;
|
|
document.getElementById('deleteForm').action = `/militantes/excluir/${militanteId}`;
|
|
});
|
|
|
|
// Pesquisa em tempo real
|
|
const searchInput = document.getElementById('searchInput');
|
|
searchInput.addEventListener('input', function() {
|
|
const searchTerm = this.value.toLowerCase();
|
|
const rows = document.querySelectorAll('#militantesTable tbody tr');
|
|
let visibleCount = 0;
|
|
|
|
rows.forEach(row => {
|
|
const text = row.textContent.toLowerCase();
|
|
const isVisible = text.includes(searchTerm);
|
|
row.style.display = isVisible ? '' : 'none';
|
|
if (isVisible) visibleCount++;
|
|
});
|
|
|
|
document.getElementById('countMilitantes').textContent = visibleCount;
|
|
});
|
|
|
|
// Filtros
|
|
const filterButtons = document.querySelectorAll('[data-filter]');
|
|
filterButtons.forEach(button => {
|
|
button.addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const filter = this.getAttribute('data-filter');
|
|
const rows = document.querySelectorAll('#militantesTable tbody tr');
|
|
let visibleCount = 0;
|
|
|
|
rows.forEach(row => {
|
|
const filiado = row.getAttribute('data-filiado');
|
|
let isVisible = true;
|
|
|
|
if (filter === 'filiados') {
|
|
isVisible = filiado === 'sim';
|
|
} else if (filter === 'nao-filiados') {
|
|
isVisible = filiado === 'nao';
|
|
}
|
|
|
|
row.style.display = isVisible ? '' : 'none';
|
|
if (isVisible) visibleCount++;
|
|
});
|
|
|
|
document.getElementById('countMilitantes').textContent = visibleCount;
|
|
});
|
|
});
|
|
|
|
// Exportar para CSV
|
|
document.getElementById('btnExportar').addEventListener('click', function() {
|
|
const rows = document.querySelectorAll('#militantesTable tbody tr:not([style*="display: none"])');
|
|
let csv = 'Nome,CPF,Email,Telefone,Célula\n';
|
|
|
|
rows.forEach(row => {
|
|
const nome = row.querySelector('[data-nome]').getAttribute('data-nome');
|
|
const cpf = row.querySelector('[data-cpf]').getAttribute('data-cpf');
|
|
const email = row.querySelector('[data-email]').getAttribute('data-email');
|
|
const telefone = row.querySelector('[data-telefone]').getAttribute('data-telefone');
|
|
const celula = row.querySelector('[data-celula]').getAttribute('data-celula');
|
|
|
|
csv += `"${nome}","${cpf}","${email}","${telefone}","${celula}"\n`;
|
|
});
|
|
|
|
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.setAttribute('href', url);
|
|
link.setAttribute('download', 'militantes.csv');
|
|
link.style.visibility = 'hidden';
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|
|
{% endblock %} |