From 94c81789eda50b1ef237f2c1521b4523d0422033 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 13:46:26 +0200 Subject: [PATCH] 0.9.6.10 rebuild connection editor around complete connection data --- js/nc_connector_edit_v2.js | 205 +++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 js/nc_connector_edit_v2.js diff --git a/js/nc_connector_edit_v2.js b/js/nc_connector_edit_v2.js new file mode 100644 index 0000000..59966ac --- /dev/null +++ b/js/nc_connector_edit_v2.js @@ -0,0 +1,205 @@ +(function () { + 'use strict'; + + function ready(callback) { + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', function () { window.setTimeout(callback, 0); }); + } else { + window.setTimeout(callback, 0); + } + } + + ready(function () { + var section = document.getElementById('nc-connector'); + if (!section) return; + + var pwgTokenInput = section.querySelector('input[name="pwg_token"]'); + var pwgToken = pwgTokenInput ? pwgTokenInput.value : ''; + var modeKey = 'bratonienNcWizardMode'; + + function escapeHtml(value) { + return String(value == null ? '' : value).replace(/[&<>"']/g, function (c) { + return {'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]; + }); + } + + 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 = '' + + '' + + ''; + if (mode) form.addEventListener('submit', function () { setMode(mode); }, true); + return form; + } + + function loadConnection(id) { + return fetch('plugins/bratonien_tools/nc-connector-edit-data.php?connection_id='+encodeURIComponent(id)+'&_='+Date.now(), { + credentials:'same-origin', + cache:'no-store', + headers:{'Accept':'application/json'} + }).then(function (response) { + return response.json().then(function (data) { + if (!response.ok) throw new Error(data.error || ('HTTP '+response.status)); + return data; + }); + }); + } + + function dialog() { + var node = document.getElementById('bratonien-nc-connection-edit-v2'); + if (node) return node; + node = document.createElement('dialog'); + node.id = 'bratonien-nc-connection-edit-v2'; + node.className = 'bratonien-edit-dialog'; + node.innerHTML = '
' + + '
' + + '

Verbindung bearbeiten

Alle Daten dieser Verbindung werden hier gepflegt. Eine Migration ist ein eigener Vorgang.

' + + '
' + + '
'; + document.body.appendChild(node); + node.querySelector('[data-edit-v2-close]').addEventListener('click', function () { node.close(); }); + node.addEventListener('click', function (event) { if (event.target === node) node.close(); }); + return node; + } + + function storageRow(storage) { + storage = storage || {}; + return '
' + + '' + + '' + + '' + + '
'; + } + + function openEditor(id) { + var editDialog = dialog(); + var content = editDialog.querySelector('[data-edit-v2-content]'); + content.innerHTML = '

Verbindung wird geladen …

'; + if (typeof editDialog.showModal === 'function') editDialog.showModal(); + else editDialog.setAttribute('open', 'open'); + + loadConnection(id).then(function (data) { + if (data.adapter !== 'local') throw new Error('Diese Ansicht ist nur für die bestehende Legacy-Verbindung vorgesehen.'); + var legacy = data.legacy || {}; + var webdav = data.webdav || {}; + var storages = Array.isArray(legacy.storages) ? legacy.storages : []; + var rows = storages.map(storageRow).join('') || storageRow({}); + var migrationText = webdav.migration_ready + ? 'Bereit. Nextcloud-Zugang und verbindungseigener Piwigo-API-Key sind vollständig gespeichert.' + : 'Noch nicht bereit. Es fehlen: '+escapeHtml((webdav.migration_missing || []).join(', ') || 'WebDAV-Zugangsdaten')+'.'; + + content.innerHTML = '
' + + '' + + '' + + '
Verbindung
' + + '' + + '
' + + '
Nextcloud / WebDAV
' + + '

Diese Angaben werden für den neuen WebDAV-Weg benötigt und gehören zu genau dieser Verbindung.

' + + '
' + + '' + + '' + + '' + + '
' + + '
Piwigo API dieser Verbindung
' + + '

Der API-Key wird verbindungseigen gespeichert und beim Speichern geprüft.

' + + '
' + + '' + + '' + + '
' + + '

WebDAV-Migration: '+migrationText+'

' + + '
Bestehender Legacy-Weg
' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
Speicherorte
'+rows+'
' + + '' + + '
Erweiterte Legacy-Einstellungen
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
' + + '
' + + '
'; + + var form = content.querySelector('[data-edit-v2-form]'); + form.querySelector('[data-edit-v2-cancel]').addEventListener('click', function () { editDialog.close(); }); + form.querySelector('[data-add-storage]').addEventListener('click', function () { + form.querySelector('[data-storage-list]').insertAdjacentHTML('beforeend', storageRow({})); + }); + form.addEventListener('click', function (event) { + var remove = event.target.closest('[data-remove-storage]'); + if (!remove) return; + var row = remove.closest('[data-storage-row]'); + if (row) row.remove(); + }); + }).catch(function (error) { + content.innerHTML = '

Bearbeiten nicht möglich: '+escapeHtml(error.message || String(error))+'

'; + }); + } + + function rebuildLocalActions(deleteForm, id) { + 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"]'); + if (migrate) 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); + + loadConnection(id).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 = 'WebDAV-Migration noch nicht bereit: '+(missing || 'Zugangsdaten fehlen')+'. Zuerst „Bearbeiten“.'; + } + }).catch(function (error) { + info.textContent = 'WebDAV-Migration kann nicht geprüft werden: '+(error.message || String(error)); + }); + } + + [].slice.call(section.querySelectorAll('button[value="nc_connector_delete"]')).forEach(function (deleteButton) { + var deleteForm = deleteButton.closest('form'); + var card = deleteButton.closest('details'); + if (!deleteForm || !card) return; + var idInput = deleteForm.querySelector('input[name="connection_id"]'); + if (!idInput) return; + var text = card.textContent || ''; + var isLocal = text.indexOf('bestehende Legacy-Konfiguration') !== -1; + if (isLocal) rebuildLocalActions(deleteForm, idInput.value); + }); + }); +})();