Spaces:
Build error
Build error
| const token = localStorage.getItem('token'); | |
| const username = localStorage.getItem('username'); | |
| if (username) { | |
| document.getElementById('user-name').innerText = username; | |
| document.getElementById('user-welcome').innerText = username; | |
| } | |
| function logout() { | |
| localStorage.clear(); | |
| window.location.href = '/'; | |
| } | |
| function showForm(action) { | |
| const container = document.getElementById('form-container'); | |
| let formHTML = ''; | |
| switch (action) { | |
| case 'adv-cad': | |
| formHTML = `<h3>Cadastrar Advogado</h3> | |
| <input type='text' id='nome-adv' placeholder='Nome Advogado'> | |
| <input type='text' id='uf-adv' placeholder='UF'> | |
| <button onclick='cadastrarAdvogado()'>Cadastrar</button>`; | |
| break; | |
| case 'adv-del': | |
| formHTML = `<h3>Deletar Advogado</h3> | |
| <input type='text' id='nome-adv-del' placeholder='Nome Advogado'> | |
| <input type='text' id='uf-adv-del' placeholder='UF'> | |
| <button onclick='deletarAdvogado()'>Deletar</button>`; | |
| break; | |
| case 'proc-cad': | |
| formHTML = `<h3>Cadastrar Processo</h3> | |
| <input type='text' id='num-proc' placeholder='Número Processo'> | |
| <input type='text' id='uf-proc' placeholder='UF'> | |
| <button onclick='cadastrarProcesso()'>Cadastrar</button>`; | |
| break; | |
| case 'proc-del': | |
| formHTML = `<h3>Deletar Processo</h3> | |
| <input type='text' id='num-proc-del' placeholder='Número Processo'> | |
| <input type='text' id='uf-proc-del' placeholder='UF'> | |
| <button onclick='deletarProcesso()'>Deletar</button>`; | |
| break; | |
| } | |
| container.innerHTML = formHTML; | |
| } | |
| async function cadastrarAdvogado() { | |
| const nome = document.getElementById('nome-adv').value; | |
| const uf = document.getElementById('uf-adv').value; | |
| const res = await fetch(`/api/monitoramento-processual/consulta/inserir-advogado?nome_advogado=${encodeURIComponent(nome)}&uf=${encodeURIComponent(uf)}`, { | |
| method: 'POST', | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| if (res.ok) { | |
| alert('Advogado cadastrado!'); | |
| await loadAdvogados(); | |
| } else { | |
| alert('Erro ao cadastrar advogado.'); | |
| } | |
| } | |
| async function deletarAdvogado() { | |
| const nome = document.getElementById('nome-adv-del').value; | |
| const uf = document.getElementById('uf-adv-del').value; | |
| const res = await fetch(`/api/monitoramento-processual/consulta/deletar-advogado?nome_advogado=${encodeURIComponent(nome)}&uf=${encodeURIComponent(uf)}`, { | |
| method: 'DELETE', | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| if (res.ok) { | |
| alert('Advogado deletado!'); | |
| await loadAdvogados(); | |
| } else { | |
| alert('Erro ao deletar advogado.'); | |
| } | |
| } | |
| async function cadastrarProcesso() { | |
| const num = document.getElementById('num-proc').value; | |
| const uf = document.getElementById('uf-proc').value; | |
| const res = await fetch(`/api/monitoramento-processual/consulta/inserir-processo?numero_processo=${encodeURIComponent(num)}&uf=${encodeURIComponent(uf)}`, { | |
| method: 'POST', | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| if (res.ok) { | |
| alert('Processo cadastrado!'); | |
| await loadProcessos(); | |
| } else { | |
| alert('Erro ao cadastrar processo.'); | |
| } | |
| } | |
| async function deletarProcesso() { | |
| const num = document.getElementById('num-proc-del').value; | |
| const uf = document.getElementById('uf-proc-del').value; | |
| const res = await fetch(`/api/monitoramento-processual/consulta/deletar-processo?numero_processo=${encodeURIComponent(num)}&uf=${encodeURIComponent(uf)}`, { | |
| method: 'DELETE', | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| if (res.ok) { | |
| alert('Processo deletado!'); | |
| await loadProcessos(); | |
| } else { | |
| alert('Erro ao deletar processo.'); | |
| } | |
| } | |
| async function loadAdvogados() { | |
| const res = await fetch(`/api/monitoramento-processual/consulta/listar-advogados`, { | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| const data = await res.json(); | |
| const tbody = document.querySelector('#advogados-table tbody'); | |
| tbody.innerHTML = ''; | |
| data.forEach(item => { | |
| const row = `<tr><td>${item.nome_advogado}</td><td>${item.uf}</td></tr>`; | |
| tbody.innerHTML += row; | |
| }); | |
| } | |
| async function loadProcessos() { | |
| const res = await fetch(`/api/monitoramento-processual/consulta/listar-processos`, { | |
| headers: { 'Authorization': `Bearer ${token}` } | |
| }); | |
| const data = await res.json(); | |
| const tbody = document.querySelector('#processos-table tbody'); | |
| tbody.innerHTML = ''; | |
| data.forEach(item => { | |
| const row = `<tr><td>${item.numero_processo}</td><td>${item.uf}</td></tr>`; | |
| tbody.innerHTML += row; | |
| }); | |
| } | |
| // Carregar ao abrir | |
| window.onload = () => { | |
| loadAdvogados(); | |
| loadProcessos(); | |
| }; | |