@@ -58,7 +58,7 @@ const SettingsForms = {
58
58
// Add save button at the top
59
59
let sonarrSaveButtonHtml = `
60
60
<div style="margin-bottom: 20px;">
61
- <button type="button" id="saveSonarrButton " disabled style="
61
+ <button type="button" id="sonarr-save-button " disabled style="
62
62
background: #6b7280;
63
63
color: #9ca3af;
64
64
border: 1px solid #4b5563;
@@ -577,7 +577,7 @@ const SettingsForms = {
577
577
// Add save button at the top
578
578
let radarrSaveButtonHtml = `
579
579
<div style="margin-bottom: 20px;">
580
- <button type="button" id="saveRadarrButton " disabled style="
580
+ <button type="button" id="radarr-save-button " disabled style="
581
581
background: #6b7280;
582
582
color: #9ca3af;
583
583
border: 1px solid #4b5563;
@@ -933,7 +933,7 @@ const SettingsForms = {
933
933
// Add save button at the top
934
934
let lidarrSaveButtonHtml = `
935
935
<div style="margin-bottom: 20px;">
936
- <button type="button" id="saveLidarrButton " disabled style="
936
+ <button type="button" id="lidarr-save-button " disabled style="
937
937
background: #6b7280;
938
938
color: #9ca3af;
939
939
border: 1px solid #4b5563;
@@ -2957,30 +2957,61 @@ const SettingsForms = {
2957
2957
saveButton . innerHTML = '<i class="fas fa-spinner fa-spin"></i> Saving...' ;
2958
2958
saveButton . disabled = true ;
2959
2959
2960
- // Use the apps module save functionality
2961
- if ( window . appsModule && window . appsModule . saveAppSettings ) {
2962
- const appPanel = container . closest ( '.app-apps-panel' ) || document . getElementById ( `${ appType } Apps` ) ;
2963
- if ( appPanel ) {
2964
- window . appsModule . saveAppSettings ( appType , appPanel ) ;
2965
-
2966
- // Wait a bit then reset button state (the apps module will handle success/error)
2967
- setTimeout ( ( ) => {
2968
- saveButton . innerHTML = '<i class="fas fa-save"></i> Save Changes' ;
2969
- updateSaveButtonState ( false ) ;
2970
-
2971
- // Update baseline after successful save
2972
- captureFormBaseline ( ) ;
2973
- } , 1000 ) ;
2974
- } else {
2975
- console . error ( `[SettingsForms] Could not find app panel for ${ appType } ` ) ;
2976
- saveButton . innerHTML = '<i class="fas fa-save"></i> Save Changes' ;
2977
- updateSaveButtonState ( hasChanges ) ;
2978
- }
2979
- } else {
2980
- console . error ( '[SettingsForms] Apps module save function not available' ) ;
2960
+ // Collect form settings
2961
+ let settings ;
2962
+ try {
2963
+ settings = SettingsForms . getFormSettings ( container , appType ) ;
2964
+ console . log ( `[SettingsForms] Collected ${ appType } settings:` , settings ) ;
2965
+ } catch ( error ) {
2966
+ console . error ( `[SettingsForms] Error collecting ${ appType } settings:` , error ) ;
2981
2967
saveButton . innerHTML = '<i class="fas fa-save"></i> Save Changes' ;
2982
2968
updateSaveButtonState ( hasChanges ) ;
2969
+ return ;
2983
2970
}
2971
+
2972
+ // Save settings to server
2973
+ HuntarrUtils . fetchWithTimeout ( `./api/settings/${ appType } ` , {
2974
+ method : 'POST' ,
2975
+ headers : {
2976
+ 'Content-Type' : 'application/json'
2977
+ } ,
2978
+ body : JSON . stringify ( settings )
2979
+ } )
2980
+ . then ( response => {
2981
+ if ( ! response . ok ) {
2982
+ throw new Error ( `HTTP error ${ response . status } : ${ response . statusText } ` ) ;
2983
+ }
2984
+ return response . json ( ) ;
2985
+ } )
2986
+ . then ( data => {
2987
+ console . log ( `[SettingsForms] ${ appType } settings saved successfully:` , data ) ;
2988
+
2989
+ // Reset button state and clear unsaved changes warning
2990
+ saveButton . innerHTML = '<i class="fas fa-save"></i> Save Changes' ;
2991
+ updateSaveButtonState ( false ) ;
2992
+
2993
+ // Update baseline after successful save
2994
+ captureFormBaseline ( ) ;
2995
+
2996
+ // Show success notification
2997
+ if ( typeof huntarrUI !== 'undefined' && typeof huntarrUI . showNotification === 'function' ) {
2998
+ huntarrUI . showNotification ( `${ appType . charAt ( 0 ) . toUpperCase ( ) + appType . slice ( 1 ) } settings saved successfully` , 'success' ) ;
2999
+ }
3000
+ } )
3001
+ . catch ( error => {
3002
+ console . error ( `[SettingsForms] Error saving ${ appType } settings:` , error ) ;
3003
+
3004
+ // Reset button state but keep changes detected
3005
+ saveButton . innerHTML = '<i class="fas fa-save"></i> Save Changes' ;
3006
+ updateSaveButtonState ( hasChanges ) ;
3007
+
3008
+ // Show error notification
3009
+ if ( typeof huntarrUI !== 'undefined' && typeof huntarrUI . showNotification === 'function' ) {
3010
+ huntarrUI . showNotification ( `Error saving ${ appType } settings: ${ error . message } ` , 'error' ) ;
3011
+ } else {
3012
+ alert ( `Error saving ${ appType } settings: ${ error . message } ` ) ;
3013
+ }
3014
+ } ) ;
2984
3015
} ) ;
2985
3016
2986
3017
// Function to capture current form state as baseline
0 commit comments