From fdf45840281720cd2a4ed3fad93a6c5e6c14d9b8 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 13:56:59 +0200 Subject: [PATCH 1/3] 0.9.6.11 keep connection editor open on validation errors --- nc-connector-edit-save.php | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 nc-connector-edit-save.php diff --git a/nc-connector-edit-save.php b/nc-connector-edit-save.php new file mode 100644 index 0000000..2f6f0c0 --- /dev/null +++ b/nc-connector-edit-save.php @@ -0,0 +1,80 @@ +false, 'message'=>'Bratonien Tools ist nicht aktiv.', 'fields'=>array())); +} +if (!function_exists('is_admin') || !is_admin()) +{ + bratonien_tools_nc_edit_json(403, array('ok'=>false, 'message'=>'Administratorrechte erforderlich.', 'fields'=>array())); +} +if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') +{ + bratonien_tools_nc_edit_json(405, array('ok'=>false, 'message'=>'Nur POST ist erlaubt.', 'fields'=>array())); +} + +try +{ + check_pwg_token(); + require_once(BRATONIEN_TOOLS_PATH.'include/tool_registry.inc.php'); + $result = bratonien_tools_nc_connector_update_local_friendly(); + bratonien_tools_nc_edit_json(200, array( + 'ok'=>true, + 'message'=>(string)($result['message'] ?? 'Verbindung wurde gespeichert.'), + 'fields'=>array(), + )); +} +catch (Throwable $e) +{ + $message = trim($e->getMessage()); + if ($message === '') $message = 'Die Verbindung konnte nicht gespeichert werden.'; + + $fields = array(); + $add = function($name) use (&$fields) + { + if (!in_array($name, $fields, true)) $fields[] = $name; + }; + + if (stripos($message, 'Name') !== false && stripos($message, 'Datenbankname') === false) $add('connection_name'); + if (stripos($message, 'Datenbank-Server') !== false) $add('nc_host'); + if (stripos($message, 'Datenbank-Port') !== false) $add('nc_port'); + if (stripos($message, 'Datenbankname') !== false) $add('nc_database'); + if (stripos($message, 'Reader-Benutzer') !== false) $add('nc_user'); + if (stripos($message, 'Datenbankpasswort') !== false) $add('nc_db_password'); + if (stripos($message, 'Storage-ID') !== false) $add('nc_storage_id[]'); + if (stripos($message, 'lokaler Pfad') !== false || stripos($message, 'Speicherort') !== false) $add('nc_local_mount[]'); + if (stripos($message, 'Galerieordner') !== false) $add('nc_gallery_root'); + if (stripos($message, 'Datenbankansichten') !== false || stripos($message, 'Source-View') !== false) $add('nc_source_view'); + if (stripos($message, 'Datenbankansichten') !== false || stripos($message, 'Activity-View') !== false) $add('nc_activity_view'); + + if (stripos($message, 'Nextcloud-Adresse') !== false || stripos($message, 'Unter dieser Adresse') !== false) $add('nc_nextcloud_url'); + if (stripos($message, 'Nextcloud-Benutzer') !== false || stripos($message, 'Benutzername oder Passwort') !== false || stripos($message, 'Benutzerzugang') !== false) $add('nc_nextcloud_user'); + if (stripos($message, 'Nextcloud-Passwort') !== false || stripos($message, 'Benutzername oder Passwort') !== false || stripos($message, 'Benutzerzugang') !== false) $add('nc_nextcloud_password'); + + if (stripos($message, 'API-Schluessel-ID') !== false || stripos($message, 'API-Key') !== false) $add('nc_connection_api_key_id'); + if (stripos($message, 'API-Geheimnis') !== false || stripos($message, 'API-Key') !== false) $add('nc_connection_api_key_secret'); + + bratonien_tools_nc_edit_json(422, array( + 'ok'=>false, + 'message'=>$message, + 'fields'=>$fields, + )); +} From 5b48e1f6f212b48b7303dec843f2a5f8a93292f4 Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 13:57:39 +0200 Subject: [PATCH 2/3] 0.9.6.11 keep edit dialog open and mark invalid fields --- js/nc_connector_edit_v2.js | 90 +++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/js/nc_connector_edit_v2.js b/js/nc_connector_edit_v2.js index 59966ac..8c6abd7 100644 --- a/js/nc_connector_edit_v2.js +++ b/js/nc_connector_edit_v2.js @@ -78,6 +78,89 @@ + ''; } + function clearValidation(form) { + [].slice.call(form.querySelectorAll('[aria-invalid="true"]')).forEach(function (field) { + field.removeAttribute('aria-invalid'); + field.style.borderColor = ''; + field.style.boxShadow = ''; + }); + [].slice.call(form.querySelectorAll('[data-edit-v2-field-error]')).forEach(function (node) { node.remove(); }); + var box = form.querySelector('[data-edit-v2-error-summary]'); + if (box) box.remove(); + } + + function fieldNodes(form, fieldName) { + 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 = 'Speichern fehlgeschlagen: '+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; + + var submit = form.querySelector('button[type="submit"]'); + if (submit) submit.disabled = true; + + var body = new FormData(form); + fetch('plugins/bratonien_tools/nc-connector-edit-save.php', { + method:'POST', + credentials:'same-origin', + cache:'no-store', + headers:{'Accept':'application/json'}, + body:body + }).then(function (response) { + return response.json().then(function (data) { + if (!response.ok || !data.ok) { + showValidation(form, data); + return; + } + editDialog.close(); + window.location.reload(); + }); + }).catch(function (error) { + showValidation(form, {message:error.message || String(error), fields:[]}); + }).finally(function () { + if (submit) submit.disabled = false; + }); + } + function openEditor(id) { var editDialog = dialog(); var content = editDialog.querySelector('[data-edit-v2-content]'); @@ -132,7 +215,7 @@ + '' + '' + '' - + '
' + + '
' + ''; var form = content.querySelector('[data-edit-v2-form]'); @@ -146,6 +229,11 @@ var row = remove.closest('[data-storage-row]'); if (row) row.remove(); }); + form.addEventListener('submit', function (event) { + event.preventDefault(); + event.stopPropagation(); + submitEditor(form, editDialog); + }); }).catch(function (error) { content.innerHTML = '

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

'; }); From 898f9b1bc95fb3a6460e5f5d1f1077301927e9bb Mon Sep 17 00:00:00 2001 From: Terranom674 Date: Wed, 19 Aug 2026 13:58:08 +0200 Subject: [PATCH 3/3] 0.9.6.11 bump version for dialog validation --- main.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.inc.php b/main.inc.php index f9896a1..ea2640f 100644 --- a/main.inc.php +++ b/main.inc.php @@ -1,7 +1,7 @@