mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added presets
This commit is contained in:
@@ -269,4 +269,36 @@ function unflatten(obj) {
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function loadPresetsIntoSelect(selectElement, selectedValue = null) {
|
||||
try {
|
||||
const response = await fetch('/Settings/Presets');
|
||||
const responseJson = await response.json();
|
||||
var presets = [];
|
||||
for (var key in responseJson) {
|
||||
presets.push(key);
|
||||
}
|
||||
console.log(presets);
|
||||
const ts = selectElement.tomselect;
|
||||
if (!ts) {
|
||||
selectElement.innerHTML = `<option value="">${appTranslations.selectPreset}</option>`;
|
||||
presets.forEach(u => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = u;
|
||||
opt.textContent = u;
|
||||
selectElement.appendChild(opt);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ts.clearOptions();
|
||||
ts.addOption(presets.map(u => ({ value: u, text: u })));
|
||||
ts.refreshOptions(false);
|
||||
|
||||
if (selectedValue) ts.setValue(selectedValue);
|
||||
} catch (err) {
|
||||
console.error('Error loading presets:', err);
|
||||
showToast(appTranslations.errorLoadingPresets, 'danger');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user