// preset-ui.js
window.PresetUI = {
renderTable() {
const tableBody = document.querySelector('#sortable-tbody');
if (!tableBody) return;
tableBody.innerHTML = '';
window.PresetManager.presets.forEach((preset, index) => {
const row = document.createElement('tr');
row.setAttribute('data-index', index);
row.innerHTML = `
☰ |
|
|
|
`;
tableBody.appendChild(row);
});
this.updateExportFields();
},
async updateExportFields() {
const exportField = document.getElementById('export-string-field');
if (!exportField || !window.PresetManager) return;
const dataString = await window.PresetManager.generateExportCode(false);
const baseUrl = window.location.origin + window.location.pathname;
exportField.value = baseUrl + '#' + dataString;
},
copyShareLink() {
const exportField = document.getElementById('export-string-field');
if (!exportField || !exportField.value) return;
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(exportField.value)
.catch(() => this.fallbackCopy(exportField));
} else {
this.fallbackCopy(exportField);
}
},
fallbackCopy(field) {
field.select();
field.setSelectionRange(0, 99999);
try {
document.execCommand('copy');
} catch (err) {
window.UI.showAlert("Fehler", "Link bitte manuell kopieren.");
}
},
addPreset() {
// Hier Umlaute vermeiden oder Entities nutzen beim Default-Namen
window.PresetManager.presets.push({ name: 'Neuer Sender', url: '' });
this.renderTable();
},
deletePreset(index) {
// "Löschen" -> "Löschen" zur Sicherheit
window.UI.showConfirm("Löschen", "Sender wirklich entfernen?", (conf) => {
if (conf) {
window.PresetManager.presets.splice(index, 1);
this.renderTable();
}
});
},
changeName(i, v) {
window.PresetManager.presets[i].name = v;
this.updateExportFields();
},
changeURL(i, v) {
window.PresetManager.presets[i].url = v;
this.updateExportFields();
}
};
window.addPreset = () => window.PresetUI.addPreset();
window.deletePreset = (i) => window.PresetUI.deletePreset(i);
window.copyShareLink = () => window.PresetUI.copyShareLink();