File size: 7,922 Bytes
c024705
5d9430a
c024705
 
 
5d9430a
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
c024705
 
 
5d9430a
 
 
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
 
c024705
5d9430a
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c024705
5d9430a
 
 
 
 
 
 
 
 
 
 
c024705
 
5d9430a
c024705
5d9430a
 
 
 
 
 
 
c024705
5d9430a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
 * AIMHSA Configuration UI Management
 * Provides UI components for managing frontend configuration
 */

window.AIMHSA = window.AIMHSA || {};

// Configuration UI class for managing settings interface
class AIMHSAConfigUI {
    constructor() {
        this.isInitialized = false;
        this.settingsModal = null;
    }
    
    init() {
        if (this.isInitialized) return;
        
        this.createSettingsModal();
        this.bindEvents();
        this.isInitialized = true;
    }
    
    createSettingsModal() {
        // Create settings modal HTML
        const modalHTML = `
            <div id="aimhsa-settings-modal" class="modal fade" tabindex="-1" role="dialog">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title">AIMHSA Settings</h5>
                            <button type="button" class="close" data-dismiss="modal">
                                <span>&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="aimhsa-settings-form">
                                <div class="form-group">
                                    <label for="api-base-url">API Base URL</label>
                                    <input type="url" class="form-control" id="api-base-url" 
                                           placeholder="https://your-domain.com">
                                    <small class="form-text text-muted">
                                        Base URL for API requests. Leave empty for auto-detection.
                                    </small>
                                </div>
                                
                                <div class="form-group">
                                    <label for="environment">Environment</label>
                                    <select class="form-control" id="environment">
                                        <option value="production">Production</option>
                                        <option value="development">Development</option>
                                        <option value="staging">Staging</option>
                                    </select>
                                </div>
                                
                                <div class="form-group">
                                    <div class="custom-control custom-checkbox">
                                        <input type="checkbox" class="custom-control-input" id="debug-mode">
                                        <label class="custom-control-label" for="debug-mode">
                                            Enable Debug Mode
                                        </label>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                            <button type="button" class="btn btn-danger" id="reset-config">Reset to Defaults</button>
                            <button type="button" class="btn btn-primary" id="save-config">Save Changes</button>
                        </div>
                    </div>
                </div>
            </div>
        `;
        
        // Append to body if not exists
        if (!document.getElementById('aimhsa-settings-modal')) {
            document.body.insertAdjacentHTML('beforeend', modalHTML);
        }
        
        this.settingsModal = document.getElementById('aimhsa-settings-modal');
    }
    
    bindEvents() {
        // Save configuration
        const saveBtn = document.getElementById('save-config');
        if (saveBtn) {
            saveBtn.addEventListener('click', () => this.saveConfiguration());
        }
        
        // Reset configuration
        const resetBtn = document.getElementById('reset-config');
        if (resetBtn) {
            resetBtn.addEventListener('click', () => this.resetConfiguration());
        }
        
        // Load configuration when modal opens
        if (this.settingsModal) {
            this.settingsModal.addEventListener('show.bs.modal', () => this.loadConfiguration());
        }
    }
    
    loadConfiguration() {
        const config = window.AIMHSA.Config;
        
        // Populate form fields
        const apiUrlField = document.getElementById('api-base-url');
        const environmentField = document.getElementById('environment');
        const debugModeField = document.getElementById('debug-mode');
        
        if (apiUrlField) apiUrlField.value = config.get('apiBaseUrl') || '';
        if (environmentField) environmentField.value = config.get('environment') || 'production';
        if (debugModeField) debugModeField.checked = config.get('debugMode') || false;
    }
    
    saveConfiguration() {
        const config = window.AIMHSA.Config;
        
        // Get form values
        const apiUrl = document.getElementById('api-base-url')?.value?.trim();
        const environment = document.getElementById('environment')?.value;
        const debugMode = document.getElementById('debug-mode')?.checked;
        
        // Update configuration
        if (apiUrl) config.set('apiBaseUrl', apiUrl);
        config.set('environment', environment);
        config.set('debugMode', debugMode);
        
        // Show success message
        this.showNotification('Configuration saved successfully!', 'success');
        
        // Close modal
        if (window.jQuery && window.jQuery.fn.modal) {
            window.jQuery(this.settingsModal).modal('hide');
        }
        
        // Refresh page to apply changes
        setTimeout(() => {
            window.location.reload();
        }, 1000);
    }
    
    resetConfiguration() {
        if (confirm('Are you sure you want to reset all settings to defaults?')) {
            window.AIMHSA.Config.reset();
            this.loadConfiguration();
            this.showNotification('Configuration reset to defaults!', 'info');
        }
    }
    
    showNotification(message, type = 'info') {
        // Create notification element
        const notification = document.createElement('div');
        notification.className = `alert alert-${type} alert-dismissible fade show`;
        notification.style.cssText = `
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 9999;
            min-width: 300px;
        `;
        notification.innerHTML = `
            ${message}
            <button type="button" class="close" data-dismiss="alert">
                <span>&times;</span>
            </button>
        `;
        
        document.body.appendChild(notification);
        
        // Auto-remove after 3 seconds
        setTimeout(() => {
            if (notification.parentNode) {
                notification.parentNode.removeChild(notification);
            }
        }, 3000);
    }
    
    openSettings() {
        if (!this.isInitialized) this.init();
        
        if (window.jQuery && window.jQuery.fn.modal) {
            window.jQuery(this.settingsModal).modal('show');
        } else {
            // Fallback for non-Bootstrap environments
            this.settingsModal.style.display = 'block';
        }
    }
}

// Initialize global configuration UI
window.AIMHSA.ConfigUI = new AIMHSAConfigUI();

// Auto-initialize when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
    window.AIMHSA.ConfigUI.init();
});

// Export for module systems if available
if (typeof module !== 'undefined' && module.exports) {
    module.exports = AIMHSAConfigUI;
}