mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 14:04:34 +00:00
0.9.6.24: Migrations-UI aus Verbindungseditor entfernen
This commit is contained in:
@@ -2,20 +2,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function ready(callback) {
|
function ready(callback) {
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', callback);
|
||||||
document.addEventListener('DOMContentLoaded', function () { window.setTimeout(callback, 0); });
|
else callback();
|
||||||
} else {
|
|
||||||
window.setTimeout(callback, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ready(function () {
|
ready(function () {
|
||||||
var section = document.getElementById('nc-connector');
|
var section = document.getElementById('nc-connector');
|
||||||
if (!section) return;
|
if (!section) return;
|
||||||
|
|
||||||
var pwgTokenInput = section.querySelector('input[name="pwg_token"]');
|
var tokenInput = section.querySelector('input[name="pwg_token"]');
|
||||||
var pwgToken = pwgTokenInput ? pwgTokenInput.value : '';
|
var pwgToken = tokenInput ? tokenInput.value : '';
|
||||||
var modeKey = 'bratonienNcWizardMode';
|
|
||||||
|
|
||||||
function escapeHtml(value) {
|
function escapeHtml(value) {
|
||||||
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) {
|
||||||
@@ -23,27 +19,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setMode(value) {
|
|
||||||
try { sessionStorage.setItem(modeKey, value); } catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
function postForm(label, tool, id, mode) {
|
|
||||||
var form = document.createElement('form');
|
|
||||||
form.method = 'post';
|
|
||||||
form.style.display = 'inline';
|
|
||||||
form.dataset.ncV2Action = tool;
|
|
||||||
form.innerHTML = '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
|
||||||
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(id)+'">'
|
|
||||||
+ '<button class="buttonLike" type="submit" name="bratonien_tool" value="'+escapeHtml(tool)+'">'+escapeHtml(label)+'</button>';
|
|
||||||
if (mode) form.addEventListener('submit', function () { setMode(mode); }, true);
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadConnection(id) {
|
function loadConnection(id) {
|
||||||
return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), {
|
return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), {
|
||||||
credentials:'same-origin',
|
credentials:'same-origin', cache:'no-store', headers:{'Accept':'application/json'}
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'}
|
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
return response.json().then(function (data) {
|
return response.json().then(function (data) {
|
||||||
if (!response.ok) throw new Error(data.error || ('HTTP '+response.status));
|
if (!response.ok) throw new Error(data.error || ('HTTP '+response.status));
|
||||||
@@ -52,6 +30,16 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createPostForm(label, tool, id) {
|
||||||
|
var form = document.createElement('form');
|
||||||
|
form.method = 'post';
|
||||||
|
form.style.display = 'inline';
|
||||||
|
form.innerHTML = '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
||||||
|
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(id)+'">'
|
||||||
|
+ '<button class="buttonLike" type="submit" name="bratonien_tool" value="'+escapeHtml(tool)+'">'+escapeHtml(label)+'</button>';
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
function dialog() {
|
function dialog() {
|
||||||
var node = document.getElementById('bratonien-nc-connection-edit-v2');
|
var node = document.getElementById('bratonien-nc-connection-edit-v2');
|
||||||
if (node) return node;
|
if (node) return node;
|
||||||
@@ -60,11 +48,11 @@
|
|||||||
node.className = 'bratonien-edit-dialog';
|
node.className = 'bratonien-edit-dialog';
|
||||||
node.innerHTML = '<div class="bratonien-edit-dialog__body">'
|
node.innerHTML = '<div class="bratonien-edit-dialog__body">'
|
||||||
+ '<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem">'
|
+ '<div style="display:flex;align-items:flex-start;justify-content:space-between;gap:1rem">'
|
||||||
+ '<div><h4 style="margin:0">Verbindung bearbeiten</h4><p class="bratonien-base-note" style="margin:.35rem 0 0">Alle für diese Verbindung nötigen Zugänge werden hier gemeinsam gepflegt.</p></div>'
|
+ '<div><h4 style="margin:0">Verbindung bearbeiten</h4><p class="bratonien-base-note" style="margin:.35rem 0 0">Die Einstellungen gelten nur für diese Verbindung.</p></div>'
|
||||||
+ '<button type="button" class="buttonLike" data-edit-v2-close>Schließen</button></div>'
|
+ '<button type="button" class="buttonLike" data-edit-close>Schließen</button></div>'
|
||||||
+ '<div data-edit-v2-content style="margin-top:1rem"></div></div>';
|
+ '<div data-edit-content style="margin-top:1rem"></div></div>';
|
||||||
document.body.appendChild(node);
|
document.body.appendChild(node);
|
||||||
node.querySelector('[data-edit-v2-close]').addEventListener('click', function () { node.close(); });
|
node.querySelector('[data-edit-close]').addEventListener('click', function () { node.close(); });
|
||||||
node.addEventListener('click', function (event) { if (event.target === node) node.close(); });
|
node.addEventListener('click', function (event) { if (event.target === node) node.close(); });
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@@ -78,129 +66,68 @@
|
|||||||
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
+ '<button type="button" class="buttonLike" data-remove-storage>Entfernen</button></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearValidation(form) {
|
function showError(form, data) {
|
||||||
[].slice.call(form.querySelectorAll('[aria-invalid="true"]')).forEach(function (field) {
|
var old = form.querySelector('[data-edit-error]');
|
||||||
field.removeAttribute('aria-invalid');
|
if (old) old.remove();
|
||||||
field.style.borderColor = '';
|
var box = document.createElement('div');
|
||||||
field.style.boxShadow = '';
|
box.dataset.editError = '1';
|
||||||
});
|
box.className = 'bratonien-main-cache__warning';
|
||||||
[].slice.call(form.querySelectorAll('[data-edit-v2-field-error]')).forEach(function (node) { node.remove(); });
|
box.style.margin = '0 0 1rem';
|
||||||
var box = form.querySelector('[data-edit-v2-error-summary]');
|
box.textContent = (data && data.message) ? data.message : 'Die Verbindung konnte nicht gespeichert werden.';
|
||||||
if (box) box.remove();
|
form.insertBefore(box, form.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fieldNodes(form, fieldName) {
|
function submitLocal(form, editDialog) {
|
||||||
return [].slice.call(form.querySelectorAll('[name="'+fieldName.replace(/"/g, '\\"')+'"]'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function showValidation(form, data) {
|
|
||||||
clearValidation(form);
|
|
||||||
var message = (data && data.message) ? data.message : 'Die Verbindung konnte nicht gespeichert werden.';
|
|
||||||
var summary = document.createElement('div');
|
|
||||||
summary.dataset.editV2ErrorSummary = '1';
|
|
||||||
summary.className = 'bratonien-main-cache__warning';
|
|
||||||
summary.style.margin = '0 0 1rem';
|
|
||||||
summary.style.padding = '.75rem';
|
|
||||||
summary.style.border = '1px solid currentColor';
|
|
||||||
summary.innerHTML = '<strong>Speichern fehlgeschlagen:</strong> '+escapeHtml(message);
|
|
||||||
form.insertBefore(summary, form.firstChild);
|
|
||||||
|
|
||||||
var first = null;
|
|
||||||
var fields = data && Array.isArray(data.fields) ? data.fields : [];
|
|
||||||
fields.forEach(function (fieldName) {
|
|
||||||
fieldNodes(form, fieldName).forEach(function (field) {
|
|
||||||
field.setAttribute('aria-invalid', 'true');
|
|
||||||
field.style.borderColor = '#d65a5a';
|
|
||||||
field.style.boxShadow = '0 0 0 1px #d65a5a';
|
|
||||||
if (!first) first = field;
|
|
||||||
var note = document.createElement('span');
|
|
||||||
note.dataset.editV2FieldError = '1';
|
|
||||||
note.className = 'bratonien-main-cache__warning';
|
|
||||||
note.style.display = 'block';
|
|
||||||
note.style.marginTop = '.25rem';
|
|
||||||
note.textContent = message;
|
|
||||||
field.insertAdjacentElement('afterend', note);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
first.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
window.setTimeout(function () { first.focus(); }, 150);
|
|
||||||
} else {
|
|
||||||
summary.scrollIntoView({block:'center', behavior:'smooth'});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function submitEditor(form, editDialog) {
|
|
||||||
clearValidation(form);
|
|
||||||
if (!form.reportValidity()) return;
|
if (!form.reportValidity()) return;
|
||||||
|
var button = form.querySelector('button[type="submit"]');
|
||||||
var submit = form.querySelector('button[type="submit"]');
|
if (button) button.disabled = true;
|
||||||
if (submit) submit.disabled = true;
|
|
||||||
|
|
||||||
var body = new FormData(form);
|
|
||||||
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
fetch('plugins/bratonien_tools/nc-connector-edit-save.php', {
|
||||||
method:'POST',
|
method:'POST', credentials:'same-origin', cache:'no-store', headers:{'Accept':'application/json'}, body:new FormData(form)
|
||||||
credentials:'same-origin',
|
|
||||||
cache:'no-store',
|
|
||||||
headers:{'Accept':'application/json'},
|
|
||||||
body:body
|
|
||||||
}).then(function (response) {
|
}).then(function (response) {
|
||||||
return response.json().then(function (data) {
|
return response.json().then(function (data) {
|
||||||
if (!response.ok || !data.ok) {
|
if (!response.ok || !data.ok) { showError(form, data); return; }
|
||||||
showValidation(form, data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editDialog.close();
|
editDialog.close();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
showValidation(form, {message:error.message || String(error), fields:[]});
|
showError(form, {message:error.message || String(error)});
|
||||||
}).finally(function () {
|
}).finally(function () {
|
||||||
if (submit) submit.disabled = false;
|
if (button) button.disabled = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEditor(id) {
|
function openLocalEditor(id) {
|
||||||
var editDialog = dialog();
|
var editDialog = dialog();
|
||||||
var content = editDialog.querySelector('[data-edit-v2-content]');
|
var content = editDialog.querySelector('[data-edit-content]');
|
||||||
content.innerHTML = '<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
content.innerHTML = '<p class="bratonien-base-note">Verbindung wird geladen …</p>';
|
||||||
if (typeof editDialog.showModal === 'function') editDialog.showModal();
|
if (typeof editDialog.showModal === 'function') editDialog.showModal();
|
||||||
else editDialog.setAttribute('open', 'open');
|
else editDialog.setAttribute('open', 'open');
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
loadConnection(id).then(function (data) {
|
||||||
if (data.adapter !== 'local') throw new Error('Diese Ansicht ist für eine noch nicht migrierte Verbindung vorgesehen.');
|
if (data.adapter !== 'local') throw new Error('Diese Verbindung wird über den WebDAV-Assistenten bearbeitet.');
|
||||||
var legacy = data.legacy || {};
|
var legacy = data.legacy || {};
|
||||||
var webdav = data.webdav || {};
|
var webdav = data.webdav || {};
|
||||||
var storages = Array.isArray(legacy.storages) ? legacy.storages : [];
|
var storages = Array.isArray(legacy.storages) ? legacy.storages : [];
|
||||||
var rows = storages.map(storageRow).join('') || storageRow({});
|
var rows = storages.map(storageRow).join('') || storageRow({});
|
||||||
var migrationText = webdav.migration_ready
|
|
||||||
? '<strong>Bereit.</strong> Nextcloud-Zugang und ein gültiger Piwigo-Zugang sind vollständig gespeichert.'
|
|
||||||
: '<strong>Noch nicht bereit.</strong> Es fehlen: '+escapeHtml((webdav.migration_missing || []).join(', ') || 'WebDAV-Zugangsdaten')+'.';
|
|
||||||
|
|
||||||
content.innerHTML = '<form method="post" data-edit-v2-form>'
|
content.innerHTML = '<form method="post" data-edit-form>'
|
||||||
+ '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
+ '<input type="hidden" name="pwg_token" value="'+escapeHtml(pwgToken)+'">'
|
||||||
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'
|
+ '<input type="hidden" name="connection_id" value="'+escapeHtml(data.id)+'">'
|
||||||
+ '<h5>Verbindung</h5><div class="bratonien-form-grid">'
|
+ '<h5>Verbindung</h5><div class="bratonien-form-grid">'
|
||||||
+ '<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'
|
+ '<label class="bratonien-label">Name</label><input name="connection_name" value="'+escapeHtml(data.name)+'" required>'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Nextcloud / WebDAV</h5>'
|
+ '<h5 style="margin-top:1.2rem">Nextcloud</h5><div class="bratonien-form-grid">'
|
||||||
+ '<p class="bratonien-base-note">Diese Angaben bestimmen, auf welche Ordner diese Verbindung zugreifen darf.</p>'
|
+ '<label class="bratonien-label">Nextcloud-Adresse</label><input name="nc_nextcloud_url" value="'+escapeHtml(webdav.nextcloud_url || '')+'">'
|
||||||
+ '<div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">Nextcloud-Adresse</label><input name="nc_nextcloud_url" value="'+escapeHtml(webdav.nextcloud_url || '')+'" placeholder="https://cloud.example.de">'
|
|
||||||
+ '<label class="bratonien-label">Nextcloud-Benutzer</label><input name="nc_nextcloud_user" value="'+escapeHtml(webdav.nextcloud_user || '')+'" autocomplete="username">'
|
+ '<label class="bratonien-label">Nextcloud-Benutzer</label><input name="nc_nextcloud_user" value="'+escapeHtml(webdav.nextcloud_user || '')+'" autocomplete="username">'
|
||||||
+ '<label class="bratonien-label">Nextcloud-Passwort</label><input name="nc_nextcloud_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_nextcloud_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
+ '<label class="bratonien-label">Nextcloud-Passwort</label><input name="nc_nextcloud_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_nextcloud_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Piwigo-Zugang</h5>'
|
+ '<h5 style="margin-top:1.2rem">Piwigo-Zugang</h5><div class="bratonien-form-grid">'
|
||||||
+ '<p class="bratonien-base-note">Bevorzugt wird die API. Benutzername und Passwort können als Fallback verwendet werden.</p>'
|
|
||||||
+ '<div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">API-Schlüssel-ID</label><input name="nc_connection_api_key_id" value="'+escapeHtml(webdav.api_key_id || '')+'" autocomplete="off">'
|
+ '<label class="bratonien-label">API-Schlüssel-ID</label><input name="nc_connection_api_key_id" value="'+escapeHtml(webdav.api_key_id || '')+'" autocomplete="off">'
|
||||||
+ '<label class="bratonien-label">API-Geheimnis</label><input name="nc_connection_api_key_secret" type="password" autocomplete="new-password" placeholder="'+(webdav.has_api_key_secret ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
+ '<label class="bratonien-label">API-Geheimnis</label><input name="nc_connection_api_key_secret" type="password" autocomplete="new-password" placeholder="'+(webdav.has_api_key_secret ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
+ '<label class="bratonien-label">Fallback-Benutzer</label><input name="nc_fallback_user" value="'+escapeHtml(webdav.fallback_user || '')+'" autocomplete="username">'
|
+ '<label class="bratonien-label">Fallback-Benutzer</label><input name="nc_fallback_user" value="'+escapeHtml(webdav.fallback_user || '')+'" autocomplete="username">'
|
||||||
+ '<label class="bratonien-label">Fallback-Passwort</label><input name="nc_fallback_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_fallback_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
+ '<label class="bratonien-label">Fallback-Passwort</label><input name="nc_fallback_password" type="password" autocomplete="current-password" placeholder="'+(webdav.has_fallback_password ? 'gespeichert – leer = unverändert' : 'noch nicht gespeichert')+'">'
|
||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<p class="bratonien-base-note"><strong>WebDAV-Migration:</strong> '+migrationText+'</p>'
|
+ '<h5 style="margin-top:1.2rem">Lokaler Connector</h5><div class="bratonien-form-grid">'
|
||||||
+ '<h5 style="margin-top:1.2rem">Bestehender Legacy-Weg</h5><div class="bratonien-form-grid">'
|
|
||||||
+ '<label class="bratonien-label">Datenbank-Server</label><input name="nc_host" value="'+escapeHtml(legacy.host)+'" required>'
|
+ '<label class="bratonien-label">Datenbank-Server</label><input name="nc_host" value="'+escapeHtml(legacy.host)+'" required>'
|
||||||
+ '<label class="bratonien-label">Port</label><input name="nc_port" type="number" min="1" max="65535" value="'+escapeHtml(legacy.port || 5432)+'" required>'
|
+ '<label class="bratonien-label">Port</label><input name="nc_port" type="number" min="1" max="65535" value="'+escapeHtml(legacy.port || 5432)+'" required>'
|
||||||
+ '<label class="bratonien-label">Datenbank</label><input name="nc_database" value="'+escapeHtml(legacy.database)+'" required>'
|
+ '<label class="bratonien-label">Datenbank</label><input name="nc_database" value="'+escapeHtml(legacy.database)+'" required>'
|
||||||
@@ -209,7 +136,7 @@
|
|||||||
+ '</div>'
|
+ '</div>'
|
||||||
+ '<h5 style="margin-top:1.2rem">Speicherorte</h5><div data-storage-list>'+rows+'</div>'
|
+ '<h5 style="margin-top:1.2rem">Speicherorte</h5><div data-storage-list>'+rows+'</div>'
|
||||||
+ '<button type="button" class="buttonLike" data-add-storage>Speicherort hinzufügen</button>'
|
+ '<button type="button" class="buttonLike" data-add-storage>Speicherort hinzufügen</button>'
|
||||||
+ '<details style="margin-top:1rem"><summary>Erweiterte Legacy-Einstellungen</summary><div class="bratonien-form-grid" style="margin-top:.75rem">'
|
+ '<details style="margin-top:1rem"><summary>Erweiterte Einstellungen</summary><div class="bratonien-form-grid" style="margin-top:.75rem">'
|
||||||
+ '<label class="bratonien-label">Source-View</label><input name="nc_source_view" value="'+escapeHtml(legacy.source_view)+'" required>'
|
+ '<label class="bratonien-label">Source-View</label><input name="nc_source_view" value="'+escapeHtml(legacy.source_view)+'" required>'
|
||||||
+ '<label class="bratonien-label">Activity-View</label><input name="nc_activity_view" value="'+escapeHtml(legacy.activity_view)+'" required>'
|
+ '<label class="bratonien-label">Activity-View</label><input name="nc_activity_view" value="'+escapeHtml(legacy.activity_view)+'" required>'
|
||||||
+ '<label class="bratonien-label">Piwigo-Galerieordner</label><input name="nc_gallery_root" value="'+escapeHtml(legacy.gallery_root)+'" required>'
|
+ '<label class="bratonien-label">Piwigo-Galerieordner</label><input name="nc_gallery_root" value="'+escapeHtml(legacy.gallery_root)+'" required>'
|
||||||
@@ -217,105 +144,61 @@
|
|||||||
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
+ '<label class="bratonien-label">Maximale Wartezeit (Sek.)</label><input name="nc_max_wait_seconds" type="number" min="60" value="'+escapeHtml(legacy.max_wait_seconds)+'">'
|
||||||
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
+ '<label class="bratonien-label">Vollprüfung nach (Sek.)</label><input name="nc_full_sync_seconds" type="number" min="300" value="'+escapeHtml(legacy.full_sync_seconds)+'">'
|
||||||
+ '</div></details>'
|
+ '</div></details>'
|
||||||
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-edit-v2-cancel>Abbrechen</button></div>'
|
+ '<div class="bratonien-actions" style="margin-top:1rem"><button class="buttonLike" type="submit">Änderungen prüfen und speichern</button><button class="buttonLike" type="button" data-cancel>Abbrechen</button></div>'
|
||||||
+ '</form>';
|
+ '</form>';
|
||||||
|
|
||||||
var form = content.querySelector('[data-edit-v2-form]');
|
var form = content.querySelector('[data-edit-form]');
|
||||||
form.querySelector('[data-edit-v2-cancel]').addEventListener('click', function () { editDialog.close(); });
|
form.querySelector('[data-cancel]').addEventListener('click', function () { editDialog.close(); });
|
||||||
form.querySelector('[data-add-storage]').addEventListener('click', function () {
|
form.querySelector('[data-add-storage]').addEventListener('click', function () {
|
||||||
form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({}));
|
form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({}));
|
||||||
});
|
});
|
||||||
form.addEventListener('click', function (event) {
|
form.addEventListener('click', function (event) {
|
||||||
var remove = event.target.closest('[data-remove-storage]');
|
var remove = event.target.closest('[data-remove-storage]');
|
||||||
if (!remove) return;
|
if (remove) {
|
||||||
var row = remove.closest('[data-storage-row]');
|
var row = remove.closest('[data-storage-row]');
|
||||||
if (row) row.remove();
|
if (row) row.remove();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
form.addEventListener('submit', function (event) {
|
form.addEventListener('submit', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
submitLocal(form, editDialog);
|
||||||
submitEditor(form, editDialog);
|
|
||||||
});
|
});
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
content.innerHTML = '<p class="bratonien-main-cache__warning"><strong>Bearbeiten nicht möglich:</strong> '+escapeHtml(error.message || String(error))+'</p>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuildLocalActions(deleteForm, id, connectionData) {
|
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
|
|
||||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
|
||||||
var migrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
|
||||||
var editStart = form.querySelector('button[value="nc_connector_edit_start"]');
|
|
||||||
if (migrate || editStart) form.remove();
|
|
||||||
});
|
|
||||||
[].slice.call(actions.children).forEach(function (child) {
|
|
||||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
|
||||||
if (child.dataset && child.dataset.ncMigrationInfo) child.remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
var edit = document.createElement('button');
|
|
||||||
edit.type = 'button';
|
|
||||||
edit.className = 'buttonLike';
|
|
||||||
edit.textContent = 'Bearbeiten';
|
|
||||||
edit.addEventListener('click', function () { openEditor(id); });
|
|
||||||
actions.insertBefore(edit, deleteForm);
|
|
||||||
|
|
||||||
var info = document.createElement('span');
|
|
||||||
info.dataset.ncMigrationInfo = '1';
|
|
||||||
info.className = 'bratonien-base-note';
|
|
||||||
info.textContent = 'WebDAV-Migration wird geprüft …';
|
|
||||||
actions.insertBefore(info, deleteForm);
|
|
||||||
|
|
||||||
var dataPromise = connectionData ? Promise.resolve(connectionData) : loadConnection(id);
|
|
||||||
dataPromise.then(function (data) {
|
|
||||||
var webdav = data.webdav || {};
|
|
||||||
if (webdav.migration_ready) {
|
|
||||||
info.remove();
|
|
||||||
actions.insertBefore(postForm('Auf WebDAV migrieren', 'nc_connector_migrate_start', id, 'migrate'), deleteForm);
|
|
||||||
} else {
|
|
||||||
var missing = (webdav.migration_missing || []).join(', ');
|
|
||||||
info.textContent = 'Migration noch nicht bereit: '+(missing || 'Zugangsdaten fehlen')+'. Zuerst „Bearbeiten“.';
|
|
||||||
}
|
|
||||||
}).catch(function (error) {
|
|
||||||
info.textContent = 'Migration kann nicht geprüft werden: '+(error.message || String(error));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildRemoteActions(deleteForm, id) {
|
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
[].slice.call(actions.querySelectorAll('form')).forEach(function (form) {
|
|
||||||
var oldEdit = form.querySelector('button[value="nc_connector_edit_start"]');
|
|
||||||
var oldMigrate = form.querySelector('button[value="nc_connector_migrate_start"]');
|
|
||||||
if (oldEdit || oldMigrate) form.remove();
|
|
||||||
});
|
|
||||||
[].slice.call(actions.children).forEach(function (child) {
|
|
||||||
if (child.tagName === 'BUTTON' && (child.textContent || '').trim() === 'Bearbeiten') child.remove();
|
|
||||||
if (child.dataset && child.dataset.ncMigrationInfo) child.remove();
|
|
||||||
});
|
|
||||||
actions.insertBefore(postForm('Bearbeiten', 'nc_connector_edit_start', id, 'edit'), deleteForm);
|
|
||||||
}
|
|
||||||
|
|
||||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_edit_start"]')).forEach(function (button) {
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_edit_start"]')).forEach(function (button) {
|
||||||
var form = button.closest('form');
|
var form = button.closest('form');
|
||||||
if (form) form.remove();
|
if (form) form.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_migrate_start"]')).forEach(function (button) {
|
||||||
|
var form = button.closest('form');
|
||||||
|
if (form) form.remove();
|
||||||
|
});
|
||||||
|
|
||||||
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
[].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) {
|
||||||
var deleteForm = deleteButton.closest('form');
|
var deleteForm = deleteButton.closest('form');
|
||||||
if (!deleteForm) return;
|
if (!deleteForm || !deleteForm.parentElement) return;
|
||||||
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
var idInput = deleteForm.querySelector('input[name="connection_id"]');
|
||||||
if (!idInput) return;
|
if (!idInput) return;
|
||||||
var id = idInput.value;
|
var id = idInput.value;
|
||||||
|
var actions = deleteForm.parentElement;
|
||||||
|
|
||||||
loadConnection(id).then(function (data) {
|
loadConnection(id).then(function (data) {
|
||||||
if (data.adapter === 'local') rebuildLocalActions(deleteForm, id, data);
|
var edit;
|
||||||
else rebuildRemoteActions(deleteForm, id);
|
if (data.adapter === 'local') {
|
||||||
|
edit = document.createElement('button');
|
||||||
|
edit.type = 'button';
|
||||||
|
edit.className = 'buttonLike';
|
||||||
|
edit.textContent = 'Bearbeiten';
|
||||||
|
edit.addEventListener('click', function () { openLocalEditor(id); });
|
||||||
|
} else {
|
||||||
|
edit = createPostForm('Bearbeiten', 'nc_connector_edit_start', id);
|
||||||
|
}
|
||||||
|
actions.insertBefore(edit, deleteForm);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
var actions = deleteForm.parentElement;
|
|
||||||
if (!actions) return;
|
|
||||||
var info = document.createElement('span');
|
var info = document.createElement('span');
|
||||||
info.className = 'bratonien-main-cache__warning';
|
info.className = 'bratonien-main-cache__warning';
|
||||||
info.textContent = 'Verbindung konnte nicht geladen werden: '+(error.message || String(error));
|
info.textContent = 'Verbindung konnte nicht geladen werden: '+(error.message || String(error));
|
||||||
|
|||||||
Reference in New Issue
Block a user