|
4 | 4 | // Free settings page |
5 | 5 | ?> |
6 | 6 | <div class="pp-content"> |
| 7 | + <?php if (isset($_GET['updated']) && $_GET['updated'] === 'true'): ?> |
| 8 | + <div class="notice notice-success is-dismissible" style="margin: 20px 0; padding: 12px 20px; background: #d4edda; border: 1px solid #c3e6cb; border-radius: 4px; color: #155724;"> |
| 9 | + <strong>Settings saved successfully!</strong> Your Path Pilot configuration has been updated. |
| 10 | + </div> |
| 11 | + <?php endif; ?> |
| 12 | + |
7 | 13 | <form method="post" action="<?php echo esc_url(admin_url('admin-post.php')); ?>" id="path-pilot-settings-form"> |
8 | 14 | <input type="hidden" name="action" value="path_pilot_save_settings"> |
9 | 15 | <?php wp_nonce_field('path_pilot_save_settings'); ?> |
10 | 16 | <?php include plugin_dir_path(__DIR__) . 'common/settings-common.php'; ?> |
11 | 17 | <?php |
12 | 18 | do_action('path_pilot_additional_settings'); |
13 | 19 | ?> |
14 | | - <button type="submit" class="btn btn-primary" style="padding:12px 24px;font-weight:600;font-size:1rem;">Save Settings</button> |
| 20 | + <button type="submit" class="btn btn-primary" id="save-settings-btn" style="padding:12px 24px;font-weight:600;font-size:1rem;">Save Settings</button> |
15 | 21 | </form> |
| 22 | + |
| 23 | + <!-- Loading overlay --> |
| 24 | + <div id="pp-loading-overlay" style="display:none;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:9999;justify-content:center;align-items:center;"> |
| 25 | + <div style="background:#fff;padding:30px;border-radius:8px;text-align:center;box-shadow:0 4px 20px rgba(0,0,0,0.3);"> |
| 26 | + <div style="width:40px;height:40px;border:4px solid #f3f3f3;border-top:4px solid #1976d2;border-radius:50%;animation:spin 1s linear infinite;margin:0 auto 15px;"></div> |
| 27 | + <div style="font-size:16px;font-weight:600;color:#333;">Saving Settings...</div> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + |
| 31 | + <style> |
| 32 | + @keyframes spin { |
| 33 | + 0% { transform: rotate(0deg); } |
| 34 | + 100% { transform: rotate(360deg); } |
| 35 | + } |
| 36 | + </style> |
| 37 | + |
| 38 | + <script> |
| 39 | + document.addEventListener('DOMContentLoaded', function() { |
| 40 | + var form = document.getElementById('path-pilot-settings-form'); |
| 41 | + var saveBtn = document.getElementById('save-settings-btn'); |
| 42 | + var overlay = document.getElementById('pp-loading-overlay'); |
| 43 | + |
| 44 | + if (form && saveBtn && overlay) { |
| 45 | + form.addEventListener('submit', function(e) { |
| 46 | + // Show loading overlay |
| 47 | + overlay.style.display = 'flex'; |
| 48 | + |
| 49 | + // Disable save button to prevent double submission |
| 50 | + saveBtn.disabled = true; |
| 51 | + saveBtn.textContent = 'Saving...'; |
| 52 | + |
| 53 | + // Hide overlay after 30 seconds as fallback (in case redirect doesn't work) |
| 54 | + setTimeout(function() { |
| 55 | + overlay.style.display = 'none'; |
| 56 | + saveBtn.disabled = false; |
| 57 | + saveBtn.textContent = 'Save Settings'; |
| 58 | + |
| 59 | + // Show error message |
| 60 | + var errorDiv = document.createElement('div'); |
| 61 | + errorDiv.style.cssText = 'margin: 20px 0; padding: 12px 20px; background: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px; color: #721c24;'; |
| 62 | + errorDiv.innerHTML = '<strong>Request timed out.</strong> The settings may not have been saved. Please try again.'; |
| 63 | + |
| 64 | + // Insert error message before the form |
| 65 | + form.parentNode.insertBefore(errorDiv, form); |
| 66 | + |
| 67 | + // Remove error message after 10 seconds |
| 68 | + setTimeout(function() { |
| 69 | + if (errorDiv.parentNode) { |
| 70 | + errorDiv.parentNode.removeChild(errorDiv); |
| 71 | + } |
| 72 | + }, 10000); |
| 73 | + }, 30000); |
| 74 | + }); |
| 75 | + } |
| 76 | + }); |
| 77 | + </script> |
16 | 78 | </div> |
0 commit comments