| @@ -12,253 +12,256 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @since Phase 5 |
| 14 | 14 | */ |
| 15 | 15 | jQuery(document).ready(function ($) { |
| 16 | - var $form = $('#metasync-execution-settings-form'); | |
| 17 | - var $saveBtn = $('#metasync-execution-settings-save-btn'); | |
| 18 | - var $message = $('#metasync-execution-settings-message'); | |
| 16 | + var $form = $('#metasync-execution-settings-form'); | |
| 17 | + var $saveBtn = $('#metasync-execution-settings-save-btn'); | |
| 18 | + var $message = $('#metasync-execution-settings-message'); | |
| 19 | 19 | |
| 20 | - // Server limit values from localized data | |
| 21 | - var serverMaxExecTime = metasyncExecSettingsData.serverMaxExecTime; | |
| 22 | - var serverMaxMemory = metasyncExecSettingsData.serverMaxMemory; | |
| 23 | - var canChangeMemory = metasyncExecSettingsData.canChangeMemory; | |
| 20 | + // Server limit values from localized data | |
| 21 | + var serverMaxExecTime = metasyncExecSettingsData.serverMaxExecTime; | |
| 22 | + var serverMaxMemory = metasyncExecSettingsData.serverMaxMemory; | |
| 23 | + var canChangeMemory = metasyncExecSettingsData.canChangeMemory; | |
| 24 | 24 | |
| 25 | - // Normalize string 'Infinity' to JS Infinity | |
| 26 | - if (serverMaxExecTime === 'Infinity') { | |
| 27 | - serverMaxExecTime = Infinity; | |
| 28 | - } | |
| 29 | - if (serverMaxMemory === 'Infinity') { | |
| 30 | - serverMaxMemory = Infinity; | |
| 31 | - } | |
| 25 | + // Normalize to numbers ('Infinity' marker -> JS Infinity). wp_localize_script | |
| 26 | + // casts every scalar to a string, so these arrive as e.g. "2048"; comparing a | |
| 27 | + // string field value against a string limit ("256" > "2048") would be | |
| 28 | + // lexicographic and wrong, so coerce to numbers here. | |
| 29 | + serverMaxExecTime = (serverMaxExecTime === 'Infinity') ? Infinity : parseInt(serverMaxExecTime, 10); | |
| 30 | + serverMaxMemory = (serverMaxMemory === 'Infinity') ? Infinity : parseInt(serverMaxMemory, 10); | |
| 32 | 31 | |
| 33 | - // Real-time validation for server limits | |
| 34 | - function checkServerLimits() { | |
| 35 | - var maxExecTime = parseInt($('#max_execution_time').val()) || 0; | |
| 36 | - var maxMemory = parseInt($('#max_memory_limit').val()) || 0; | |
| 32 | + // Real-time validation for server limits | |
| 33 | + function checkServerLimits() { | |
| 34 | + var maxExecTime = parseInt($('#max_execution_time').val()) || 0; | |
| 35 | + var maxMemory = parseInt($('#max_memory_limit').val()) || 0; | |
| 37 | 36 | |
| 38 | - // Check execution time limit | |
| 39 | - if (serverMaxExecTime !== Infinity && maxExecTime > serverMaxExecTime) { | |
| 40 | - $('#max_execution_time_warning').show(); | |
| 41 | - } else { | |
| 42 | - $('#max_execution_time_warning').hide(); | |
| 43 | - } | |
| 37 | + // Check execution time limit | |
| 38 | + if (serverMaxExecTime !== Infinity && maxExecTime > serverMaxExecTime) { | |
| 39 | + $('#max_execution_time_warning').show(); | |
| 40 | + } else { | |
| 41 | + $('#max_execution_time_warning').hide(); | |
| 42 | + } | |
| 44 | 43 | |
| 45 | - // Check memory limit (only if server allows changing it) | |
| 46 | - if (canChangeMemory && serverMaxMemory !== Infinity && maxMemory > serverMaxMemory) { | |
| 47 | - $('#max_memory_limit_warning').show(); | |
| 48 | - } else { | |
| 49 | - $('#max_memory_limit_warning').hide(); | |
| 50 | - } | |
| 51 | - } | |
| 44 | + // Check memory limit (only if server allows changing it) | |
| 45 | + if (canChangeMemory && serverMaxMemory !== Infinity && maxMemory > serverMaxMemory) { | |
| 46 | + $('#max_memory_limit_warning').show(); | |
| 47 | + } else { | |
| 48 | + $('#max_memory_limit_warning').hide(); | |
| 49 | + } | |
| 50 | + } | |
| 52 | 51 | |
| 53 | - // Real-time validation on input change | |
| 54 | - $('#max_execution_time, #max_memory_limit').on('input change', function () { | |
| 55 | - checkServerLimits(); | |
| 56 | - // Remove error styling when user starts typing | |
| 57 | - $(this).css('border-color', 'var(--dashboard-border)'); | |
| 58 | - }); | |
| 52 | + // Real-time validation on input change | |
| 53 | + $('#max_execution_time, #max_memory_limit').on('input change', function () { | |
| 54 | + checkServerLimits(); | |
| 55 | + // Remove error styling when user starts typing | |
| 56 | + $(this).css('border-color', 'var(--dashboard-border)'); | |
| 57 | + }); | |
| 59 | 58 | |
| 60 | - // Add visual feedback for invalid inputs | |
| 61 | - function highlightInvalidField($field, isValid) { | |
| 62 | - if (isValid) { | |
| 63 | - $field.css({ | |
| 64 | - 'border-color': 'var(--dashboard-border)', | |
| 65 | - 'box-shadow': 'none' | |
| 66 | - }); | |
| 67 | - } else { | |
| 68 | - $field.css({ | |
| 69 | - 'border-color': '#ef4444', | |
| 70 | - 'box-shadow': '0 0 0 3px rgba(239, 68, 68, 0.1)' | |
| 71 | - }); | |
| 72 | - } | |
| 73 | - } | |
| 59 | + // Add visual feedback for invalid inputs | |
| 60 | + function highlightInvalidField($field, isValid) { | |
| 61 | + if (isValid) { | |
| 62 | + $field.css({ | |
| 63 | + 'border-color': 'var(--dashboard-border)', | |
| 64 | + 'box-shadow': 'none' | |
| 65 | + }); | |
| 66 | + } else { | |
| 67 | + $field.css({ | |
| 68 | + 'border-color': '#ef4444', | |
| 69 | + 'box-shadow': '0 0 0 3px rgba(239, 68, 68, 0.1)' | |
| 70 | + }); | |
| 71 | + } | |
| 72 | + } | |
| 74 | 73 | |
| 75 | - // Validate individual fields on blur | |
| 76 | - $('#max_execution_time').on('blur', function () { | |
| 77 | - var value = parseInt($(this).val()) || 0; | |
| 78 | - var isValid = value >= 1 && value <= 300 && (serverMaxExecTime === Infinity || value <= serverMaxExecTime); | |
| 79 | - highlightInvalidField($(this), isValid); | |
| 80 | - }); | |
| 74 | + // Validate individual fields on blur | |
| 75 | + $('#max_execution_time').on('blur', function () { | |
| 76 | + var value = parseInt($(this).val()) || 0; | |
| 77 | + var isValid = value >= 1 && value <= 300 && (serverMaxExecTime === Infinity || value <= serverMaxExecTime); | |
| 78 | + highlightInvalidField($(this), isValid); | |
| 79 | + }); | |
| 81 | 80 | |
| 82 | - $('#max_memory_limit').on('blur', function () { | |
| 83 | - if (!canChangeMemory) return; | |
| 84 | - var value = parseInt($(this).val()) || 0; | |
| 85 | - var isValid = value >= 64 && value <= 512 && (serverMaxMemory === Infinity || value <= serverMaxMemory); | |
| 86 | - highlightInvalidField($(this), isValid); | |
| 87 | - }); | |
| 81 | + $('#max_memory_limit').on('blur', function () { | |
| 82 | + if (!canChangeMemory) { | |
| 83 | + return; | |
| 84 | + } | |
| 85 | + var value = parseInt($(this).val()) || 0; | |
| 86 | + var isValid = value >= 64 && (serverMaxMemory === Infinity || value <= serverMaxMemory); | |
| 87 | + highlightInvalidField($(this), isValid); | |
| 88 | + }); | |
| 88 | 89 | |
| 89 | - // Initial check on page load | |
| 90 | - checkServerLimits(); | |
| 90 | + // Initial check on page load | |
| 91 | + checkServerLimits(); | |
| 91 | 92 | |
| 92 | - // Save button click (not form submit — form is nested inside #metaSyncGeneralSetting which would double-fire) | |
| 93 | - $saveBtn.on('click', function (e) { | |
| 94 | - e.preventDefault(); | |
| 93 | + // Save button click (not form submit — form is nested inside #metaSyncGeneralSetting which would double-fire) | |
| 94 | + $saveBtn.on('click', function (e) { | |
| 95 | + e.preventDefault(); | |
| 95 | 96 | |
| 96 | - var formData = { | |
| 97 | - action: 'metasync_save_execution_settings', | |
| 98 | - execution_settings_nonce: $('#execution_settings_nonce').val(), | |
| 99 | - max_execution_time: $('#max_execution_time').val(), | |
| 100 | - max_memory_limit: $('#max_memory_limit').val(), | |
| 101 | - log_batch_size: $('#log_batch_size').val(), | |
| 102 | - action_scheduler_batches: $('#action_scheduler_batches').val(), | |
| 103 | - otto_rate_limit: $('#otto_rate_limit').val(), | |
| 104 | - queue_cleanup_days: $('#queue_cleanup_days').val() | |
| 105 | - }; | |
| 97 | + var formData = { | |
| 98 | + action: 'metasync_save_execution_settings', | |
| 99 | + execution_settings_nonce: $('#execution_settings_nonce').val(), | |
| 100 | + max_execution_time: $('#max_execution_time').val(), | |
| 101 | + max_memory_limit: $('#max_memory_limit').val(), | |
| 102 | + log_batch_size: $('#log_batch_size').val(), | |
| 103 | + action_scheduler_batches: $('#action_scheduler_batches').val(), | |
| 104 | + otto_rate_limit: $('#otto_rate_limit').val(), | |
| 105 | + queue_cleanup_days: $('#queue_cleanup_days').val() | |
| 106 | + }; | |
| 106 | 107 | |
| 107 | - // Clear previous error highlights | |
| 108 | - $('input[type="number"]').css({ | |
| 109 | - 'border-color': 'var(--dashboard-border)', | |
| 110 | - 'box-shadow': 'none' | |
| 111 | - }); | |
| 108 | + // Clear previous error highlights | |
| 109 | + $('input[type="number"]').css({ | |
| 110 | + 'border-color': 'var(--dashboard-border)', | |
| 111 | + 'box-shadow': 'none' | |
| 112 | + }); | |
| 112 | 113 | |
| 113 | - // Validate ranges | |
| 114 | - var hasError = false; | |
| 115 | - var errorField = null; | |
| 114 | + // Validate ranges | |
| 115 | + var hasError = false; | |
| 116 | + var errorField = null; | |
| 116 | 117 | |
| 117 | - if (formData.max_execution_time < 1 || formData.max_execution_time > 300) { | |
| 118 | - showMessage('Max Execution Time must be between 1 and 300 seconds.', 'error'); | |
| 119 | - highlightInvalidField($('#max_execution_time'), false); | |
| 120 | - errorField = $('#max_execution_time'); | |
| 121 | - hasError = true; | |
| 122 | - } else if (serverMaxExecTime !== Infinity && formData.max_execution_time > serverMaxExecTime) { | |
| 123 | - showMessage('Max Execution Time exceeds server limit of ' + serverMaxExecTime + ' seconds. Please reduce the value.', 'error'); | |
| 124 | - highlightInvalidField($('#max_execution_time'), false); | |
| 125 | - errorField = $('#max_execution_time'); | |
| 126 | - hasError = true; | |
| 127 | - } | |
| 118 | + if (formData.max_execution_time < 1 || formData.max_execution_time > 300) { | |
| 119 | + showMessage('Max Execution Time must be between 1 and 300 seconds.', 'error'); | |
| 120 | + highlightInvalidField($('#max_execution_time'), false); | |
| 121 | + errorField = $('#max_execution_time'); | |
| 122 | + hasError = true; | |
| 123 | + } else if (serverMaxExecTime !== Infinity && formData.max_execution_time > serverMaxExecTime) { | |
| 124 | + showMessage('Max Execution Time exceeds server limit of ' + serverMaxExecTime + ' seconds. Please reduce the value.', 'error'); | |
| 125 | + highlightInvalidField($('#max_execution_time'), false); | |
| 126 | + errorField = $('#max_execution_time'); | |
| 127 | + hasError = true; | |
| 128 | + } | |
| 128 | 129 | |
| 129 | - // Only validate memory limit if server allows changing it | |
| 130 | - if (canChangeMemory) { | |
| 131 | - if (formData.max_memory_limit < 64 || formData.max_memory_limit > 512) { | |
| 132 | - showMessage('Max Memory Limit must be between 64 and 512 MB.', 'error'); | |
| 133 | - highlightInvalidField($('#max_memory_limit'), false); | |
| 134 | - if (!hasError) { | |
| 135 | - errorField = $('#max_memory_limit'); | |
| 136 | - hasError = true; | |
| 137 | - } | |
| 138 | - } else if (serverMaxMemory !== Infinity && formData.max_memory_limit > serverMaxMemory) { | |
| 139 | - showMessage('Max Memory Limit exceeds server limit of ' + serverMaxMemory + ' MB. Please reduce the value.', 'error'); | |
| 140 | - highlightInvalidField($('#max_memory_limit'), false); | |
| 141 | - if (!hasError) { | |
| 142 | - errorField = $('#max_memory_limit'); | |
| 143 | - hasError = true; | |
| 144 | - } | |
| 145 | - } | |
| 146 | - } | |
| 130 | + // Only validate memory limit if server allows changing it | |
| 131 | + if (canChangeMemory) { | |
| 132 | + if (formData.max_memory_limit < 64) { | |
| 133 | + showMessage('Max Memory Limit must be at least 64 MB.', 'error'); | |
| 134 | + highlightInvalidField($('#max_memory_limit'), false); | |
| 135 | + if (!hasError) { | |
| 136 | + errorField = $('#max_memory_limit'); | |
| 137 | + hasError = true; | |
| 138 | + } | |
| 139 | + } else if (serverMaxMemory !== Infinity && formData.max_memory_limit > serverMaxMemory) { | |
| 140 | + showMessage('Max Memory Limit must be between 64 and ' + serverMaxMemory + ' MB.', 'error'); | |
| 141 | + highlightInvalidField($('#max_memory_limit'), false); | |
| 142 | + if (!hasError) { | |
| 143 | + errorField = $('#max_memory_limit'); | |
| 144 | + hasError = true; | |
| 145 | + } | |
| 146 | + } | |
| 147 | + } | |
| 147 | 148 | |
| 148 | - if (formData.log_batch_size < 100 || formData.log_batch_size > 5000) { | |
| 149 | - showMessage('Log Batch Size must be between 100 and 5000 lines.', 'error'); | |
| 150 | - highlightInvalidField($('#log_batch_size'), false); | |
| 151 | - if (!hasError) { | |
| 152 | - errorField = $('#log_batch_size'); | |
| 153 | - hasError = true; | |
| 154 | - } | |
| 155 | - } | |
| 156 | - if (formData.action_scheduler_batches < 1 || formData.action_scheduler_batches > 10) { | |
| 157 | - showMessage('Action Scheduler Batches must be between 1 and 10.', 'error'); | |
| 158 | - highlightInvalidField($('#action_scheduler_batches'), false); | |
| 159 | - if (!hasError) { | |
| 160 | - errorField = $('#action_scheduler_batches'); | |
| 161 | - hasError = true; | |
| 162 | - } | |
| 163 | - } | |
| 164 | - if (formData.otto_rate_limit < 1 || formData.otto_rate_limit > 60) { | |
| 165 | - showMessage('OTTO Rate Limit must be between 1 and 60 calls per minute.', 'error'); | |
| 166 | - highlightInvalidField($('#otto_rate_limit'), false); | |
| 167 | - if (!hasError) { | |
| 168 | - errorField = $('#otto_rate_limit'); | |
| 169 | - hasError = true; | |
| 170 | - } | |
| 171 | - } | |
| 172 | - if (formData.queue_cleanup_days < 7 || formData.queue_cleanup_days > 90) { | |
| 173 | - showMessage('Queue Cleanup Days must be between 7 and 90 days.', 'error'); | |
| 174 | - highlightInvalidField($('#queue_cleanup_days'), false); | |
| 175 | - if (!hasError) { | |
| 176 | - errorField = $('#queue_cleanup_days'); | |
| 177 | - hasError = true; | |
| 178 | - } | |
| 179 | - } | |
| 149 | + if (formData.log_batch_size < 100 || formData.log_batch_size > 5000) { | |
| 150 | + showMessage('Log Batch Size must be between 100 and 5000 lines.', 'error'); | |
| 151 | + highlightInvalidField($('#log_batch_size'), false); | |
| 152 | + if (!hasError) { | |
| 153 | + errorField = $('#log_batch_size'); | |
| 154 | + hasError = true; | |
| 155 | + } | |
| 156 | + } | |
| 157 | + if (formData.action_scheduler_batches < 1 || formData.action_scheduler_batches > 10) { | |
| 158 | + showMessage('Action Scheduler Batches must be between 1 and 10.', 'error'); | |
| 159 | + highlightInvalidField($('#action_scheduler_batches'), false); | |
| 160 | + if (!hasError) { | |
| 161 | + errorField = $('#action_scheduler_batches'); | |
| 162 | + hasError = true; | |
| 163 | + } | |
| 164 | + } | |
| 165 | + if (formData.otto_rate_limit < 1 || formData.otto_rate_limit > 60) { | |
| 166 | + showMessage('OTTO Rate Limit must be between 1 and 60 calls per minute.', 'error'); | |
| 167 | + highlightInvalidField($('#otto_rate_limit'), false); | |
| 168 | + if (!hasError) { | |
| 169 | + errorField = $('#otto_rate_limit'); | |
| 170 | + hasError = true; | |
| 171 | + } | |
| 172 | + } | |
| 173 | + if (formData.queue_cleanup_days < 7 || formData.queue_cleanup_days > 90) { | |
| 174 | + showMessage('Queue Cleanup Days must be between 7 and 90 days.', 'error'); | |
| 175 | + highlightInvalidField($('#queue_cleanup_days'), false); | |
| 176 | + if (!hasError) { | |
| 177 | + errorField = $('#queue_cleanup_days'); | |
| 178 | + hasError = true; | |
| 179 | + } | |
| 180 | + } | |
| 180 | 181 | |
| 181 | - if (hasError) { | |
| 182 | - if (errorField) { | |
| 183 | - errorField.focus(); | |
| 184 | - // Scroll to error field | |
| 185 | - $('html, body').animate({ | |
| 186 | - scrollTop: errorField.offset().top - 100 | |
| 187 | - }, 300); | |
| 188 | - } | |
| 189 | - return; | |
| 190 | - } | |
| 182 | + if (hasError) { | |
| 183 | + if (errorField) { | |
| 184 | + errorField.focus(); | |
| 185 | + // Scroll to error field | |
| 186 | + $('html, body').animate({ | |
| 187 | + scrollTop: errorField.offset().top - 100 | |
| 188 | + }, 300); | |
| 189 | + } | |
| 190 | + return; | |
| 191 | + } | |
| 191 | 192 | |
| 192 | - // Show loading state | |
| 193 | - $saveBtn.prop('disabled', true); | |
| 194 | - $saveBtn.find('.save-text').text('Saving...'); | |
| 195 | - $saveBtn.find('.save-spinner').show(); | |
| 196 | - $message.hide(); | |
| 193 | + // Show loading state | |
| 194 | + $saveBtn.prop('disabled', true); | |
| 195 | + $saveBtn.find('.save-text').text('Saving...'); | |
| 196 | + $saveBtn.find('.save-spinner').show(); | |
| 197 | + $message.hide(); | |
| 197 | 198 | |
| 198 | - $.ajax({ | |
| 199 | - url: ajaxurl, | |
| 200 | - type: 'POST', | |
| 201 | - data: formData, | |
| 202 | - success: function (response) { | |
| 203 | - if (response.success) { | |
| 204 | - showMessage(response.data.message || 'Settings saved successfully!', 'success'); | |
| 205 | - // Re-enable button | |
| 206 | - $saveBtn.prop('disabled', false); | |
| 207 | - $saveBtn.find('.save-text').text('Save Settings'); | |
| 208 | - $saveBtn.find('.save-spinner').hide(); | |
| 209 | - // Re-check server limits after save | |
| 210 | - setTimeout(function () { | |
| 211 | - checkServerLimits(); | |
| 212 | - }, 100); | |
| 213 | - // Scroll to top to show success message | |
| 214 | - $('html, body').animate({ | |
| 215 | - scrollTop: $form.offset().top - 100 | |
| 216 | - }, 300); | |
| 217 | - } else { | |
| 218 | - showMessage(response.data.message || 'Error saving settings.', 'error'); | |
| 219 | - $saveBtn.prop('disabled', false); | |
| 220 | - $saveBtn.find('.save-text').text('Save Settings'); | |
| 221 | - $saveBtn.find('.save-spinner').hide(); | |
| 222 | - // Scroll to show error message | |
| 223 | - $('html, body').animate({ | |
| 224 | - scrollTop: $message.offset().top - 100 | |
| 225 | - }, 300); | |
| 226 | - } | |
| 227 | - }, | |
| 228 | - error: function () { | |
| 229 | - showMessage('An error occurred while saving settings. Please try again.', 'error'); | |
| 230 | - $saveBtn.prop('disabled', false); | |
| 231 | - $saveBtn.find('.save-text').text('Save Settings'); | |
| 232 | - $saveBtn.find('.save-spinner').hide(); | |
| 233 | - // Scroll to show error message | |
| 234 | - $('html, body').animate({ | |
| 235 | - scrollTop: $message.offset().top - 100 | |
| 236 | - }, 300); | |
| 237 | - } | |
| 238 | - }); | |
| 239 | - }); | |
| 199 | + $.ajax({ | |
| 200 | + url: ajaxurl, | |
| 201 | + type: 'POST', | |
| 202 | + data: formData, | |
| 203 | + success: function (response) { | |
| 204 | + if (response.success) { | |
| 205 | + showMessage(response.data.message || 'Settings saved successfully!', 'success'); | |
| 206 | + // Re-enable button | |
| 207 | + $saveBtn.prop('disabled', false); | |
| 208 | + $saveBtn.find('.save-text').text('Save Settings'); | |
| 209 | + $saveBtn.find('.save-spinner').hide(); | |
| 210 | + // Re-check server limits after save | |
| 211 | + setTimeout(function () { | |
| 212 | + checkServerLimits(); | |
| 213 | + }, 100); | |
| 214 | + // Scroll to top to show success message | |
| 215 | + $('html, body').animate({ | |
| 216 | + scrollTop: $form.offset().top - 100 | |
| 217 | + }, 300); | |
| 218 | + } else { | |
| 219 | + showMessage(response.data.message || 'Error saving settings.', 'error'); | |
| 220 | + $saveBtn.prop('disabled', false); | |
| 221 | + $saveBtn.find('.save-text').text('Save Settings'); | |
| 222 | + $saveBtn.find('.save-spinner').hide(); | |
| 223 | + // Scroll to show error message | |
| 224 | + $('html, body').animate({ | |
| 225 | + scrollTop: $message.offset().top - 100 | |
| 226 | + }, 300); | |
| 227 | + } | |
| 228 | + }, | |
| 229 | + error: function () { | |
| 230 | + showMessage('An error occurred while saving settings. Please try again.', 'error'); | |
| 231 | + $saveBtn.prop('disabled', false); | |
| 232 | + $saveBtn.find('.save-text').text('Save Settings'); | |
| 233 | + $saveBtn.find('.save-spinner').hide(); | |
| 234 | + // Scroll to show error message | |
| 235 | + $('html, body').animate({ | |
| 236 | + scrollTop: $message.offset().top - 100 | |
| 237 | + }, 300); | |
| 238 | + } | |
| 239 | + }); | |
| 240 | + }); | |
| 240 | 241 | |
| 241 | - function showMessage(text, type) { | |
| 242 | - $message.removeClass('notice-success notice-error') | |
| 243 | - .addClass('notice-' + type) | |
| 244 | - .css({ | |
| 245 | - 'background': type === 'success' ? 'rgba(34, 197, 94, 0.1)' : 'rgba(239, 68, 68, 0.1)', | |
| 246 | - 'border': '1px solid ' + (type === 'success' ? 'rgba(34, 197, 94, 0.3)' : 'rgba(239, 68, 68, 0.3)'), | |
| 247 | - 'color': type === 'success' ? '#22c55e' : '#ef4444', | |
| 248 | - 'padding': '12px 16px', | |
| 249 | - 'border-radius': '6px', | |
| 250 | - 'font-size': '14px', | |
| 251 | - 'line-height': '1.5', | |
| 252 | - 'display': 'block' | |
| 253 | - }) | |
| 254 | - .html('<strong style="margin-right: 8px;">' + (type === 'success' ? '\u2713' : '\u2717') + '</strong>' + text) | |
| 255 | - .show(); | |
| 242 | + function showMessage(text, type) { | |
| 243 | + $message.removeClass('notice-success notice-error') | |
| 244 | + .addClass('notice-' + type) | |
| 245 | + .css({ | |
| 246 | + 'background': type === 'success' ? 'rgba(34, 197, 94, 0.1)' : 'rgba(239, 68, 68, 0.1)', | |
| 247 | + 'border': '1px solid ' + (type === 'success' ? 'rgba(34, 197, 94, 0.3)' : 'rgba(239, 68, 68, 0.3)'), | |
| 248 | + 'color': type === 'success' ? '#22c55e' : '#ef4444', | |
| 249 | + 'padding': '12px 16px', | |
| 250 | + 'border-radius': '6px', | |
| 251 | + 'font-size': '14px', | |
| 252 | + 'line-height': '1.5', | |
| 253 | + 'display': 'block' | |
| 254 | + }) | |
| 255 | + .empty() | |
| 256 | + .append($('<strong>').css('margin-right', '8px').text(type === 'success' ? '\u2713' : '\u2717')) | |
| 257 | + .show(); | |
| 258 | + $message[0].appendChild(document.createTextNode(text)); | |
| 256 | 259 | |
| 257 | - // Auto-hide success messages after 5 seconds | |
| 258 | - if (type === 'success') { | |
| 259 | - setTimeout(function () { | |
| 260 | - $message.fadeOut(300); | |
| 261 | - }, 5000); | |
| 262 | - } | |
| 263 | - } | |
| 260 | + // Auto-hide success messages after 5 seconds | |
| 261 | + if (type === 'success') { | |
| 262 | + setTimeout(function () { | |
| 263 | + $message.fadeOut(300); | |
| 264 | + }, 5000); | |
| 265 | + } | |
| 266 | + } | |
| 264 | 267 | }); |