| @@ -114,11 +114,22 @@ | ||
| 114 | 114 | |
| 115 | 115 | function installAndActivateTheme(themeSlug) { |
| 116 | 116 | const button = event.target; |
| 117 | 117 | const originalContent = button.innerHTML; |
| 118 | + const yatraThemeWizardI18n = { | |
| 119 | + installing: <?php echo wp_json_encode(__('Installing...', 'yatra')); ?>, | |
| 120 | + activating: <?php echo wp_json_encode(__('Activating...', 'yatra')); ?>, | |
| 121 | + installationFailedInvalidResponse: <?php echo wp_json_encode(__('Installation failed: Invalid response format', 'yatra')); ?>, | |
| 122 | + activationFailedPrefix: <?php echo wp_json_encode(__('Activation failed:', 'yatra')); ?>, | |
| 123 | + installationFailedPrefix: <?php echo wp_json_encode(__('Installation failed:', 'yatra')); ?>, | |
| 124 | + activationRequestFailed: <?php echo wp_json_encode(__('Activation request failed. Please try again.', 'yatra')); ?>, | |
| 125 | + installationRequestFailed: <?php echo wp_json_encode(__('Installation request failed. Please try again.', 'yatra')); ?>, | |
| 126 | + unknownActivationError: <?php echo wp_json_encode(__('Unknown activation error', 'yatra')); ?>, | |
| 127 | + unknownInstallationError: <?php echo wp_json_encode(__('Unknown installation error', 'yatra')); ?> | |
| 128 | + }; | |
| 118 | 129 | |
| 119 | 130 | // Show loading state with spinner |
| 120 | - button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> Installing...'; | |
| 131 | + button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> ' + yatraThemeWizardI18n.installing; | |
| 121 | 132 | button.disabled = true; |
| 122 | 133 | button.style.cursor = 'not-allowed'; |
| 123 | 134 | button.style.opacity = '0.7'; |
| 124 | 135 | |
| @@ -139,9 +150,9 @@ | ||
| 139 | 150 | theme_slug: themeSlug, |
| 140 | 151 | nonce: '<?php echo wp_create_nonce('yatra_theme_actions'); ?>' |
| 141 | 152 | }, |
| 142 | 153 | success: function(response) { |
| 143 | - console.log('Raw installation response:', response); // Debug log | |
| 154 | + window.YATRA_DEBUG && console.log('Raw installation response:', response); // Debug log | |
| 144 | 155 | |
| 145 | 156 | // Handle case where HTML is mixed with JSON |
| 146 | 157 | let jsonResponse = response; |
| 147 | 158 | if (typeof response === 'string' && response.includes('{')) { |
| @@ -154,9 +165,9 @@ | ||
| 154 | 165 | jsonResponse = JSON.parse(jsonString); |
| 155 | 166 | } catch (e) { |
| 156 | 167 | console.error('Failed to parse JSON:', e); |
| 157 | 168 | resetButtonState(button, originalContent); |
| 158 | - alert('Installation failed: Invalid response format'); | |
| 169 | + alert(yatraThemeWizardI18n.installationFailedInvalidResponse); | |
| 159 | 170 | return; |
| 160 | 171 | } |
| 161 | 172 | } |
| 162 | 173 | |
| @@ -161,9 +172,9 @@ | ||
| 161 | 172 | } |
| 162 | 173 | |
| 163 | 174 | if (jsonResponse && jsonResponse.success) { |
| 164 | 175 | // Theme installed successfully, now activate it |
| 165 | - button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> Activating...'; | |
| 176 | + button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> ' + yatraThemeWizardI18n.activating; | |
| 166 | 177 | |
| 167 | 178 | jQuery.ajax({ |
| 168 | 179 | url: ajaxurl, |
| 169 | 180 | type: 'POST', |
| @@ -172,34 +183,34 @@ | ||
| 172 | 183 | theme_slug: themeSlug, |
| 173 | 184 | nonce: '<?php echo wp_create_nonce('yatra_theme_actions'); ?>' |
| 174 | 185 | }, |
| 175 | 186 | success: function(activateResponse) { |
| 176 | - console.log('Activation response:', activateResponse); // Debug log | |
| 187 | + window.YATRA_DEBUG && console.log('Activation response:', activateResponse); // Debug log | |
| 177 | 188 | if (activateResponse && activateResponse.success) { |
| 178 | 189 | // Update UI dynamically to show activated state |
| 179 | 190 | updateThemeCardToActivated(); |
| 180 | 191 | } else { |
| 181 | 192 | resetButtonState(button, originalContent); |
| 182 | - const errorMsg = activateResponse && activateResponse.data ? activateResponse.data : 'Unknown activation error'; | |
| 183 | - alert('Activation failed: ' + errorMsg); | |
| 193 | + const errorMsg = activateResponse && activateResponse.data ? activateResponse.data : yatraThemeWizardI18n.unknownActivationError; | |
| 194 | + alert(yatraThemeWizardI18n.activationFailedPrefix + ' ' + errorMsg); | |
| 184 | 195 | } |
| 185 | 196 | }, |
| 186 | 197 | error: function(xhr, status, error) { |
| 187 | - console.log('Activation AJAX error:', {xhr: xhr, status: status, error: error}); // Debug log | |
| 198 | + window.YATRA_DEBUG && console.log('Activation AJAX error:', {xhr: xhr, status: status, error: error}); // Debug log | |
| 188 | 199 | resetButtonState(button, originalContent); |
| 189 | - alert('Activation request failed. Please try again.'); | |
| 200 | + alert(yatraThemeWizardI18n.activationRequestFailed); | |
| 190 | 201 | } |
| 191 | 202 | }); |
| 192 | 203 | } else { |
| 193 | 204 | resetButtonState(button, originalContent); |
| 194 | - const errorMsg = jsonResponse && jsonResponse.data ? jsonResponse.data : 'Unknown installation error'; | |
| 195 | - alert('Installation failed: ' + errorMsg); | |
| 205 | + const errorMsg = jsonResponse && jsonResponse.data ? jsonResponse.data : yatraThemeWizardI18n.unknownInstallationError; | |
| 206 | + alert(yatraThemeWizardI18n.installationFailedPrefix + ' ' + errorMsg); | |
| 196 | 207 | } |
| 197 | 208 | }, |
| 198 | 209 | error: function() { |
| 199 | 210 | button.innerHTML = originalContent; |
| 200 | 211 | button.disabled = false; |
| 201 | - alert('Installation request failed. Please try again.'); | |
| 212 | + alert(yatraThemeWizardI18n.installationRequestFailed); | |
| 202 | 213 | } |
| 203 | 214 | }); |
| 204 | 215 | } |
| 205 | 216 | |
| @@ -205,11 +216,17 @@ | ||
| 205 | 216 | |
| 206 | 217 | function activateTheme(themeSlug) { |
| 207 | 218 | const button = event.target; |
| 208 | 219 | const originalContent = button.innerHTML; |
| 220 | + const yatraThemeWizardI18n = { | |
| 221 | + activating: <?php echo wp_json_encode(__('Activating...', 'yatra')); ?>, | |
| 222 | + activationFailedPrefix: <?php echo wp_json_encode(__('Activation failed:', 'yatra')); ?>, | |
| 223 | + activationRequestFailed: <?php echo wp_json_encode(__('Activation request failed. Please try again.', 'yatra')); ?>, | |
| 224 | + unknownActivationError: <?php echo wp_json_encode(__('Unknown activation error', 'yatra')); ?> | |
| 225 | + }; | |
| 209 | 226 | |
| 210 | 227 | // Show loading state with spinner |
| 211 | - button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> Activating...'; | |
| 228 | + button.innerHTML = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="animation: spin 1s linear infinite;"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle><path d="M12 2v10l4 2" fill="none" stroke="currentColor" stroke-width="2"></path></svg> ' + yatraThemeWizardI18n.activating; | |
| 212 | 229 | button.disabled = true; |
| 213 | 230 | button.style.cursor = 'not-allowed'; |
| 214 | 231 | button.style.opacity = '0.7'; |
| 215 | 232 | |
| @@ -230,22 +247,22 @@ | ||
| 230 | 247 | theme_slug: themeSlug, |
| 231 | 248 | nonce: '<?php echo wp_create_nonce('yatra_theme_actions'); ?>' |
| 232 | 249 | }, |
| 233 | 250 | success: function(response) { |
| 234 | - console.log('Activation response:', response); // Debug log | |
| 251 | + window.YATRA_DEBUG && console.log('Activation response:', response); // Debug log | |
| 235 | 252 | if (response && response.success) { |
| 236 | 253 | // Update UI dynamically to show activated state |
| 237 | 254 | updateThemeCardToActivated(); |
| 238 | 255 | } else { |
| 239 | 256 | resetButtonState(button, originalContent); |
| 240 | - const errorMsg = response && response.data ? response.data : 'Unknown activation error'; | |
| 241 | - alert('Activation failed: ' + errorMsg); | |
| 257 | + const errorMsg = response && response.data ? response.data : yatraThemeWizardI18n.unknownActivationError; | |
| 258 | + alert(yatraThemeWizardI18n.activationFailedPrefix + ' ' + errorMsg); | |
| 242 | 259 | } |
| 243 | 260 | }, |
| 244 | 261 | error: function(xhr, status, error) { |
| 245 | - console.log('Activation AJAX error:', {xhr: xhr, status: status, error: error}); // Debug log | |
| 262 | + window.YATRA_DEBUG && console.log('Activation AJAX error:', {xhr: xhr, status: status, error: error}); // Debug log | |
| 246 | 263 | resetButtonState(button, originalContent); |
| 247 | - alert('Activation request failed. Please try again.'); | |
| 264 | + alert(yatraThemeWizardI18n.activationRequestFailed); | |
| 248 | 265 | } |
| 249 | 266 | }); |
| 250 | 267 | } |
| 251 | 268 | |