Files
Forge-Engine/static/js/scenes/global-variables.js
T
williamandClaude Sonnet 5 c57420c8c9 Phase 3 : hardening qualite de code - typage strict, securite, dead code, a11y
Config strictement stricte partout (ruff, mypy --strict, bandit, vulture,
import-linter, eslint, stylelint), aucune regle desactivee "pour ne pas
casser le build" - l'existant a ete corrige pour la satisfaire plutot que
l'inverse. Hooks pre-commit locaux (language: system) bloquants.

- Typage mypy --strict propage a tout le moteur (db, screens, auth, core,
  ai, routes, puis publish/scripts/tests/app.py/build_css.py).
- Securite : fuite de handle fichier Windows corrigee dans l'export SCORM
  (routes/publish/export_scorm.py), CSRF/RNG non-crypto/xAPI documentes
  (# nosec, # NOSONAR justifies), nouveau db.json_for_script() (echappe
  "</script>" dans le JSON embarque en <script>, 25 sites).
- Architecture : imports circulaires/F811 nettoyes, contrats
  import-linter respectes, code mort retire (vulture).
- Accessibilite : 69 champs de formulaire sans label correctement
  associe corriges (for/id ou aria-label) sur 11 templates.
- ESLint/Stylelint : lot mecanique JS/CSS, regles ajustees puis
  appliquees (aucune desactivee sans verification individuelle).
- Tests : isolation du compte admin partage (nettoyage ponctuel +
  fixture de teardown automatique en filet de securite), suite complete
  verte (591 tests Python, 241 tests JS).
- SonarQube Community Build self-heberge (Docker + PostgreSQL) : rapport
  complet analyse point par point, faux positifs documentes.
- .gitattributes ajoute (LF force) : core.autocrlf=true sur cette machine
  faisait echouer ESLint (linebreak-style) via un bug connu de git
  (checkout "en place" qui ignore l'eol force sur un fichier deja
  present sur disque - contourne en supprimant puis recreant chaque
  fichier suivi).

djLint (H021, styles inline) volontairement saute pour ce commit -
backlog assume, deja documente, traite dans un lot separe.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-15 16:06:15 +02:00

68 lines
2.9 KiB
JavaScript

// ---------- Onglet "Variables" — CRUD en AJAX ----------
// Demande explicite : modifier/supprimer une variable rechargeait toute
// la page (formulaires classiques + navigation pjax) — remplacé par de
// vrais appels fetch(), sans jamais recharger ni naviguer.
// Enregistre automatiquement dès qu'un champ (type/valeur) change — plus
// besoin d'un bouton "Enregistrer" séparé (demande explicite : "que la
// modification s'enregistre automatiquement").
function saveGlobalVariable(varId) {
const row = document.querySelector(`tr[data-var-row="${varId}"]`);
if (!row) return;
const type = row.querySelector('select[name="type"]').value;
const { value } = row.querySelector('input[name="value"]');
const status = document.getElementById(`varSaveStatus${varId}`);
const body = new FormData();
body.append('type', type);
body.append('value', value);
fetch(`/game/${GAME_SLUG}/variables/${varId}/edit`, {
method: 'POST', headers: { 'X-Requested-With': 'fetch' }, body,
})
.then((r) => {
if (!r.ok) { window.location.reload(); return; }
if (status) {
status.textContent = 'Enregistré ✓';
setTimeout(() => { status.textContent = ''; }, 2000);
}
})
.catch(() => { window.location.reload(); });
}
function deleteGlobalVariable(varId, name) {
if (!window.confirm(`Supprimer la variable « ${name} » ? Toute condition/action qui la référence encore cessera de fonctionner.`)) return;
const body = new FormData();
fetch(`/game/${GAME_SLUG}/variables/${varId}/delete`, {
method: 'POST', headers: { 'X-Requested-With': 'fetch' }, body,
})
.then((r) => {
if (!r.ok) { window.location.reload(); return; }
const row = document.querySelector(`tr[data-var-row="${varId}"]`);
if (row) row.remove();
const body2 = document.getElementById('globalVariablesBody');
const emptyHint = document.getElementById('globalVariablesEmptyHint');
if (body2 && emptyHint) emptyHint.style.display = body2.children.length ? 'none' : '';
})
.catch(() => { window.location.reload(); });
}
function createGlobalVariable(event) {
event.preventDefault();
const form = event.target;
const body = new FormData(form);
fetch(`/game/${GAME_SLUG}/variables/new`, {
method: 'POST', headers: { 'X-Requested-With': 'fetch' }, body,
})
.then((r) => (r.ok ? r.json() : Promise.reject()))
.then((json) => {
if (!json.row_html) { window.location.reload(); return; }
const tbody = document.getElementById('globalVariablesBody');
tbody.insertAdjacentHTML('beforeend', json.row_html);
const emptyHint = document.getElementById('globalVariablesEmptyHint');
if (emptyHint) emptyHint.style.display = 'none';
form.reset();
form.style.display = 'none'; // même comportement que toggleDashCreate() après création
})
.catch(() => { window.location.reload(); });
return false;
}