Files
ASPIC/backoffice.js
T

60 lines
2.7 KiB
JavaScript

/* ASPIC — backoffice.js (11 septembre 2026)
Mécanique commune à toutes les pages du BackOffice : menu de gauche, pied
de page (logo + version), et la règle de navigation par Échap voulue par
Jean-Marc — "chaque application intégrée au BO doit, lorsqu'on en sort,
rester dans le BO ; un simple Échap, quand aucune application n'est
ouverte, permet de sortir du BO". Concrètement : chaque page BO appelle
initBackoffice() avec sa propre cible d'Échap — 'ecran_fond.html' pour
backoffice.html elle-même (l'écran de menu, "aucune application ouverte"),
'backoffice.html' pour toutes les autres (revenir au menu, jamais sortir
directement vers la CRM). */
const BO_MENU_ITEMS = [
{ href: 'bo_collaborateurs.html', label: 'Collaborateurs' },
{ href: 'bo_competences.html', label: 'Compétences' },
{ href: 'bo_espaces.html', label: 'Espaces disque' },
{ href: 'bo_cout_ia.html', label: 'Coût IA' },
];
function initBackoffice(options) {
const page = (window.location.pathname.split('/').pop()) || 'backoffice.html';
const cibleEchap = options && options.cibleEchap ? options.cibleEchap : 'backoffice.html';
const menu = document.getElementById('bo-menu');
if (menu) {
const titre = document.createElement('div');
titre.className = 'titre-bo';
titre.textContent = 'BackOffice ASPIC';
menu.appendChild(titre);
BO_MENU_ITEMS.forEach(function (item) {
const lien = document.createElement('a');
lien.href = item.href;
lien.textContent = item.label;
if (item.href === page) lien.classList.add('actif');
menu.appendChild(lien);
});
}
const pied = document.getElementById('bo-pied');
if (pied) {
pied.innerHTML =
'<img src="mevelia-icone.png" alt="Mévélia Solutions">' +
'<span><span class="A">A</span><span class="rest">SPIC</span></span>' +
'<span id="bo-version"></span>';
fetch('version.php').then(function (r) { return r.json(); }).then(function (data) {
document.getElementById('bo-version').textContent = data.version || '';
}).catch(function () { /* pied de page non bloquant, jamais d'erreur affichée pour ça */ });
}
document.addEventListener('keydown', function (e) {
if (e.key !== 'Escape') return;
// Une application ouverte sur la page (ex. une discussion, un panneau
// d'édition) peut se réserver Échap elle-même en appelant
// e.stopPropagation() sur son propre écouteur, posé avant celui-ci —
// ce gestionnaire ne réagit donc que si personne d'autre n'a intercepté
// la touche : c'est la traduction concrète de "quand aucune application
// n'est ouverte".
window.location.href = cibleEchap;
});
}