| @@ -897,27 +897,14 @@ | ||
| 897 | 897 | // Toggle visibility handlers |
| 898 | 898 | function toggleVisibility(selector) { |
| 899 | 899 | $(selector).on('click', function() { |
| 900 | 900 | var inputField = $(this).prev('input'); |
| 901 | - // Check if this is a CSS-masked field (type="text" with mxchat-api-key-field class) | |
| 902 | - if (inputField.hasClass('mxchat-api-key-field')) { | |
| 903 | - // Use CSS class toggle for CSS-masked fields | |
| 904 | - if (inputField.hasClass('mxchat-show-key')) { | |
| 905 | - inputField.removeClass('mxchat-show-key'); | |
| 906 | - $(this).text('Show'); | |
| 907 | - } else { | |
| 908 | - inputField.addClass('mxchat-show-key'); | |
| 909 | - $(this).text('Hide'); | |
| 910 | - } | |
| 901 | + if (inputField.attr('type') === 'password') { | |
| 902 | + inputField.attr('type', 'text'); | |
| 903 | + $(this).text('Hide'); | |
| 911 | 904 | } else { |
| 912 | - // Legacy type toggle for password fields | |
| 913 | - if (inputField.attr('type') === 'password') { | |
| 914 | - inputField.attr('type', 'text'); | |
| 915 | - $(this).text('Hide'); | |
| 916 | - } else { | |
| 917 | - inputField.attr('type', 'password'); | |
| 918 | - $(this).text('Show'); | |
| 919 | - } | |
| 905 | + inputField.attr('type', 'password'); | |
| 906 | + $(this).text('Show'); | |
| 920 | 907 | } |
| 921 | 908 | }); |
| 922 | 909 | } |
| 923 | 910 | |
| @@ -1027,12 +1014,8 @@ | ||
| 1027 | 1014 | { value: 'gemini-1.5-pro', label: 'Gemini 1.5 Pro', description: 'Deprecated September 2025' }, |
| 1028 | 1015 | { value: 'gemini-1.5-flash', label: 'Gemini 1.5 Flash', description: 'Deprecated September 2025' }, |
| 1029 | 1016 | ], |
| 1030 | 1017 | openai: [ |
| 1031 | - { value: 'gpt-5.4', label: 'GPT-5.4', description: 'Flagship reasoning and coding model' }, | |
| 1032 | - { value: 'gpt-5.4-mini', label: 'GPT-5.4 Mini', description: 'Fast and affordable with 400K context' }, | |
| 1033 | - { value: 'gpt-5.4-nano', label: 'GPT-5.4 Nano', description: 'Fastest and cheapest for lightweight tasks' }, | |
| 1034 | - { value: 'gpt-5.3-chat-latest', label: 'GPT-5.3 Chat', description: 'Optimized for natural conversations with reduced hallucinations' }, | |
| 1035 | 1018 | { value: 'gpt-5.2', label: 'GPT-5.2', description: 'Best general-purpose & agentic model with fast responses' }, |
| 1036 | 1019 | { value: 'gpt-5.1-chat-latest', label: 'GPT-5.1 Chat Latest', description: 'Recommended for most use cases' }, |
| 1037 | 1020 | { value: 'gpt-5.1-2025-11-13', label: 'GPT-5.1', description: 'Flagship for coding & agentic tasks with low reasoning (400K context)' }, |
| 1038 | 1021 | { value: 'gpt-5', label: 'GPT-5', description: 'Flagship for coding, reasoning, and agentic tasks across domains' }, |
| @@ -1040,9 +1023,8 @@ | ||
| 1040 | 1023 | { value: 'gpt-5-nano', label: 'GPT-5 Nano', description: 'Fastest and cheapest; ideal for summarization and classification' }, |
| 1041 | 1024 | ], |
| 1042 | 1025 | claude: [ |
| 1043 | 1026 | { value: 'claude-opus-4-6', label: 'Claude Opus 4.6', description: 'Most capable Claude model - recommended' }, |
| 1044 | - { value: 'claude-sonnet-4-6', label: 'Claude Sonnet 4.6', description: 'Latest Sonnet - excellent balance of speed and capability' }, | |
| 1045 | 1027 | { value: 'claude-opus-4-5', label: 'Claude Opus 4.5', description: 'Highly capable for complex tasks' }, |
| 1046 | 1028 | { value: 'claude-sonnet-4-5-20250929', label: 'Claude Sonnet 4.5', description: 'Best for complex agents and coding' }, |
| 1047 | 1029 | { value: 'claude-opus-4-1-20250805', label: 'Claude Opus 4.1', description: 'Exceptional for specialized complex tasks' }, |
| 1048 | 1030 | { value: 'claude-haiku-4-5-20251001', label: 'Claude Haiku 4.5', description: 'Fastest and most intelligent Haiku' }, |
| @@ -1617,71 +1599,8 @@ | ||
| 1617 | 1599 | }); |
| 1618 | 1600 | |
| 1619 | 1601 | } |
| 1620 | 1602 | |
| 1621 | -// 3.2.3: Confirmation dialog shown when the user attempts to switch embedding | |
| 1622 | -// models after they've already embedded content with a different model. Mixing | |
| 1623 | -// embeddings from two models silently breaks similarity matching. | |
| 1624 | -function showEmbeddingSwitchWarning(data, newValue, onChoice) { | |
| 1625 | - $('#mxchat_embedding_switch_warning').remove(); | |
| 1626 | - | |
| 1627 | - const dimsBlock = data.dims_differ ? ` | |
| 1628 | - <div class="mxchat-embed-warn-dims"> | |
| 1629 | - <strong>Dimension mismatch:</strong> | |
| 1630 | - Existing vectors are ${data.active_dims}-dimensional, but ${data.new_label} | |
| 1631 | - produces ${data.new_dims}-dimensional vectors. | |
| 1632 | - If you use Pinecone, your index will reject queries entirely until you re-embed. | |
| 1633 | - </div>` : ''; | |
| 1634 | - | |
| 1635 | - const $modal = $(` | |
| 1636 | - <div id="mxchat_embedding_switch_warning" class="mxchat-embed-warn-overlay"> | |
| 1637 | - <div class="mxchat-embed-warn-dialog"> | |
| 1638 | - <div class="mxchat-embed-warn-header"> | |
| 1639 | - <span class="mxchat-embed-warn-icon">⚠️</span> | |
| 1640 | - <h3>Switching embedding models will break similarity matching</h3> | |
| 1641 | - </div> | |
| 1642 | - <div class="mxchat-embed-warn-body"> | |
| 1643 | - <p> | |
| 1644 | - Your knowledge base and actions are currently embedded with | |
| 1645 | - <code>${data.active_label}</code>. Switching to | |
| 1646 | - <code>${data.new_label}</code> means new queries are embedded with | |
| 1647 | - a different model than the stored vectors — the chatbot will return | |
| 1648 | - inaccurate results or fail to match anything. | |
| 1649 | - </p> | |
| 1650 | - ${dimsBlock} | |
| 1651 | - <p><strong>To switch safely:</strong></p> | |
| 1652 | - <ol> | |
| 1653 | - <li>Go to <em>Knowledge Base</em> and delete all existing entries.</li> | |
| 1654 | - <li>Go to <em>Actions</em> and delete all existing actions.</li> | |
| 1655 | - <li>Come back here, switch the model, then re-import your content and re-add your actions.</li> | |
| 1656 | - </ol> | |
| 1657 | - </div> | |
| 1658 | - <div class="mxchat-embed-warn-footer"> | |
| 1659 | - <button type="button" class="button button-secondary" id="mxchat_embed_warn_cancel">Cancel — keep ${data.active_label}</button> | |
| 1660 | - <button type="button" class="button button-primary mxchat-embed-warn-danger" id="mxchat_embed_warn_continue">Switch anyway (I'll handle it)</button> | |
| 1661 | - </div> | |
| 1662 | - </div> | |
| 1663 | - </div> | |
| 1664 | - `); | |
| 1665 | - | |
| 1666 | - $('body').append($modal); | |
| 1667 | - | |
| 1668 | - let resolved = false; | |
| 1669 | - function resolve(confirmed) { | |
| 1670 | - if (resolved) return; | |
| 1671 | - resolved = true; | |
| 1672 | - $modal.remove(); | |
| 1673 | - if (typeof onChoice === 'function') onChoice(confirmed); | |
| 1674 | - } | |
| 1675 | - | |
| 1676 | - // Click on the overlay background dismisses (cancel) | |
| 1677 | - $modal.on('click', function(e) { | |
| 1678 | - if (e.target === $modal[0]) resolve(false); | |
| 1679 | - }); | |
| 1680 | - $modal.find('#mxchat_embed_warn_cancel').on('click', function() { resolve(false); }); | |
| 1681 | - $modal.find('#mxchat_embed_warn_continue').on('click', function() { resolve(true); }); | |
| 1682 | -} | |
| 1683 | - | |
| 1684 | 1603 | // Embedding model selector - completely separate from chat model selector |
| 1685 | 1604 | function setupMxChatEmbeddingModelSelector() { |
| 1686 | 1605 | const $embeddingModelSelect = $('#embedding_model'); |
| 1687 | 1606 | |
| @@ -1862,53 +1781,25 @@ | ||
| 1862 | 1781 | const activeCategory = $('.mxchat-embedding-model-selector-categories .mxchat-embedding-model-category-btn.active').data('category'); |
| 1863 | 1782 | populateEmbeddingModelsGrid(searchTerm, activeCategory); |
| 1864 | 1783 | }); |
| 1865 | 1784 | |
| 1866 | - // 3.2.3: Commit a model change — same as the original click handler, just | |
| 1867 | - // factored out so it can be invoked from both the safe path and the | |
| 1868 | - // post-confirmation path. | |
| 1869 | - function commitEmbeddingModelChange(modelValue) { | |
| 1785 | + // Use a direct selector to avoid conflicts with other card elements | |
| 1786 | + $(document).on('click.embeddingModelSelector', '.mxchat-embedding-model-selector-grid .mxchat-embedding-model-selector-card', function(e) { | |
| 1787 | + e.stopPropagation(); // Prevent event bubbling | |
| 1788 | + const modelValue = $(this).data('value'); | |
| 1789 | + | |
| 1790 | + // Important: Only update this specific select element | |
| 1870 | 1791 | $embeddingModelSelect.val(modelValue); |
| 1792 | + | |
| 1793 | + // Manually trigger change only on this element | |
| 1871 | 1794 | const changeEvent = new Event('change', { bubbles: true }); |
| 1872 | 1795 | $embeddingModelSelect[0].dispatchEvent(changeEvent); |
| 1796 | + | |
| 1797 | + // Update button text | |
| 1873 | 1798 | updateButtonText(); |
| 1799 | + | |
| 1800 | + // Hide modal | |
| 1874 | 1801 | $('#' + embeddingModalId).hide(); |
| 1875 | - } | |
| 1876 | - | |
| 1877 | - // Use a direct selector to avoid conflicts with other card elements | |
| 1878 | - $(document).on('click.embeddingModelSelector', '.mxchat-embedding-model-selector-grid .mxchat-embedding-model-selector-card', function(e) { | |
| 1879 | - e.stopPropagation(); // Prevent event bubbling | |
| 1880 | - const modelValue = $(this).data('value'); | |
| 1881 | - const previousValue = $embeddingModelSelect.val(); | |
| 1882 | - | |
| 1883 | - // No-op if the user clicked the already-selected card | |
| 1884 | - if (modelValue === previousValue) { | |
| 1885 | - $('#' + embeddingModalId).hide(); | |
| 1886 | - return; | |
| 1887 | - } | |
| 1888 | - | |
| 1889 | - // 3.2.3: Preflight — if the user has content embedded with a different | |
| 1890 | - // model, surface a confirmation dialog before committing the switch. | |
| 1891 | - $.post(ajaxurl, { | |
| 1892 | - action: 'mxchat_check_embedding_switch', | |
| 1893 | - security: (typeof mxchatAdmin !== 'undefined' ? mxchatAdmin.nonce : ''), | |
| 1894 | - new_model: modelValue | |
| 1895 | - }).done(function(resp) { | |
| 1896 | - if (resp && resp.success && resp.data && resp.data.is_mismatch) { | |
| 1897 | - showEmbeddingSwitchWarning(resp.data, modelValue, function(confirmed) { | |
| 1898 | - if (confirmed) { | |
| 1899 | - commitEmbeddingModelChange(modelValue); | |
| 1900 | - } | |
| 1901 | - }); | |
| 1902 | - } else { | |
| 1903 | - commitEmbeddingModelChange(modelValue); | |
| 1904 | - } | |
| 1905 | - }).fail(function() { | |
| 1906 | - // If preflight fails, fall back to the original behavior so a network | |
| 1907 | - // hiccup doesn't block legitimate model switches. | |
| 1908 | - commitEmbeddingModelChange(modelValue); | |
| 1909 | - }); | |
| 1910 | - return; | |
| 1911 | 1802 | }); |
| 1912 | 1803 | |
| 1913 | 1804 | // Close modal when clicking outside - use namespaced events |
| 1914 | 1805 | $(window).on('click.embeddingModelSelector', function(event) { |
| @@ -2206,14 +2097,24 @@ | ||
| 2206 | 2097 | const actionLabel = this.dataset.label; |
| 2207 | 2098 | const actionIcon = this.querySelector('.dashicons').getAttribute('class').replace('dashicons dashicons-', ''); |
| 2208 | 2099 | const actionDescription = this.querySelector('p').textContent; |
| 2209 | 2100 | |
| 2210 | - // Check if this is a promotional card (add-on not installed) | |
| 2211 | - const isPromo = this.dataset.promo === 'true'; | |
| 2212 | - | |
| 2213 | - if (isPromo || (addonName && !isInstalled)) { | |
| 2214 | - // Add-on required but not installed — show informational notice | |
| 2215 | - const addonDisplayName = this.querySelector('.mxchat-addon-info')?.textContent?.replace('Requires ', '').replace('— Get Add-on', '').trim() || addonName + ' Add-on'; | |
| 2101 | + // Pro check using the proper detection method | |
| 2102 | + const proIsActivated = typeof mxchatAdmin !== 'undefined' && | |
| 2103 | + (mxchatAdmin.is_activated === '1' || | |
| 2104 | + mxchatAdmin.is_activated === 'true' || | |
| 2105 | + mxchatAdmin.is_activated === true); | |
| 2106 | + | |
| 2107 | + // Handle different states | |
| 2108 | + if (isPro && !proIsActivated) { | |
| 2109 | + // Pro feature but no Pro license | |
| 2110 | + showProFeatureNotice(); | |
| 2111 | + return; | |
| 2112 | + } | |
| 2113 | + | |
| 2114 | + if (addonName && !isInstalled) { | |
| 2115 | + // Add-on required but not installed | |
| 2116 | + const addonDisplayName = this.querySelector('.mxchat-addon-info')?.textContent?.replace('Requires ', '') || addonName + ' Add-on'; | |
| 2216 | 2117 | showAddonRequiredNotice(addonDisplayName); |
| 2217 | 2118 | return; |
| 2218 | 2119 | } |
| 2219 | 2120 | |
| @@ -3375,253 +3276,5 @@ | ||
| 3375 | 3276 | var div = document.createElement('div'); |
| 3376 | 3277 | div.appendChild(document.createTextNode(text)); |
| 3377 | 3278 | return div.innerHTML; |
| 3378 | 3279 | } |
| 3379 | - | |
| 3380 | - // ======================================== | |
| 3381 | - // DEBUG & OPTIMIZATION TOOLS | |
| 3382 | - // ======================================== | |
| 3383 | - | |
| 3384 | - // Debug Mode Toggle | |
| 3385 | - $('#mxchat_debug_mode').on('change', function() { | |
| 3386 | - var $toggle = $(this); | |
| 3387 | - var enabled = $toggle.is(':checked') ? 'on' : 'off'; | |
| 3388 | - var $label = $toggle.closest('label'); | |
| 3389 | - | |
| 3390 | - // Add loading indicator next to the toggle label | |
| 3391 | - var $indicator = $label.find('.mxchat-save-indicator'); | |
| 3392 | - if ($indicator.length === 0) { | |
| 3393 | - $indicator = $('<span class="mxchat-save-indicator" style="margin-left: 10px;"></span>'); | |
| 3394 | - $label.append($indicator); | |
| 3395 | - } | |
| 3396 | - $indicator.html('<span class="mxchat-saving-spinner"></span>').show(); | |
| 3397 | - | |
| 3398 | - $.ajax({ | |
| 3399 | - url: ajaxurl, | |
| 3400 | - type: 'POST', | |
| 3401 | - data: { | |
| 3402 | - action: 'mxchat_toggle_debug_mode', | |
| 3403 | - enabled: enabled, | |
| 3404 | - _ajax_nonce: mxchatAdmin.setting_nonce | |
| 3405 | - }, | |
| 3406 | - success: function(response) { | |
| 3407 | - if (response.success) { | |
| 3408 | - // Show success indicator | |
| 3409 | - $indicator.html('<span class="mxchat-save-success">✓</span>'); | |
| 3410 | - setTimeout(function() { | |
| 3411 | - $indicator.fadeOut(300); | |
| 3412 | - }, 2000); | |
| 3413 | - | |
| 3414 | - // Always refresh the log after toggling | |
| 3415 | - refreshDebugLog(); | |
| 3416 | - } else { | |
| 3417 | - $indicator.html('<span class="mxchat-save-error">✗</span>'); | |
| 3418 | - alert(response.data.message || 'Error toggling debug mode'); | |
| 3419 | - $toggle.prop('checked', !$toggle.is(':checked')); | |
| 3420 | - } | |
| 3421 | - }, | |
| 3422 | - error: function() { | |
| 3423 | - $indicator.html('<span class="mxchat-save-error">✗</span>'); | |
| 3424 | - alert('Error toggling debug mode'); | |
| 3425 | - $toggle.prop('checked', !$toggle.is(':checked')); | |
| 3426 | - } | |
| 3427 | - }); | |
| 3428 | - }); | |
| 3429 | - | |
| 3430 | - // Refresh Debug Log | |
| 3431 | - function refreshDebugLog() { | |
| 3432 | - var $container = $('#mxchat-debug-log'); | |
| 3433 | - var $countBadge = $('#mxchat-log-count'); | |
| 3434 | - | |
| 3435 | - $.ajax({ | |
| 3436 | - url: ajaxurl, | |
| 3437 | - type: 'POST', | |
| 3438 | - data: { | |
| 3439 | - action: 'mxchat_get_debug_log', | |
| 3440 | - _ajax_nonce: mxchatAdmin.setting_nonce | |
| 3441 | - }, | |
| 3442 | - success: function(response) { | |
| 3443 | - if (response.success) { | |
| 3444 | - var log = response.data.log; | |
| 3445 | - var count = response.data.count; | |
| 3446 | - | |
| 3447 | - if (count > 0) { | |
| 3448 | - $countBadge.text(count + ' entries').show(); | |
| 3449 | - var html = '<div class="mxchat-debug-log-entries">'; | |
| 3450 | - log.forEach(function(entry) { | |
| 3451 | - var typeClass = 'mxchat-log-type-' + entry.type; | |
| 3452 | - var typeLabel = entry.type.replace(/_/g, ' ').toUpperCase(); | |
| 3453 | - html += '<div class="mxchat-debug-log-entry ' + typeClass + '">'; | |
| 3454 | - html += '<div class="mxchat-log-header">'; | |
| 3455 | - html += '<span class="mxchat-log-type">' + escapeHtml(typeLabel) + '</span>'; | |
| 3456 | - html += '<span class="mxchat-log-time">' + escapeHtml(entry.time) + '</span>'; | |
| 3457 | - html += '</div>'; | |
| 3458 | - html += '<div class="mxchat-log-message">' + escapeHtml(entry.message) + '</div>'; | |
| 3459 | - if (entry.data) { | |
| 3460 | - html += '<div class="mxchat-log-data">' + escapeHtml(JSON.stringify(entry.data, null, 2)) + '</div>'; | |
| 3461 | - } | |
| 3462 | - html += '</div>'; | |
| 3463 | - }); | |
| 3464 | - html += '</div>'; | |
| 3465 | - $container.html(html); | |
| 3466 | - } else { | |
| 3467 | - $countBadge.hide(); | |
| 3468 | - $container.html( | |
| 3469 | - '<div class="mxchat-debug-log-empty">' + | |
| 3470 | - '<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" style="opacity: 0.3;"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>' + | |
| 3471 | - '<p>No log entries yet. Enable debug mode to start logging.</p>' + | |
| 3472 | - '</div>' | |
| 3473 | - ); | |
| 3474 | - } | |
| 3475 | - } | |
| 3476 | - } | |
| 3477 | - }); | |
| 3478 | - } | |
| 3479 | - | |
| 3480 | - // Load debug log on page load | |
| 3481 | - if ($('#mxchat-debug-log').length) { | |
| 3482 | - refreshDebugLog(); | |
| 3483 | - } | |
| 3484 | - | |
| 3485 | - // Refresh Log Button | |
| 3486 | - $('#mxchat-refresh-log').on('click', function() { | |
| 3487 | - var $btn = $(this); | |
| 3488 | - $btn.prop('disabled', true); | |
| 3489 | - refreshDebugLog(); | |
| 3490 | - setTimeout(function() { | |
| 3491 | - $btn.prop('disabled', false); | |
| 3492 | - }, 500); | |
| 3493 | - }); | |
| 3494 | - | |
| 3495 | - // Clear Log Button | |
| 3496 | - $('#mxchat-clear-log').on('click', function() { | |
| 3497 | - if (!confirm('Are you sure you want to clear the debug log?')) { | |
| 3498 | - return; | |
| 3499 | - } | |
| 3500 | - | |
| 3501 | - var $btn = $(this); | |
| 3502 | - $btn.prop('disabled', true); | |
| 3503 | - | |
| 3504 | - $.ajax({ | |
| 3505 | - url: ajaxurl, | |
| 3506 | - type: 'POST', | |
| 3507 | - data: { | |
| 3508 | - action: 'mxchat_clear_debug_log', | |
| 3509 | - _ajax_nonce: mxchatAdmin.setting_nonce | |
| 3510 | - }, | |
| 3511 | - success: function(response) { | |
| 3512 | - if (response.success) { | |
| 3513 | - refreshDebugLog(); | |
| 3514 | - } else { | |
| 3515 | - alert(response.data.message || 'Error clearing log'); | |
| 3516 | - } | |
| 3517 | - }, | |
| 3518 | - error: function() { | |
| 3519 | - alert('Error clearing log'); | |
| 3520 | - }, | |
| 3521 | - complete: function() { | |
| 3522 | - $btn.prop('disabled', false); | |
| 3523 | - } | |
| 3524 | - }); | |
| 3525 | - }); | |
| 3526 | - | |
| 3527 | - // Export Settings Button | |
| 3528 | - $('#mxchat-export-settings').on('click', function() { | |
| 3529 | - var $btn = $(this); | |
| 3530 | - var originalHtml = $btn.html(); | |
| 3531 | - $btn.prop('disabled', true).html( | |
| 3532 | - '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" 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" stroke-dasharray="32" stroke-dashoffset="12"/></svg> Exporting...' | |
| 3533 | - ); | |
| 3534 | - | |
| 3535 | - $.ajax({ | |
| 3536 | - url: ajaxurl, | |
| 3537 | - type: 'POST', | |
| 3538 | - data: { | |
| 3539 | - action: 'mxchat_export_settings', | |
| 3540 | - _ajax_nonce: mxchatAdmin.setting_nonce | |
| 3541 | - }, | |
| 3542 | - success: function(response) { | |
| 3543 | - if (response.success) { | |
| 3544 | - // Create and download the JSON file | |
| 3545 | - var dataStr = JSON.stringify(response.data.settings, null, 2); | |
| 3546 | - var blob = new Blob([dataStr], { type: 'application/json' }); | |
| 3547 | - var url = URL.createObjectURL(blob); | |
| 3548 | - var a = document.createElement('a'); | |
| 3549 | - a.href = url; | |
| 3550 | - a.download = response.data.filename; | |
| 3551 | - document.body.appendChild(a); | |
| 3552 | - a.click(); | |
| 3553 | - document.body.removeChild(a); | |
| 3554 | - URL.revokeObjectURL(url); | |
| 3555 | - } else { | |
| 3556 | - alert(response.data.message || 'Error exporting settings'); | |
| 3557 | - } | |
| 3558 | - }, | |
| 3559 | - error: function() { | |
| 3560 | - alert('Error exporting settings'); | |
| 3561 | - }, | |
| 3562 | - complete: function() { | |
| 3563 | - $btn.prop('disabled', false).html(originalHtml); | |
| 3564 | - } | |
| 3565 | - }); | |
| 3566 | - }); | |
| 3567 | - | |
| 3568 | - // Reset Settings Modal | |
| 3569 | - var $resetModal = $('#mxchat-reset-modal'); | |
| 3570 | - var $resetConfirmInput = $('#mxchat-reset-confirmation'); | |
| 3571 | - var $resetConfirmBtn = $('#mxchat-reset-confirm'); | |
| 3572 | - | |
| 3573 | - $('#mxchat-reset-settings').on('click', function() { | |
| 3574 | - $resetModal.fadeIn(200); | |
| 3575 | - $resetConfirmInput.val('').focus(); | |
| 3576 | - $resetConfirmBtn.prop('disabled', true); | |
| 3577 | - }); | |
| 3578 | - | |
| 3579 | - $('#mxchat-reset-modal-close, #mxchat-reset-cancel, .mxch-modal-backdrop').on('click', function() { | |
| 3580 | - $resetModal.fadeOut(200); | |
| 3581 | - }); | |
| 3582 | - | |
| 3583 | - $resetConfirmInput.on('input', function() { | |
| 3584 | - var value = $(this).val().toUpperCase(); | |
| 3585 | - $resetConfirmBtn.prop('disabled', value !== 'RESET'); | |
| 3586 | - }); | |
| 3587 | - | |
| 3588 | - $resetConfirmBtn.on('click', function() { | |
| 3589 | - var $btn = $(this); | |
| 3590 | - var confirmation = $resetConfirmInput.val(); | |
| 3591 | - | |
| 3592 | - $btn.prop('disabled', true).text('Resetting...'); | |
| 3593 | - | |
| 3594 | - $.ajax({ | |
| 3595 | - url: ajaxurl, | |
| 3596 | - type: 'POST', | |
| 3597 | - data: { | |
| 3598 | - action: 'mxchat_reset_all_settings', | |
| 3599 | - confirmation: confirmation, | |
| 3600 | - _ajax_nonce: mxchatAdmin.setting_nonce | |
| 3601 | - }, | |
| 3602 | - success: function(response) { | |
| 3603 | - if (response.success) { | |
| 3604 | - alert(response.data.message); | |
| 3605 | - window.location.reload(); | |
| 3606 | - } else { | |
| 3607 | - alert(response.data.message || 'Error resetting settings'); | |
| 3608 | - $btn.prop('disabled', false).text('Reset All Settings'); | |
| 3609 | - } | |
| 3610 | - }, | |
| 3611 | - error: function() { | |
| 3612 | - alert('Error resetting settings'); | |
| 3613 | - $btn.prop('disabled', false).text('Reset All Settings'); | |
| 3614 | - } | |
| 3615 | - }); | |
| 3616 | - }); | |
| 3617 | - | |
| 3618 | - // Load debug log on page load if we're on the optimization section | |
| 3619 | - if ($('#optimization').hasClass('active') || window.location.hash === '#optimization') { | |
| 3620 | - refreshDebugLog(); | |
| 3621 | - } | |
| 3622 | - | |
| 3623 | - // Also refresh when switching to optimization tab | |
| 3624 | - $(document).on('click', '[data-section="optimization"]', function() { | |
| 3625 | - setTimeout(refreshDebugLog, 100); | |
| 3626 | - }); | |
| 3627 | 3280 | }); |