lukujarjestaja/käyttöliittymä.js

35 lines
899 B
JavaScript
Raw Permalink Normal View History

2023-08-02 17:12:15 +00:00
'use strict';
document.getElementById('kumoa').addEventListener('click', () => {
suorita(tietokanta.kumoa());
});
function suorita(muutokset) {
for (const muutos of muutokset) {
suoritaMuutos(muutos);
2023-08-02 17:12:15 +00:00
}
}
function suoritaMuutos(muutos) {
const {taulu, id, vanha, uusi} = muutos;
if (taulu === taulut.luokat && vanha === undefined) {
// Uusi luokka
// TODO: Järjestele
const luokatLista = document.getElementById('luokat-lista');
luokatLista.appendChild(luoLuokka(id, uusi));
} else if (taulu === taulut.luokat && uusi === undefined) {
// Luokka poistettu
const luokka = document.getElementById(`luokka-${id}`);
luokka.parentElement.removeChild(luokka);
} else {
throw new Error(`Ei toteutettu ${taulu} ${id} ${vanha} ${uusi}`);
}
}
function luoLuokka(id, nimi) {
const li = document.createElement('li');
li.id = `luokka-${id}`;
li.textContent = nimi;
return li;
2023-08-02 17:12:15 +00:00
}