2023-08-02 17:12:15 +00:00
|
|
|
'use strict';
|
2023-08-08 16:08:44 +00:00
|
|
|
|
2024-05-12 22:02:26 +00:00
|
|
|
document.getElementById('kumoa').addEventListener('click', () => {
|
|
|
|
suorita(tietokanta.kumoa());
|
2023-08-08 16:08:44 +00:00
|
|
|
});
|
|
|
|
|
2024-05-12 22:02:26 +00:00
|
|
|
function suorita(muutokset) {
|
|
|
|
for (const muutos of muutokset) {
|
|
|
|
suoritaMuutos(muutos);
|
2023-08-02 17:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 22:02:26 +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}`);
|
2023-08-08 16:08:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-12 22:02:26 +00:00
|
|
|
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
|
|
|
}
|