Auf Wunsch von Filipe. Betrifft ausschliesslich die Anzeige.
Der Rollenschluessel bleibt "admin". Er steckt in der CHECK-Regel der
Datenbank, in jeder bestehenden Sitzung und in jeder Rechteabfrage --
ihn umzubenennen haette alle drei gebrochen, und bestehende Anmeldungen
waeren ungueltig geworden. Umbenannt wird nur, was man LIEST.
Der Anzeigename steht jetzt an EINER Stelle (ROLLEN_NAME in
workspace.js) und kommt ueber /workspace/api/ich als rolle_name mit.
Stand er in elf Dateien, waere er beim naechsten Mal in zehn davon
geaendert.
Dabei aufgefallen: In der Kopfleiste stand auf JEDER Seite der rohe
Rollenschluessel -- "Chef · admin". Das war schon vorher unschoen, faellt
aber jetzt erst richtig auf. Alle elf Seiten zeigen jetzt "Chef ·
DogFather". Geprueft: kein rohes "admin" mehr in der Oberflaeche.
Geaendert: Rollenkachel und Untertitel auf der Anmeldeseite, Kopfleiste
aller Seiten, Rollentext auf dem Dashboard, Rollenmarken und Auswahl in
der Personenverwaltung, die Betreuungs-Auswahl ("nur DogFather"), der
Hinweis auf der Dateienseite, die Erklaerung zur internen Notiz im
Profil, die Hinweise fuer Scouts ohne Zuteilung -- und vier
Fehlermeldungen vom Server.
Schreibweise "DogFather" wie von Filipe geschrieben; das ist auch auf
der oeffentlichen Website die haeufigste Form (717 von 1216).
In den Code-Kommentaren der Fachmodule heisst die Rolle weiterhin "das
Management". Das bleibt bewusst so -- eine Massenaenderung an vierzig
Kommentaren waere reines Risiko ohne sichtbaren Nutzen. Ein Hinweis an
der ROLLEN_NAME-Zuordnung erklaert den Zusammenhang.
133 lines
4.6 KiB
JavaScript
133 lines
4.6 KiB
JavaScript
/* ===================================================================
|
|
Creator-Profil.
|
|
|
|
Welche Felder überhaupt ankommen, entscheidet der Server anhand der
|
|
Rolle -- `admin_notiz` fehlt in der Antwort an einen Creator komplett.
|
|
Diese Datei blendet deshalb nur aus, was ohnehin nicht da ist.
|
|
=================================================================== */
|
|
(() => {
|
|
'use strict';
|
|
|
|
const OFFEN = ['handles', 'nische', 'live_zeiten', 'technik',
|
|
'ziel_live', 'ziel_content', 'ziel_community', 'ziel_technik',
|
|
'plan_prio1', 'plan_prio2', 'plan_prio3'];
|
|
const NUR_ADMIN = ['plan_start', 'naechster_review', 'admin_notiz'];
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
let ich = null;
|
|
let aktuell = null;
|
|
let darfAlles = false;
|
|
|
|
const melde = (t) => { $('fehler').textContent = t || ''; };
|
|
|
|
async function hole(pfad, optionen = {}) {
|
|
const a = await fetch(pfad, { credentials: 'same-origin', ...optionen });
|
|
if (a.status === 401) { location.assign('/workspace/'); throw new Error('abgemeldet'); }
|
|
return a;
|
|
}
|
|
|
|
function fuelle(profil) {
|
|
for (const f of [...OFFEN, ...NUR_ADMIN]) {
|
|
const feld = $(f);
|
|
if (!feld) continue;
|
|
/* undefined heißt: Der Server hat das Feld nicht geschickt (fehlende
|
|
Berechtigung). Dann bleibt es leer und wird auch nicht gesendet. */
|
|
feld.value = profil[f] ?? '';
|
|
}
|
|
}
|
|
|
|
function datumHuebsch(iso) {
|
|
return iso.slice(0, 10).split('-').reverse().join('.');
|
|
}
|
|
|
|
async function profilLaden(id) {
|
|
melde('');
|
|
try {
|
|
const a = await hole('/workspace/api/profil/' + id);
|
|
if (!a.ok) { melde('Profil konnte nicht geladen werden.'); return; }
|
|
const daten = await a.json();
|
|
aktuell = daten.person.id;
|
|
darfAlles = daten.darf_alles;
|
|
|
|
$('titel').textContent = ich.rolle === 'admin'
|
|
? 'Profil: ' + daten.person.name
|
|
: 'Mein Profil';
|
|
$('unterzeile').textContent = daten.profil.geaendert
|
|
? 'Zuletzt geändert am ' + datumHuebsch(daten.profil.geaendert)
|
|
: 'Noch nichts eingetragen.';
|
|
|
|
$('gruppe-intern').hidden = !darfAlles;
|
|
$('termine').hidden = !darfAlles;
|
|
fuelle(daten.profil);
|
|
$('formular').hidden = false;
|
|
} catch { /* umgeleitet */ }
|
|
}
|
|
|
|
$('formular').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
melde('');
|
|
const knopf = $('speichern');
|
|
const daten = {};
|
|
for (const f of darfAlles ? [...OFFEN, ...NUR_ADMIN] : OFFEN) {
|
|
const feld = $(f);
|
|
if (feld) daten[f] = feld.value;
|
|
}
|
|
knopf.disabled = true;
|
|
$('stand').textContent = 'Speichere …';
|
|
try {
|
|
const a = await hole('/workspace/api/profil/' + aktuell, {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(daten),
|
|
});
|
|
if (!a.ok) {
|
|
melde((await a.json().catch(() => ({}))).fehler || 'Speichern ging nicht.');
|
|
$('stand').textContent = '';
|
|
return;
|
|
}
|
|
$('stand').textContent = 'Gespeichert ✓';
|
|
setTimeout(() => { $('stand').textContent = ''; }, 2600);
|
|
} catch { /* umgeleitet */ } finally { knopf.disabled = false; }
|
|
});
|
|
|
|
|
|
(async () => {
|
|
try {
|
|
const a = await hole('/workspace/api/ich');
|
|
if (!a.ok) { location.assign('/workspace/'); return; }
|
|
ich = await a.json();
|
|
} catch { return; }
|
|
/* Scouts betreuen ihre zugeteilten Creator wie DogFather --
|
|
sie sehen aber nur die management-internen Felder nicht. */
|
|
$('wer').textContent = ich.name + ' · ' + (ich.rolle_name || ich.rolle);
|
|
|
|
let liste;
|
|
try { liste = await (await hole('/workspace/api/profil')).json(); } catch { return; }
|
|
|
|
if (ich.rolle === 'admin' || ich.rolle === 'scout') {
|
|
if (!liste.creator.length) {
|
|
$('unterzeile').textContent = ich.rolle === 'scout'
|
|
? 'Dir ist noch kein Creator zugeteilt. DogFather legt fest, wen du betreust.'
|
|
: 'Es gibt noch keinen Creator. Lege zuerst unter Personen & Zugänge einen an.';
|
|
return;
|
|
}
|
|
if (ich.rolle === 'scout') {
|
|
$('unterzeile').textContent = liste.creator.length === 1
|
|
? 'Der Creator, den du betreust.'
|
|
: `Die ${liste.creator.length} Creator, die du betreust.`;
|
|
}
|
|
$('auswahl-block').hidden = false;
|
|
for (const c of liste.creator) {
|
|
const o = document.createElement('option');
|
|
o.value = String(c.id);
|
|
o.textContent = c.name + (c.aktiv ? '' : ' (gesperrt)');
|
|
$('auswahl').append(o);
|
|
}
|
|
$('auswahl').addEventListener('change', () => profilLaden(Number($('auswahl').value)));
|
|
await profilLaden(liste.creator[0].id);
|
|
} else {
|
|
await profilLaden(ich.id);
|
|
}
|
|
})();
|
|
})();
|