feat(i18n): pathology editor header navbar + full FR/EN translation
Header with brand link + FR/EN segmented toggle reading/writing osteo:locale localStorage key. 76 translation keys covering all UI strings. View state tracked for re-render on locale switch. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
1673302b09
commit
f2c9c9bdb7
1 file changed
+388
-79
+388
-79
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<html lang="fr" id="pe-html">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@@ -27,11 +27,66 @@
|
||||
font-family: var(--font-sans);
|
||||
color: var(--color-ink);
|
||||
background: var(--color-bg);
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pe-header {
|
||||
padding: 12px 24px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-shrink: 0;
|
||||
background: var(--color-bg);
|
||||
}
|
||||
.pe-header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.pe-header-brand {
|
||||
font-family: var(--font-serif);
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-ink);
|
||||
text-decoration: none;
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
.pe-header-brand:hover { color: var(--color-accent); }
|
||||
.pe-header-tagline {
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-ink-muted);
|
||||
margin-left: 12px;
|
||||
}
|
||||
.pe-lang-toggle {
|
||||
display: flex;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.pe-lang-toggle button {
|
||||
padding: 4px 12px;
|
||||
font-size: 13px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
color: var(--color-ink);
|
||||
font-family: inherit;
|
||||
width: auto;
|
||||
margin: 0;
|
||||
}
|
||||
.pe-lang-toggle button:hover { background: var(--color-surface-strong); }
|
||||
.pe-lang-toggle button.active {
|
||||
background: var(--color-accent);
|
||||
color: white;
|
||||
}
|
||||
.pe-lang-toggle button.active:hover { background: var(--color-accent-strong); }
|
||||
|
||||
.pe-root {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@@ -393,13 +448,14 @@
|
||||
.pe-export-bar button { margin-bottom: 0; }
|
||||
|
||||
@media (max-width: 899px) {
|
||||
.pe-header { display: none; }
|
||||
.pe-root { display: none; }
|
||||
body::after {
|
||||
content: 'Veuillez utiliser un écran plus large (min. 900px) pour cet outil.';
|
||||
content: attr(data-small-screen-msg);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
flex: 1;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
@@ -460,6 +516,17 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header class="pe-header" id="pe-header">
|
||||
<div class="pe-header-left">
|
||||
<a href="/" class="pe-header-brand">Zoosteo</a>
|
||||
<span class="pe-header-tagline" id="pe-header-tagline"></span>
|
||||
</div>
|
||||
<div class="pe-lang-toggle" id="pe-lang-toggle">
|
||||
<button data-lang="fr">FR</button>
|
||||
<button data-lang="en">EN</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="pe-root">
|
||||
<div class="pe-canvas">
|
||||
<div class="pe-canvas-inner" id="pe-canvas-inner"></div>
|
||||
@@ -468,14 +535,14 @@
|
||||
|
||||
<div class="pe-sidebar">
|
||||
<header>
|
||||
<h1>Éditeur de pathologies<span id="pe-dirty" class="pe-dirty-dot" style="display:none"></span></h1>
|
||||
<div class="sub">Sélectionnez une zone sur le SVG pour éditer ses pathologies</div>
|
||||
<h1 id="pe-sidebar-title"><span id="pe-dirty" class="pe-dirty-dot" style="display:none"></span></h1>
|
||||
<div class="sub" id="pe-sidebar-subtitle"></div>
|
||||
</header>
|
||||
|
||||
<div class="pe-sidebar-content" id="pe-sidebar-content"></div>
|
||||
|
||||
<div class="pe-export-bar" id="pe-export-bar" style="display:none">
|
||||
<button class="primary" id="pe-export-btn">Télécharger JSON</button>
|
||||
<button class="primary" id="pe-export-btn"></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -484,14 +551,246 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ── Translations ──
|
||||
|
||||
var TRANSLATIONS = {
|
||||
fr: {
|
||||
'tagline': 'Outil de pathologies',
|
||||
'title': 'Éditeur de pathologies',
|
||||
'subtitle': 'Sélectionnez une zone sur le SVG pour éditer ses pathologies',
|
||||
'export_json': 'Télécharger JSON',
|
||||
'source': 'Source',
|
||||
'tab_prewired': 'Liste pré-câblée',
|
||||
'tab_upload': 'Upload manuel',
|
||||
'species': 'Espèce',
|
||||
'view': 'Vue',
|
||||
'load': 'Charger',
|
||||
'species_equine': 'Cheval',
|
||||
'view_full_body': 'Corps complet',
|
||||
'view_head_detail': 'Tête (détail)',
|
||||
'file_svg': 'Fichier SVG',
|
||||
'file_json': 'Fichier JSON',
|
||||
'both_files_required': 'Les deux fichiers (SVG et JSON) sont obligatoires.',
|
||||
'file_svg_too_large': 'Fichier SVG trop volumineux (max 10 Mo).',
|
||||
'file_json_too_large': 'Fichier JSON trop volumineux (max 10 Mo).',
|
||||
'error_read_svg': 'Erreur de lecture du fichier SVG.',
|
||||
'error_read_json': 'Erreur de lecture du fichier JSON.',
|
||||
'error_load_files': 'Impossible de charger les fichiers : ',
|
||||
'error_invalid_json': 'Le fichier JSON est invalide : ',
|
||||
'error_missing_schema_version': 'Structure JSON invalide : champ "schema_version" manquant',
|
||||
'error_missing_species': 'Structure JSON invalide : champ "species" manquant',
|
||||
'error_missing_zones': 'Structure JSON invalide : champ "zones" manquant',
|
||||
'error_no_svg_element': 'Fichier SVG invalide : aucun élément <svg> trouvé.',
|
||||
'error_no_annotated': 'Aucun élément annoté (data-anno-*) trouvé dans ce SVG.',
|
||||
'change_source': '← Changer de source',
|
||||
'selected_zone': 'Zone sélectionnée',
|
||||
'click_zone_hint': 'Cliquez sur une zone du SVG pour éditer ses pathologies.',
|
||||
'json_summary': 'Résumé JSON',
|
||||
'stat_zones': ' zones · ',
|
||||
'stat_nodes': ' nœuds · ',
|
||||
'stat_leaves': ' feuilles',
|
||||
'confirm_unsaved': 'Des modifications non enregistrées seront perdues. Continuer ?',
|
||||
'back': '← Retour',
|
||||
'nav_zone': 'Zone de navigation',
|
||||
'nav_zone_opens': 'Cette zone ouvre un SVG de détail (',
|
||||
'nav_zone_no_edit': '). Elle ne contient pas de pathologies éditables ici.',
|
||||
'nav_zone_load_detail': 'Chargez le SVG de détail correspondant pour éditer ses zones.',
|
||||
'unknown_zone': 'Zone inconnue',
|
||||
'no_matching_zone': 'Aucune zone correspondante dans le JSON pour : ',
|
||||
'create_zone': 'Créer cette zone',
|
||||
'vet_referral_badge': 'réf. vét.',
|
||||
'stat_cat': ' cat.',
|
||||
'stat_nodes_short': ' nœuds',
|
||||
'stat_leaves_short': ' feuilles',
|
||||
'add_category': '+ Ajouter une catégorie',
|
||||
'add_child_title': 'Ajouter un enfant',
|
||||
'edit_title': 'Modifier',
|
||||
'delete_title': 'Supprimer',
|
||||
'delete_confirm_prefix': 'Supprimer « ',
|
||||
'delete_confirm_suffix': ' »',
|
||||
'delete_confirm_children': ' et ses ',
|
||||
'delete_confirm_children_suffix': ' enfants',
|
||||
'name_fr_label': 'Nom FR *',
|
||||
'name_fr_placeholder': 'Nom en français',
|
||||
'name_en_label': 'Nom EN *',
|
||||
'name_en_placeholder': 'English name',
|
||||
'desc_fr_label': 'Description FR',
|
||||
'desc_fr_placeholder': 'Description en français (optionnel)',
|
||||
'desc_en_label': 'Description EN',
|
||||
'desc_en_placeholder': 'English description (optional)',
|
||||
'vet_referral_checkbox': ' Nécessite un renvoi vétérinaire',
|
||||
'sources_label': 'Sources',
|
||||
'add_source': '+ Ajouter une source',
|
||||
'citation_placeholder': 'Citation',
|
||||
'url_placeholder': 'URL (optionnel)',
|
||||
'save': 'Enregistrer',
|
||||
'create': 'Créer',
|
||||
'cancel': 'Annuler',
|
||||
'name_required': 'Au moins un nom (FR ou EN) est obligatoire.',
|
||||
'welcome_title': 'Éditeur de pathologies',
|
||||
'welcome_p1': 'Choisissez une source dans la barre latérale pour commencer. Sélectionnez un SVG et son JSON de pathologies associé.',
|
||||
'welcome_p2': 'Cliquez ensuite sur une zone anatomique pour éditer son arbre de pathologies.',
|
||||
'small_screen': 'Veuillez utiliser un écran plus large (min. 900px) pour cet outil.'
|
||||
},
|
||||
en: {
|
||||
'tagline': 'Pathology tool',
|
||||
'title': 'Pathology Editor',
|
||||
'subtitle': 'Select a zone on the SVG to edit its pathologies',
|
||||
'export_json': 'Download JSON',
|
||||
'source': 'Source',
|
||||
'tab_prewired': 'Pre-wired list',
|
||||
'tab_upload': 'Manual upload',
|
||||
'species': 'Species',
|
||||
'view': 'View',
|
||||
'load': 'Load',
|
||||
'species_equine': 'Horse',
|
||||
'view_full_body': 'Full body',
|
||||
'view_head_detail': 'Head (detail)',
|
||||
'file_svg': 'SVG file',
|
||||
'file_json': 'JSON file',
|
||||
'both_files_required': 'Both files (SVG and JSON) are required.',
|
||||
'file_svg_too_large': 'SVG file too large (max 10 MB).',
|
||||
'file_json_too_large': 'JSON file too large (max 10 MB).',
|
||||
'error_read_svg': 'Error reading SVG file.',
|
||||
'error_read_json': 'Error reading JSON file.',
|
||||
'error_load_files': 'Unable to load files: ',
|
||||
'error_invalid_json': 'Invalid JSON file: ',
|
||||
'error_missing_schema_version': 'Invalid JSON structure: missing "schema_version" field',
|
||||
'error_missing_species': 'Invalid JSON structure: missing "species" field',
|
||||
'error_missing_zones': 'Invalid JSON structure: missing "zones" field',
|
||||
'error_no_svg_element': 'Invalid SVG file: no <svg> element found.',
|
||||
'error_no_annotated': 'No annotated elements (data-anno-*) found in this SVG.',
|
||||
'change_source': '← Change source',
|
||||
'selected_zone': 'Selected zone',
|
||||
'click_zone_hint': 'Click a zone on the SVG to edit its pathologies.',
|
||||
'json_summary': 'JSON Summary',
|
||||
'stat_zones': ' zones · ',
|
||||
'stat_nodes': ' nodes · ',
|
||||
'stat_leaves': ' leaves',
|
||||
'confirm_unsaved': 'Unsaved changes will be lost. Continue?',
|
||||
'back': '← Back',
|
||||
'nav_zone': 'Navigation zone',
|
||||
'nav_zone_opens': 'This zone opens a detail SVG (',
|
||||
'nav_zone_no_edit': '). It does not contain editable pathologies here.',
|
||||
'nav_zone_load_detail': 'Load the corresponding detail SVG to edit its zones.',
|
||||
'unknown_zone': 'Unknown zone',
|
||||
'no_matching_zone': 'No matching zone in the JSON for: ',
|
||||
'create_zone': 'Create this zone',
|
||||
'vet_referral_badge': 'vet ref.',
|
||||
'stat_cat': ' cat.',
|
||||
'stat_nodes_short': ' nodes',
|
||||
'stat_leaves_short': ' leaves',
|
||||
'add_category': '+ Add a category',
|
||||
'add_child_title': 'Add a child',
|
||||
'edit_title': 'Edit',
|
||||
'delete_title': 'Delete',
|
||||
'delete_confirm_prefix': 'Delete "',
|
||||
'delete_confirm_suffix': '"',
|
||||
'delete_confirm_children': ' and its ',
|
||||
'delete_confirm_children_suffix': ' children',
|
||||
'name_fr_label': 'Name FR *',
|
||||
'name_fr_placeholder': 'French name',
|
||||
'name_en_label': 'Name EN *',
|
||||
'name_en_placeholder': 'English name',
|
||||
'desc_fr_label': 'Description FR',
|
||||
'desc_fr_placeholder': 'French description (optional)',
|
||||
'desc_en_label': 'Description EN',
|
||||
'desc_en_placeholder': 'English description (optional)',
|
||||
'vet_referral_checkbox': ' Requires veterinary referral',
|
||||
'sources_label': 'Sources',
|
||||
'add_source': '+ Add a source',
|
||||
'citation_placeholder': 'Citation',
|
||||
'url_placeholder': 'URL (optional)',
|
||||
'save': 'Save',
|
||||
'create': 'Create',
|
||||
'cancel': 'Cancel',
|
||||
'name_required': 'At least one name (FR or EN) is required.',
|
||||
'welcome_title': 'Pathology Editor',
|
||||
'welcome_p1': 'Choose a source in the sidebar to get started. Select an SVG and its associated pathology JSON.',
|
||||
'welcome_p2': 'Then click an anatomical zone to edit its pathology tree.',
|
||||
'small_screen': 'Please use a wider screen (min. 900px) for this tool.'
|
||||
}
|
||||
};
|
||||
|
||||
var currentLocale = localStorage.getItem('osteo:locale') || 'fr';
|
||||
|
||||
function t(key) {
|
||||
return (TRANSLATIONS[currentLocale] || TRANSLATIONS.fr)[key] || key;
|
||||
}
|
||||
|
||||
// ── Locale UI ──
|
||||
|
||||
var langToggle = document.getElementById('pe-lang-toggle');
|
||||
var taglineEl = document.getElementById('pe-header-tagline');
|
||||
|
||||
function updateLangToggle() {
|
||||
var buttons = langToggle.querySelectorAll('button');
|
||||
for (var i = 0; i < buttons.length; i++) {
|
||||
if (buttons[i].getAttribute('data-lang') === currentLocale) {
|
||||
buttons[i].classList.add('active');
|
||||
} else {
|
||||
buttons[i].classList.remove('active');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateStaticTexts() {
|
||||
document.documentElement.lang = currentLocale;
|
||||
document.title = 'Zoosteo — ' + t('title');
|
||||
taglineEl.textContent = t('tagline');
|
||||
document.body.setAttribute('data-small-screen-msg', t('small_screen'));
|
||||
|
||||
var titleEl = document.getElementById('pe-sidebar-title');
|
||||
if (titleEl) {
|
||||
var dirtySpanRef = document.getElementById('pe-dirty');
|
||||
titleEl.textContent = t('title');
|
||||
if (dirtySpanRef) titleEl.appendChild(dirtySpanRef);
|
||||
}
|
||||
var subtitleEl = document.getElementById('pe-sidebar-subtitle');
|
||||
if (subtitleEl) subtitleEl.textContent = t('subtitle');
|
||||
|
||||
var expBtn = document.getElementById('pe-export-btn');
|
||||
if (expBtn) expBtn.textContent = t('export_json');
|
||||
}
|
||||
|
||||
// Track current view for re-render on locale switch
|
||||
var currentView = 'welcome'; // 'welcome' | 'source-picker' | 'editor' | 'zone-editor'
|
||||
var currentZone = null;
|
||||
|
||||
langToggle.addEventListener('click', function (e) {
|
||||
var btn = e.target.closest('button[data-lang]');
|
||||
if (!btn) return;
|
||||
var lang = btn.getAttribute('data-lang');
|
||||
if (lang === currentLocale) return;
|
||||
currentLocale = lang;
|
||||
localStorage.setItem('osteo:locale', currentLocale);
|
||||
updateLangToggle();
|
||||
updateStaticTexts();
|
||||
rerenderCurrentView();
|
||||
});
|
||||
|
||||
function rerenderCurrentView() {
|
||||
if (currentView === 'source-picker') {
|
||||
showSourcePicker();
|
||||
} else if (currentView === 'editor') {
|
||||
showEditorSidebar();
|
||||
} else if (currentView === 'zone-editor' && currentZone) {
|
||||
showZoneEditor(currentZone);
|
||||
} else if (currentView === 'welcome') {
|
||||
showSourcePicker();
|
||||
}
|
||||
}
|
||||
|
||||
// ── Species config (labels resolved via t()) ──
|
||||
|
||||
var SPECIES_CONFIG = [
|
||||
{
|
||||
id: 'equine',
|
||||
label: 'Cheval',
|
||||
labelKey: 'species_equine',
|
||||
jsonPath: '/species/equine/pathologies.json',
|
||||
views: [
|
||||
{ label: 'Corps complet', svgPath: '/species/equine/Horse.svg' },
|
||||
{ label: 'Tête (détail)', svgPath: '/species/equine/Horse_head.svg' },
|
||||
{ labelKey: 'view_full_body', svgPath: '/species/equine/Horse.svg' },
|
||||
{ labelKey: 'view_head_detail', svgPath: '/species/equine/Horse_head.svg' },
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -509,6 +808,10 @@
|
||||
var exportBtn = document.getElementById('pe-export-btn');
|
||||
var dirtyDot = document.getElementById('pe-dirty');
|
||||
|
||||
// Initialize locale UI
|
||||
updateLangToggle();
|
||||
updateStaticTexts();
|
||||
|
||||
setupZoom();
|
||||
showSourcePicker();
|
||||
exportBtn.addEventListener('click', downloadJson);
|
||||
@@ -653,6 +956,7 @@
|
||||
// ── Source picker ──
|
||||
|
||||
function showSourcePicker() {
|
||||
currentView = 'source-picker';
|
||||
exportBar.style.display = 'none';
|
||||
selectedZoneId = null;
|
||||
clearChildren(sidebar);
|
||||
@@ -660,14 +964,14 @@
|
||||
var section = el('div');
|
||||
section.className = 'pe-section';
|
||||
|
||||
var h3 = el('h3', 'Source');
|
||||
var h3 = el('h3', t('source'));
|
||||
section.appendChild(h3);
|
||||
|
||||
var modeBar = el('div');
|
||||
modeBar.className = 'pe-picker-mode';
|
||||
var btnPre = el('button', 'Liste pré-câblée');
|
||||
var btnPre = el('button', t('tab_prewired'));
|
||||
btnPre.className = 'active';
|
||||
var btnUp = el('button', 'Upload manuel');
|
||||
var btnUp = el('button', t('tab_upload'));
|
||||
modeBar.append(btnPre, btnUp);
|
||||
section.appendChild(modeBar);
|
||||
|
||||
@@ -686,22 +990,22 @@
|
||||
});
|
||||
|
||||
showPrewiredPicker(content);
|
||||
showWelcomeScreen();
|
||||
if (!svgRoot) showWelcomeScreen();
|
||||
}
|
||||
|
||||
function showPrewiredPicker(container) {
|
||||
clearChildren(container);
|
||||
|
||||
var lbl1 = el('label', 'Espèce');
|
||||
var lbl1 = el('label', t('species'));
|
||||
var speciesSel = el('select');
|
||||
speciesSel.id = 'pe-species-select';
|
||||
SPECIES_CONFIG.forEach(function (sp) {
|
||||
var opt = el('option', sp.label);
|
||||
var opt = el('option', t(sp.labelKey));
|
||||
opt.value = sp.id;
|
||||
speciesSel.appendChild(opt);
|
||||
});
|
||||
|
||||
var lbl2 = el('label', 'Vue');
|
||||
var lbl2 = el('label', t('view'));
|
||||
var viewSel = el('select');
|
||||
viewSel.id = 'pe-view-select';
|
||||
|
||||
@@ -710,7 +1014,7 @@
|
||||
var sp = SPECIES_CONFIG.find(function (s) { return s.id === speciesSel.value; });
|
||||
if (!sp) return;
|
||||
sp.views.forEach(function (v, i) {
|
||||
var opt = el('option', v.label);
|
||||
var opt = el('option', t(v.labelKey));
|
||||
opt.value = i;
|
||||
viewSel.appendChild(opt);
|
||||
});
|
||||
@@ -718,7 +1022,7 @@
|
||||
populateViews();
|
||||
speciesSel.addEventListener('change', populateViews);
|
||||
|
||||
var loadBtn = el('button', 'Charger');
|
||||
var loadBtn = el('button', t('load'));
|
||||
loadBtn.className = 'primary';
|
||||
loadBtn.style.marginTop = '8px';
|
||||
loadBtn.addEventListener('click', function () {
|
||||
@@ -736,16 +1040,16 @@
|
||||
function showUploadPicker(container) {
|
||||
clearChildren(container);
|
||||
|
||||
var lbl1 = el('label', 'Fichier SVG');
|
||||
var lbl1 = el('label', t('file_svg'));
|
||||
var svgInput = el('input');
|
||||
svgInput.type = 'file'; svgInput.accept = '.svg';
|
||||
var lbl2 = el('label', 'Fichier JSON');
|
||||
var lbl2 = el('label', t('file_json'));
|
||||
var jsonInput = el('input');
|
||||
jsonInput.type = 'file'; jsonInput.accept = '.json';
|
||||
var warning = el('div');
|
||||
warning.className = 'pe-upload-warning';
|
||||
warning.style.display = 'none';
|
||||
var loadBtn = el('button', 'Charger');
|
||||
var loadBtn = el('button', t('load'));
|
||||
loadBtn.className = 'primary';
|
||||
loadBtn.style.marginTop = '8px';
|
||||
loadBtn.disabled = true;
|
||||
@@ -755,7 +1059,7 @@
|
||||
var hasJson = jsonInput.files && jsonInput.files.length > 0;
|
||||
loadBtn.disabled = !(hasSvg && hasJson);
|
||||
if ((hasSvg && !hasJson) || (!hasSvg && hasJson)) {
|
||||
warning.textContent = 'Les deux fichiers (SVG et JSON) sont obligatoires.';
|
||||
warning.textContent = t('both_files_required');
|
||||
warning.style.display = 'block';
|
||||
} else {
|
||||
warning.style.display = 'none';
|
||||
@@ -767,15 +1071,15 @@
|
||||
loadBtn.addEventListener('click', function () {
|
||||
var sf = svgInput.files[0], jf = jsonInput.files[0];
|
||||
if (!sf || !jf) return;
|
||||
if (sf.size > 10485760) { showError('Fichier SVG trop volumineux (max 10 Mo).'); return; }
|
||||
if (jf.size > 10485760) { showError('Fichier JSON trop volumineux (max 10 Mo).'); return; }
|
||||
if (sf.size > 10485760) { showError(t('file_svg_too_large')); return; }
|
||||
if (jf.size > 10485760) { showError(t('file_json_too_large')); return; }
|
||||
currentSpeciesId = 'custom';
|
||||
var sr = new FileReader();
|
||||
sr.onerror = function () { showError('Erreur de lecture du fichier SVG.'); };
|
||||
sr.onerror = function () { showError(t('error_read_svg')); };
|
||||
sr.onload = function (e) {
|
||||
var svgText = e.target.result;
|
||||
var jr = new FileReader();
|
||||
jr.onerror = function () { showError('Erreur de lecture du fichier JSON.'); };
|
||||
jr.onerror = function () { showError(t('error_read_json')); };
|
||||
jr.onload = function (e2) { processSource(svgText, e2.target.result); };
|
||||
jr.readAsText(jf, 'UTF-8');
|
||||
};
|
||||
@@ -798,25 +1102,25 @@
|
||||
]).then(function (res) {
|
||||
processSource(res[0], res[1]);
|
||||
}).catch(function (err) {
|
||||
showError('Impossible de charger les fichiers : ' + err.message);
|
||||
showError(t('error_load_files') + err.message);
|
||||
});
|
||||
}
|
||||
|
||||
function processSource(svgText, jsonText) {
|
||||
var parsed;
|
||||
try { parsed = JSON.parse(jsonText); }
|
||||
catch (err) { showError('Le fichier JSON est invalide : ' + err.message); return; }
|
||||
catch (err) { showError(t('error_invalid_json') + err.message); return; }
|
||||
|
||||
if (!parsed.schema_version) { showError('Structure JSON invalide : champ "schema_version" manquant'); return; }
|
||||
if (!parsed.species) { showError('Structure JSON invalide : champ "species" manquant'); return; }
|
||||
if (!parsed.zones) { showError('Structure JSON invalide : champ "zones" manquant'); return; }
|
||||
if (!parsed.schema_version) { showError(t('error_missing_schema_version')); return; }
|
||||
if (!parsed.species) { showError(t('error_missing_species')); return; }
|
||||
if (!parsed.zones) { showError(t('error_missing_zones')); return; }
|
||||
|
||||
jsonData = parsed;
|
||||
|
||||
var parser = new DOMParser();
|
||||
var doc = parser.parseFromString(svgText, 'image/svg+xml');
|
||||
var svg = doc.querySelector('svg');
|
||||
if (!svg) { showError('Fichier SVG invalide : aucun élément <svg> trouvé.'); return; }
|
||||
if (!svg) { showError(t('error_no_svg_element')); return; }
|
||||
|
||||
clearChildren(canvasInner);
|
||||
var imported = document.importNode(svg, true);
|
||||
@@ -839,7 +1143,7 @@
|
||||
|
||||
var annotated = svgRoot.querySelectorAll('[data-anno-id]');
|
||||
if (annotated.length === 0) {
|
||||
showError('Aucun élément annoté (data-anno-*) trouvé dans ce SVG.');
|
||||
showError(t('error_no_annotated'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -907,17 +1211,19 @@
|
||||
// ── Editor sidebar (default state) ──
|
||||
|
||||
function showEditorSidebar() {
|
||||
currentView = 'editor';
|
||||
currentZone = null;
|
||||
clearChildren(sidebar);
|
||||
|
||||
var back = el('span', '← Changer de source');
|
||||
var back = el('span', t('change_source'));
|
||||
back.className = 'pe-change-source';
|
||||
back.addEventListener('click', confirmAndReset);
|
||||
sidebar.appendChild(back);
|
||||
|
||||
var section = el('div');
|
||||
section.className = 'pe-section';
|
||||
section.appendChild(el('h3', 'Zone sélectionnée'));
|
||||
var hint = el('p', 'Cliquez sur une zone du SVG pour éditer ses pathologies.');
|
||||
section.appendChild(el('h3', t('selected_zone')));
|
||||
var hint = el('p', t('click_zone_hint'));
|
||||
hint.style.cssText = 'font-size:13px;color:var(--color-ink-muted)';
|
||||
section.appendChild(hint);
|
||||
sidebar.appendChild(section);
|
||||
@@ -931,8 +1237,8 @@
|
||||
});
|
||||
var summary = el('div');
|
||||
summary.className = 'pe-section';
|
||||
summary.appendChild(el('h3', 'Résumé JSON'));
|
||||
var p = el('p', keys.length + ' zones · ' + tn + ' nœuds · ' + tl + ' feuilles');
|
||||
summary.appendChild(el('h3', t('json_summary')));
|
||||
var p = el('p', keys.length + t('stat_zones') + tn + t('stat_nodes') + tl + t('stat_leaves'));
|
||||
p.style.cssText = 'font-size:12px;color:var(--color-ink-muted)';
|
||||
summary.appendChild(p);
|
||||
sidebar.appendChild(summary);
|
||||
@@ -940,7 +1246,7 @@
|
||||
}
|
||||
|
||||
function confirmAndReset() {
|
||||
if (dirty && !confirm('Des modifications non enregistrées seront perdues. Continuer ?')) return;
|
||||
if (dirty && !confirm(t('confirm_unsaved'))) return;
|
||||
clearDirty();
|
||||
jsonData = null;
|
||||
svgRoot = null;
|
||||
@@ -953,23 +1259,23 @@
|
||||
|
||||
function showNavZoneMessage(detailId) {
|
||||
clearChildren(sidebar);
|
||||
var back = el('span', '← Retour');
|
||||
var back = el('span', t('back'));
|
||||
back.className = 'pe-change-source';
|
||||
back.addEventListener('click', function () { clearSelection(); });
|
||||
sidebar.appendChild(back);
|
||||
|
||||
var section = el('div');
|
||||
section.className = 'pe-section';
|
||||
section.appendChild(el('h3', 'Zone de navigation'));
|
||||
section.appendChild(el('h3', t('nav_zone')));
|
||||
var info = el('div');
|
||||
info.className = 'pe-info pe-info-nav';
|
||||
info.appendChild(document.createTextNode('Cette zone ouvre un SVG de détail ('));
|
||||
info.appendChild(document.createTextNode(t('nav_zone_opens')));
|
||||
var strong = el('strong', detailId);
|
||||
info.appendChild(strong);
|
||||
info.appendChild(document.createTextNode('). Elle ne contient pas de pathologies éditables ici.'));
|
||||
info.appendChild(document.createTextNode(t('nav_zone_no_edit')));
|
||||
info.appendChild(el('br'));
|
||||
info.appendChild(el('br'));
|
||||
info.appendChild(document.createTextNode('Chargez le SVG de détail correspondant pour éditer ses zones.'));
|
||||
info.appendChild(document.createTextNode(t('nav_zone_load_detail')));
|
||||
section.appendChild(info);
|
||||
sidebar.appendChild(section);
|
||||
}
|
||||
@@ -978,18 +1284,18 @@
|
||||
|
||||
function showCreateZonePrompt(nameFr, nameEn) {
|
||||
clearChildren(sidebar);
|
||||
var back = el('span', '← Retour');
|
||||
var back = el('span', t('back'));
|
||||
back.className = 'pe-change-source';
|
||||
back.addEventListener('click', function () { clearSelection(); });
|
||||
sidebar.appendChild(back);
|
||||
|
||||
var section = el('div');
|
||||
section.className = 'pe-section';
|
||||
section.appendChild(el('h3', 'Zone inconnue'));
|
||||
section.appendChild(el('h3', t('unknown_zone')));
|
||||
|
||||
var info = el('div');
|
||||
info.className = 'pe-info pe-info-create';
|
||||
info.appendChild(document.createTextNode('Aucune zone correspondante dans le JSON pour : '));
|
||||
info.appendChild(document.createTextNode(t('no_matching_zone')));
|
||||
info.appendChild(el('strong', nameFr));
|
||||
if (nameEn) {
|
||||
info.appendChild(document.createTextNode(' / '));
|
||||
@@ -997,7 +1303,7 @@
|
||||
}
|
||||
section.appendChild(info);
|
||||
|
||||
var btn = el('button', 'Créer cette zone');
|
||||
var btn = el('button', t('create_zone'));
|
||||
btn.className = 'primary';
|
||||
btn.addEventListener('click', function () {
|
||||
var existingIds = Object.keys(jsonData.zones);
|
||||
@@ -1015,9 +1321,11 @@
|
||||
// ── Zone editor ──
|
||||
|
||||
function showZoneEditor(zone) {
|
||||
currentView = 'zone-editor';
|
||||
currentZone = zone;
|
||||
clearChildren(sidebar);
|
||||
|
||||
var back = el('span', '← Retour');
|
||||
var back = el('span', t('back'));
|
||||
back.className = 'pe-change-source';
|
||||
back.addEventListener('click', function () { clearSelection(); });
|
||||
sidebar.appendChild(back);
|
||||
@@ -1036,11 +1344,11 @@
|
||||
var idBadge = el('span', zone.id);
|
||||
idBadge.className = 'pe-badge pe-badge-id';
|
||||
var nc = countNodes(zone.categories), nl = countLeaves(zone.categories);
|
||||
var catBadge = el('span', zone.categories.length + ' cat.');
|
||||
var catBadge = el('span', zone.categories.length + t('stat_cat'));
|
||||
catBadge.className = 'pe-badge pe-badge-stat';
|
||||
var nodeBadge = el('span', nc + ' nœuds');
|
||||
var nodeBadge = el('span', nc + t('stat_nodes_short'));
|
||||
nodeBadge.className = 'pe-badge pe-badge-stat';
|
||||
var leafBadge = el('span', nl + ' feuilles');
|
||||
var leafBadge = el('span', nl + t('stat_leaves_short'));
|
||||
leafBadge.className = 'pe-badge pe-badge-stat';
|
||||
stats.append(idBadge, catBadge, nodeBadge, leafBadge);
|
||||
header.appendChild(stats);
|
||||
@@ -1055,7 +1363,7 @@
|
||||
renderTree(zone, treeContainer);
|
||||
|
||||
// Add root category button
|
||||
var addCatBtn = el('button', '+ Ajouter une catégorie');
|
||||
var addCatBtn = el('button', t('add_category'));
|
||||
addCatBtn.className = 'secondary';
|
||||
addCatBtn.addEventListener('click', function () {
|
||||
showInlineForm(zone, null, zone.categories, treeContainer);
|
||||
@@ -1092,7 +1400,7 @@
|
||||
name.textContent = node.name_fr;
|
||||
if (node.requires_vet_referral) {
|
||||
name.textContent = node.name_fr + ' ';
|
||||
var vetBadge = el('span', 'réf. vét.');
|
||||
var vetBadge = el('span', t('vet_referral_badge'));
|
||||
vetBadge.className = 'pe-badge pe-badge-vet';
|
||||
name.appendChild(vetBadge);
|
||||
}
|
||||
@@ -1103,7 +1411,7 @@
|
||||
// Add child
|
||||
var addBtn = el('button', '+');
|
||||
addBtn.className = 'pe-tree-btn';
|
||||
addBtn.title = 'Ajouter un enfant';
|
||||
addBtn.title = t('add_child_title');
|
||||
addBtn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
if (!node.children) node.children = [];
|
||||
@@ -1114,7 +1422,7 @@
|
||||
// Edit
|
||||
var editBtn = el('button', '✎');
|
||||
editBtn.className = 'pe-tree-btn';
|
||||
editBtn.title = 'Modifier';
|
||||
editBtn.title = t('edit_title');
|
||||
editBtn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var treeContainer = document.getElementById('pe-tree');
|
||||
@@ -1124,12 +1432,12 @@
|
||||
// Delete
|
||||
var delBtn = el('button', '×');
|
||||
delBtn.className = 'pe-tree-btn pe-tree-btn-danger';
|
||||
delBtn.title = 'Supprimer';
|
||||
delBtn.title = t('delete_title');
|
||||
delBtn.addEventListener('click', function (e) {
|
||||
e.stopPropagation();
|
||||
var sub = countNodes(node.children || []);
|
||||
var msg = 'Supprimer « ' + node.name_fr + ' »';
|
||||
if (sub > 0) msg += ' et ses ' + sub + ' enfants';
|
||||
var msg = t('delete_confirm_prefix') + node.name_fr + t('delete_confirm_suffix');
|
||||
if (sub > 0) msg += t('delete_confirm_children') + sub + t('delete_confirm_children_suffix');
|
||||
msg += ' ?';
|
||||
if (!confirm(msg)) return;
|
||||
var idx = siblings.indexOf(node);
|
||||
@@ -1176,16 +1484,16 @@
|
||||
var nameRow = el('div');
|
||||
nameRow.className = 'pe-form-row';
|
||||
var frDiv = el('div');
|
||||
frDiv.appendChild(el('label', 'Nom FR *'));
|
||||
frDiv.appendChild(el('label', t('name_fr_label')));
|
||||
var frInput = el('input');
|
||||
frInput.value = isEdit ? existingNode.name_fr : '';
|
||||
frInput.placeholder = 'Nom en français';
|
||||
frInput.placeholder = t('name_fr_placeholder');
|
||||
frDiv.appendChild(frInput);
|
||||
var enDiv = el('div');
|
||||
enDiv.appendChild(el('label', 'Nom EN *'));
|
||||
enDiv.appendChild(el('label', t('name_en_label')));
|
||||
var enInput = el('input');
|
||||
enInput.value = isEdit ? existingNode.name_en : '';
|
||||
enInput.placeholder = 'English name';
|
||||
enInput.placeholder = t('name_en_placeholder');
|
||||
enDiv.appendChild(enInput);
|
||||
nameRow.append(frDiv, enDiv);
|
||||
form.appendChild(nameRow);
|
||||
@@ -1194,16 +1502,16 @@
|
||||
var descRow = el('div');
|
||||
descRow.className = 'pe-form-row';
|
||||
var dfrDiv = el('div');
|
||||
dfrDiv.appendChild(el('label', 'Description FR'));
|
||||
dfrDiv.appendChild(el('label', t('desc_fr_label')));
|
||||
var dfrInput = document.createElement('textarea');
|
||||
dfrInput.value = isEdit && existingNode.description_fr ? existingNode.description_fr : '';
|
||||
dfrInput.placeholder = 'Description en français (optionnel)';
|
||||
dfrInput.placeholder = t('desc_fr_placeholder');
|
||||
dfrDiv.appendChild(dfrInput);
|
||||
var denDiv = el('div');
|
||||
denDiv.appendChild(el('label', 'Description EN'));
|
||||
denDiv.appendChild(el('label', t('desc_en_label')));
|
||||
var denInput = document.createElement('textarea');
|
||||
denInput.value = isEdit && existingNode.description_en ? existingNode.description_en : '';
|
||||
denInput.placeholder = 'English description (optional)';
|
||||
denInput.placeholder = t('desc_en_placeholder');
|
||||
denDiv.appendChild(denInput);
|
||||
descRow.append(dfrDiv, denDiv);
|
||||
form.appendChild(descRow);
|
||||
@@ -1214,16 +1522,16 @@
|
||||
var vetCheck = el('input');
|
||||
vetCheck.type = 'checkbox';
|
||||
vetCheck.checked = isEdit && existingNode.requires_vet_referral;
|
||||
vetLabel.append(vetCheck, document.createTextNode(' Nécessite un renvoi vétérinaire'));
|
||||
vetLabel.append(vetCheck, document.createTextNode(t('vet_referral_checkbox')));
|
||||
form.appendChild(vetLabel);
|
||||
|
||||
// Sources
|
||||
var srcSection = el('div');
|
||||
srcSection.style.marginTop = '12px';
|
||||
srcSection.appendChild(el('label', 'Sources'));
|
||||
srcSection.appendChild(el('label', t('sources_label')));
|
||||
var srcContainer = el('div');
|
||||
srcSection.appendChild(srcContainer);
|
||||
var addSrcBtn = el('button', '+ Ajouter une source');
|
||||
var addSrcBtn = el('button', t('add_source'));
|
||||
addSrcBtn.className = 'secondary';
|
||||
addSrcBtn.style.marginTop = '4px';
|
||||
addSrcBtn.addEventListener('click', function () { addSourceRow(srcContainer); });
|
||||
@@ -1238,9 +1546,9 @@
|
||||
// Actions
|
||||
var actionsDiv = el('div');
|
||||
actionsDiv.className = 'pe-form-actions';
|
||||
var saveBtn = el('button', isEdit ? 'Enregistrer' : 'Créer');
|
||||
var saveBtn = el('button', isEdit ? t('save') : t('create'));
|
||||
saveBtn.className = 'primary';
|
||||
var cancelBtn = el('button', 'Annuler');
|
||||
var cancelBtn = el('button', t('cancel'));
|
||||
cancelBtn.className = 'secondary';
|
||||
cancelBtn.addEventListener('click', function () { form.remove(); });
|
||||
actionsDiv.append(saveBtn, cancelBtn);
|
||||
@@ -1258,7 +1566,7 @@
|
||||
// Save handler
|
||||
saveBtn.addEventListener('click', function () {
|
||||
var fr = frInput.value.trim(), en = enInput.value.trim();
|
||||
if (!fr && !en) { alert('Au moins un nom (FR ou EN) est obligatoire.'); return; }
|
||||
if (!fr && !en) { alert(t('name_required')); return; }
|
||||
if (!fr) fr = en;
|
||||
if (!en) en = fr;
|
||||
var dfr = dfrInput.value.trim(), den = denInput.value.trim();
|
||||
@@ -1316,11 +1624,11 @@
|
||||
fields.className = 'pe-source-fields';
|
||||
var citInput = el('input');
|
||||
citInput.className = 'pe-source-citation';
|
||||
citInput.placeholder = 'Citation';
|
||||
citInput.placeholder = t('citation_placeholder');
|
||||
if (existing) citInput.value = existing.citation || '';
|
||||
var urlInput = el('input');
|
||||
urlInput.className = 'pe-source-url';
|
||||
urlInput.placeholder = 'URL (optionnel)';
|
||||
urlInput.placeholder = t('url_placeholder');
|
||||
if (existing && existing.url) urlInput.value = existing.url;
|
||||
fields.append(citInput, urlInput);
|
||||
|
||||
@@ -1358,14 +1666,15 @@
|
||||
// ── Welcome screen ──
|
||||
|
||||
function showWelcomeScreen() {
|
||||
currentView = 'welcome';
|
||||
clearChildren(canvasInner);
|
||||
var w = el('div');
|
||||
w.className = 'pe-welcome';
|
||||
var icon = el('div', '🦴');
|
||||
icon.className = 'pe-welcome-icon';
|
||||
var h2 = el('h2', 'Éditeur de pathologies');
|
||||
var p1 = el('p', 'Choisissez une source dans la barre latérale pour commencer. Sélectionnez un SVG et son JSON de pathologies associé.');
|
||||
var p2 = el('p', 'Cliquez ensuite sur une zone anatomique pour éditer son arbre de pathologies.');
|
||||
var h2 = el('h2', t('welcome_title'));
|
||||
var p1 = el('p', t('welcome_p1'));
|
||||
var p2 = el('p', t('welcome_p2'));
|
||||
w.append(icon, h2, p1, p2);
|
||||
canvasInner.appendChild(w);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user