summaryrefslogtreecommitdiff
path: root/scripts/studien-edit.js
blob: d22b4f6b2c758a0aa50dc9656f2386b6d3600b7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let text = getFieldValue('studienalle');
let json = [];
let newJson = [];

try {
    json = JSON.parse(getFieldValue('studienallejson'));
    if (!Array.isArray(json)) {
        json = [];
    }
} catch (e) {
    json = [];
}

if (typeof text === 'string' || text instanceof String) {
    text.split('\n').forEach(line => {
        let id = line.split(';')[0];
        json.forEach(entry => {
            if (id === entry.nct) {
                newJson.push(entry);
            }
        });
    });
    setFieldValue('studienallejson', JSON.stringify(newJson));
} else {
    setFieldValue('studienallejson', JSON.stringify([]));
}