Skip to content

Commit 14f0473

Browse files
committed
Refactor Notifications settings form to capture actual form state as baseline for change detection. Remove reliance on default values and enhance initialization logic for improved user experience.
1 parent 4ad06a2 commit 14f0473

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

frontend/static/js/settings_forms.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,18 +2561,8 @@ const SettingsForms = {
25612561
window.notificationsUnsavedChanges = false;
25622562
this.removeUnsavedChangesWarning();
25632563

2564-
// Ensure originalSettings has the same defaults used in form generation
2565-
// This prevents mismatches between form display values and change detection
2566-
const normalizedSettings = {
2567-
enable_notifications: originalSettings.enable_notifications !== undefined ? originalSettings.enable_notifications : false,
2568-
notification_level: originalSettings.notification_level || 'warning',
2569-
apprise_urls: originalSettings.apprise_urls || [],
2570-
notify_on_missing: originalSettings.notify_on_missing !== undefined ? originalSettings.notify_on_missing : true,
2571-
notify_on_upgrade: originalSettings.notify_on_upgrade !== undefined ? originalSettings.notify_on_upgrade : true,
2572-
notification_include_instance: originalSettings.notification_include_instance !== undefined ? originalSettings.notification_include_instance : true,
2573-
notification_include_app: originalSettings.notification_include_app !== undefined ? originalSettings.notification_include_app : true,
2574-
...originalSettings // Keep any other settings that might exist
2575-
};
2564+
// Capture the actual form state as baseline instead of guessing defaults
2565+
let normalizedSettings = {};
25762566

25772567
// Initialize button in disabled/grey state immediately
25782568
saveButton.disabled = true;
@@ -2717,10 +2707,30 @@ const SettingsForms = {
27172707
}
27182708
});
27192709

2720-
// Initial change detection - ensure form is fully loaded before checking
2710+
// Initial setup - capture actual form state as baseline
27212711
// Use a longer timeout to ensure all form elements are properly initialized
27222712
setTimeout(() => {
2723-
console.log('[SettingsForms] Initializing notifications form baseline');
2713+
console.log('[SettingsForms] Capturing actual form state as notifications baseline');
2714+
2715+
// Capture the current form state as our baseline instead of guessing defaults
2716+
const inputs = container.querySelectorAll('input, select, textarea');
2717+
inputs.forEach(input => {
2718+
if (!input.id || input.disabled) return;
2719+
2720+
let value;
2721+
if (input.type === 'checkbox') {
2722+
value = input.checked;
2723+
} else if (input.type === 'number') {
2724+
value = parseInt(input.value) || 0;
2725+
} else if (input.id === 'apprise_urls') {
2726+
// Special handling for textarea - convert to array for comparison
2727+
value = input.value.split('\n').map(url => url.trim()).filter(url => url.length > 0);
2728+
} else {
2729+
value = input.value.trim();
2730+
}
2731+
2732+
normalizedSettings[input.id] = value;
2733+
});
27242734

27252735
// Force button to grey state and clear any changes
27262736
saveButton.disabled = true;
@@ -2731,12 +2741,9 @@ const SettingsForms = {
27312741
window.notificationsUnsavedChanges = false;
27322742
hasChanges = false;
27332743

2734-
// Enable change detection now that form is properly initialized
2744+
// Enable change detection now that baseline is captured
27352745
suppressInitialDetection = false;
2736-
console.log('[SettingsForms] Notifications change detection enabled - button should remain grey unless changes made');
2737-
2738-
// Run one final change detection to confirm no changes detected
2739-
detectChanges();
2746+
console.log('[SettingsForms] Notifications baseline captured, change detection enabled');
27402747
}, 500);
27412748
},
27422749

0 commit comments

Comments
 (0)