MOe Suivi
Connectez-vous pour accéder à vos projets
Données chiffrées · Accès sécurisé HTTPS
`;
document.body.appendChild(overlay);
// Entrée clavier
overlay.querySelectorAll('input').forEach(inp => {
inp.addEventListener('keydown', e => { if (e.key === 'Enter') doLogin(); });
});
}
overlay.style.display = 'flex';
setTimeout(() => document.getElementById('login-user')?.focus(), 100);
}
function hideLoginScreen() {
const el = document.getElementById('login-overlay');
if (el) el.style.display = 'none';
const sub = document.getElementById('sidebar-username');
if (sub && _syncUser) sub.textContent = '👤 ' + _syncUser;
}
function showLoginError(msg) {
const el = document.getElementById('login-error');
if (el) { el.textContent = msg; el.style.display = 'block'; }
const btn = document.getElementById('login-btn');
if (btn) { btn.textContent = 'Se connecter →'; btn.disabled = false; }
}
async function doLogin() {
const user = document.getElementById('login-user')?.value?.trim();
const pass = document.getElementById('login-pass')?.value;
const btn = document.getElementById('login-btn');
const errEl = document.getElementById('login-error');
if (errEl) errEl.style.display = 'none';
if (!user || !pass) { showLoginError('Identifiant et mot de passe requis'); return; }
if (btn) { btn.textContent = 'Connexion…'; btn.disabled = true; }
await syncLogin(user, pass);
}
// ── Sync manuelle (bouton) ────────────────────────────────────────────────
async function manualSync() {
if (!_syncEnabled) { showLoginScreen(); return; }
showSyncStatus('pending');
await syncPushToServer();
await syncPullFromServer();
}
// ── Init au chargement ────────────────────────────────────────────────────
function renderCurrentPage() {
// Re-render la page active après un pull serveur
const pages = ['dashboard','crm','ca','contrat-missions','contrat-doc','ao-suivi','chantier-taches','chantier-budget'];
const active = pages.find(p => {
const el = document.getElementById('page-'+p);
return el && el.style.display !== 'none' && el.offsetParent !== null;
});
if (active) showPage(active);
}
// Démarrer la vérification de session après chargement complet
window.addEventListener('load', () => {
syncCheckSession();
});