/* Sitio Drogheda: detalles que necesitan datos del servidor en todas las páginas. - Junto a «Pendientes» en el menú lateral, cuántos hay abiertos (de /api/tareas/resumen). - (23-oct) Quien sigue con la contraseña inicial (la que le dieron al darle acceso o al restablecerla) ve una franja arriba con la liga a Mi cuenta. Lo dice /api/whoami; el servidor quita la marca cuando la cambia. Si el servidor no responde, la página queda igual. */ (function () { function cuentaPendientes() { var ligas = [].slice.call(document.querySelectorAll('.md-nav--primary a.md-nav__link')).filter(function (a) { try { return /\/tableros\/pendientes\/?$/.test(new URL(a.href, location.href).pathname); } catch (e) { return false; } }); if (!ligas.length) return; fetch('/api/tareas/resumen', { cache: 'no-store', credentials: 'same-origin' }) .then(function (r) { return r.ok ? r.json() : null; }) .then(function (j) { if (!j || !j.ok || !j.por_pista) return; var abiertos = 0; Object.keys(j.por_pista).forEach(function (p) { var e = j.por_pista[p] || {}; abiertos += (e['por-hacer'] || 0) + (e['en-curso'] || 0) + (e['bloqueado'] || 0); }); var vencidos = (j.vencidas || []).length; ligas.forEach(function (a) { if (a.querySelector('.hg-cuenta')) return; var s = document.createElement('span'); s.className = 'hg-cuenta' + (vencidos ? ' hg-cuenta--vencidos' : ''); s.textContent = abiertos; s.title = abiertos + ' abiertos' + (vencidos ? ', ' + vencidos + ' vencido' + (vencidos > 1 ? 's' : '') : ''); a.appendChild(s); }); }) .catch(function () {}); } function avisoContrasena() { fetch('/api/whoami', { cache: 'no-store', credentials: 'same-origin' }) .then(function (r) { return r.ok ? r.json() : null; }) .then(function (j) { if (!j || !j.contrasena_inicial || document.querySelector('.hg-pass-inicial')) return; var d = document.createElement('div'); d.className = 'hg-pass-inicial'; d.setAttribute('role', 'status'); d.innerHTML = 'Sigues con la contraseña inicial. Cámbiala en Mi cuenta: ' + 'así nadie más puede entrar con tu usuario.'; var main = document.querySelector('.md-main'); if (main) main.parentNode.insertBefore(d, main); else document.body.insertBefore(d, document.body.firstChild); }) .catch(function () {}); } function arrancar() { cuentaPendientes(); avisoContrasena(); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', arrancar); else arrancar(); })();