Delegación

📍 Portal de Delegación / Vocales

Espacio de trabajo local para envío de informes, solicitudes de presupuesto y consulta de socios de tu región.

Cargando delegado/a…

👥 Socios/as de la Delegación / Contactos Básicos

Nombre Email Teléfono Dirección Provincia
Cargando socios/as…

📍 Enviar Documento a Socio Regional

Cargando socios locales…

📤 Comunicados Regionales Enviados

Socio Documento Fecha Acciones
Cargando historial de envíos…

Enviar Documento a la Central

Historial de Envíos a Central

Documento Fecha de Subida Acciones
Iniciando sesión y cargando…

💬 Comunicaciones Recibidas de Socios Regionales

Socio Remitente Asunto Fecha Recepción Archivo Adjunto
Cargando bandeja de entrada…
const apiToken = ‘RwHqQJvGgqy8G5jyBgSW4g2W’; const department = ‘delegacion’; let currentUser = null; let viewUserId = null; let globalLocalSocios = []; const urlParams = new URLSearchParams(window.location.search); viewUserId = urlParams.get(‘user_id’); async function init() { try { if (viewUserId) { const resM = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/get-members’, { headers: { ‘X-AEPOD-Token’: apiToken } }); if (resM.status === 200) { const miembros = await resM.json(); currentUser = miembros.find(x => x.id == viewUserId); } } else { const resMe = await fetch(‘https://aepod.es/wp-json/wp/v2/users/me’, { headers: { ‘X-Requested-With’: ‘XMLHttpRequest’ } }); if (resMe.status === 200) { const wpUser = await resMe.json(); currentUser = { id: wpUser.id, username: wpUser.slug, name: wpUser.name, email: wpUser.email }; } } if (currentUser) { document.getElementById(‘title-delegacion’).innerText = ‘📍 ‘ + (currentUser.name || ‘Portal de Delegación’); document.getElementById(‘delegado-name’).innerText = currentUser.email; await loadFiles(); await loadSocios(); await loadSentMailboxFiles(); await loadInboxFiles(); } else { document.getElementById(‘files-tbody’).innerHTML = ‘Error al cargar el perfil de la delegación.‘; } } catch(e) { console.error(e); } } async function loadSocios() { try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/get-socios?viewer_id=’ + currentUser.id, { headers: { ‘X-AEPOD-Token’: apiToken } }); if (res.status === 200) { const socios = await res.json(); globalLocalSocios = socios; renderSocios(socios); populateSocioSelect(socios); } } catch(e) { console.error(e); } } function populateSocioSelect(socios) { const select = document.getElementById(‘mailbox-socio-select’); select.innerHTML = ‘Selecciona un socio local…’; socios.forEach(s => { select.innerHTML += `${s.name} (${s.username})`; }); } function renderSocios(socios) { const tbody = document.getElementById(‘socios-tbody’); tbody.innerHTML = ”; if (socios.length === 0) { tbody.innerHTML = ‘No hay socios registrados en esta demarcación regional.‘; return; } socios.forEach(s => { tbody.innerHTML += ` ${s.name} ${s.email} ${s.telefono || ‘-‘} ${s.direccion || ‘-‘} ${s.provincia || ‘-‘} `; }); } async function loadFiles() { try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/get-files?department=’ + department + ‘&owner_id=’ + currentUser.id, { headers: { ‘X-AEPOD-Token’: apiToken } }); if (res.status === 200) { const files = await res.json(); const generalFiles = files.filter(f => !f.target_user_id); renderFiles(generalFiles); } } catch(e) { console.error(e); } } function renderFiles(files) { const tbody = document.getElementById(‘files-tbody’); tbody.innerHTML = ”; if (files.length === 0) { tbody.innerHTML = ‘No has enviado informes generales a la Central.‘; return; } files.forEach(f => { tbody.innerHTML += ` ${f.title} ${f.date} Ver Documento 📥 `; }); } async function loadSentMailboxFiles() { try { // Filtrar archivos de delegación mandados por esta delegación (como owner_id) const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/get-files?department=’ + department + ‘&owner_id=’ + currentUser.id, { headers: { ‘X-AEPOD-Token’: apiToken } }); if (res.status === 200) { const files = await res.json(); const sentToSocios = files.filter(f => f.target_user_id); const tbody = document.getElementById(‘sent-mailbox-tbody’); tbody.innerHTML = ”; if (sentToSocios.length === 0) { tbody.innerHTML = ‘No hay comunicados enviados a socios regionales.‘; return; } sentToSocios.forEach(f => { const destSocio = globalLocalSocios.find(x => x.id == f.target_user_id); const destName = destSocio ? destSocio.name : ‘Socio Regional #’ + f.target_user_id; tbody.innerHTML += ` ${destName} ${f.title} ${f.date} Visualizar `; }); } } catch(e) { console.error(e); } } async function loadInboxFiles() { try { // Comunicaciones enviadas a la delegación (se filtra por el slug o user_login del delegado) // El target_department será ‘delegacion_[username]’ const targetDeptVal = ‘delegacion_’ + currentUser.username; const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/get-files?target_department=’ + targetDeptVal, { headers: { ‘X-AEPOD-Token’: apiToken } }); if (res.status === 200) { const files = await res.json(); const tbody = document.getElementById(‘inbox-tbody’); tbody.innerHTML = ”; if (files.length === 0) { tbody.innerHTML = ‘No hay comunicaciones recibidas de socios locales.‘; return; } files.forEach(f => { tbody.innerHTML += ` ${f.owner_name} ${f.title} ${f.date} Descargar / Leer 📥 `; }); } } catch(e) { console.error(e); } } async function sendToSocioMailbox(event) { event.preventDefault(); const btn = document.getElementById(‘btn-submit-mailbox’); btn.innerText = ‘Subiendo…’; btn.disabled = true; const socioId = document.getElementById(‘mailbox-socio-select’).value; const title = document.getElementById(‘mailbox-title’).value; const fileInput = document.getElementById(‘mailbox-file’); const formData = new FormData(); formData.append(‘file’, fileInput.files[0], title + ‘.’ + fileInput.files[0].name.split(‘.’).pop()); formData.append(‘department’, department); formData.append(‘owner_id’, currentUser.id); formData.append(‘owner_name’, currentUser.name || currentUser.username); formData.append(‘target_user_id’, socioId); try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/upload-file’, { method: ‘POST’, headers: { ‘X-AEPOD-Token’: apiToken }, body: formData }); if (res.status === 200) { document.getElementById(‘socio-mailbox-form’).reset(); await loadSentMailboxFiles(); alert(‘Documento enviado al buzón del socio regional con éxito.’); } else { alert(‘Error al enviar el archivo.’); } } catch(e) { alert(‘Error de conexión.’); } finally { btn.innerText = ‘Depositar en Buzón’; btn.disabled = false; } } async function deleteSentMailbox(id) { if (!confirm(‘¿Seguro que deseas eliminar este comunicado del buzón del socio?’)) return; try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/delete-file’, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-AEPOD-Token’: apiToken }, body: JSON.stringify({ id: id }) }); if (res.status === 200) { await loadSentMailboxFiles(); } else { alert(‘No se pudo borrar el archivo.’); } } catch(e) { alert(‘Error de conexión.’); } } async function handleUpload(event) { event.preventDefault(); const btn = document.getElementById(‘btn-submit’); btn.innerText = ‘Subiendo…’; btn.disabled = true; const fileInput = document.getElementById(‘file-input’); const fileTitle = document.getElementById(‘file-title’).value; const formData = new FormData(); formData.append(‘file’, fileInput.files[0], fileTitle + ‘.’ + fileInput.files[0].name.split(‘.’).pop()); formData.append(‘department’, department); formData.append(‘owner_id’, currentUser.id); formData.append(‘owner_name’, currentUser.name || currentUser.username); try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/upload-file’, { method: ‘POST’, headers: { ‘X-AEPOD-Token’: apiToken }, body: formData }); if (res.status === 200) { document.getElementById(‘upload-form’).reset(); await loadFiles(); } else { alert(‘Error al subir el archivo.’); } } catch(e) { alert(‘Error de conexión.’); } finally { btn.innerText = ‘Subir Documento’; btn.disabled = false; } } async function deleteFile(id) { if (!confirm(‘¿Seguro que deseas eliminar este documento?’)) return; try { const res = await fetch(‘https://aepod.es/wp-json/aepod-jd/v1/delete-file’, { method: ‘POST’, headers: { ‘Content-Type’: ‘application/json’, ‘X-AEPOD-Token’: apiToken }, body: JSON.stringify({ id: id }) }); if (res.status === 200) { await loadFiles(); } else { alert(‘No se pudo borrar el archivo.’); } } catch(e) { alert(‘Error de conexión.’); } } window.addEventListener(‘DOMContentLoaded’, init);
Scroll al inicio