| 1 |
jQuery(document).ready(function($) { |
| 2 |
|
| 3 |
$('.mxchat-nav-tab').on('click', function(e) { |
| 4 |
e.preventDefault(); |
| 5 |
$('.mxchat-nav-tab').removeClass('mxchat-nav-tab-active'); |
| 6 |
$(this).addClass('mxchat-nav-tab-active'); |
| 7 |
$('.mxchat-tab-content').removeClass('active').hide(); |
| 8 |
var activeTab = $(this).attr('href'); |
| 9 |
$(activeTab).addClass('active').show(); |
| 10 |
}); |
| 11 |
|
| 12 |
// Activate the first tab by default |
| 13 |
$('.mxchat-nav-tab-active').trigger('click'); |
| 14 |
|
| 15 |
// Toggle visibility of API key |
| 16 |
$('#toggleApiKeyVisibility').on('click', function() { |
| 17 |
var apiKeyInput = $('#api_key'); |
| 18 |
if (apiKeyInput.attr('type') === 'password') { |
| 19 |
apiKeyInput.attr('type', 'text'); |
| 20 |
$(this).text('Hide'); |
| 21 |
} else { |
| 22 |
apiKeyInput.attr('type', 'password'); |
| 23 |
$(this).text('Show'); |
| 24 |
} |
| 25 |
}); |
| 26 |
|
| 27 |
// Toggle visibility of WooCommerce Consumer Secret |
| 28 |
$('#toggleWooCommerceSecretVisibility').on('click', function() { |
| 29 |
var secretInput = $('#woocommerce_consumer_secret'); |
| 30 |
if (secretInput.attr('type') === 'password') { |
| 31 |
secretInput.attr('type', 'text'); |
| 32 |
$(this).text('Hide'); |
| 33 |
} else { |
| 34 |
secretInput.attr('type', 'password'); |
| 35 |
$(this).text('Show'); |
| 36 |
} |
| 37 |
}); |
| 38 |
|
| 39 |
// Toggle visibility of Loops API Key |
| 40 |
$('#toggleLoopsApiKeyVisibility').on('click', function() { |
| 41 |
var loopsApiKeyInput = $('#loops_api_key'); |
| 42 |
if (loopsApiKeyInput.attr('type') === 'password') { |
| 43 |
loopsApiKeyInput.attr('type', 'text'); |
| 44 |
$(this).text('Hide'); |
| 45 |
} else { |
| 46 |
loopsApiKeyInput.attr('type', 'password'); |
| 47 |
$(this).text('Show'); |
| 48 |
} |
| 49 |
}); |
| 50 |
|
| 51 |
// Toggle visibility of X.AI API Key |
| 52 |
$('#toggleXaiApiKeyVisibility').on('click', function() { |
| 53 |
var xaiApiKeyInput = $('#xai_api_key'); |
| 54 |
if (xaiApiKeyInput.attr('type') === 'password') { |
| 55 |
xaiApiKeyInput.attr('type', 'text'); |
| 56 |
$(this).text('Hide'); |
| 57 |
} else { |
| 58 |
xaiApiKeyInput.attr('type', 'password'); |
| 59 |
$(this).text('Show'); |
| 60 |
} |
| 61 |
}); |
| 62 |
|
| 63 |
// Toggle visibility of Claude API Key |
| 64 |
$('#toggleClaudeApiKeyVisibility').on('click', function() { |
| 65 |
var claudeApiKeyInput = $('#claude_api_key'); |
| 66 |
if (claudeApiKeyInput.attr('type') === 'password') { |
| 67 |
claudeApiKeyInput.attr('type', 'text'); |
| 68 |
$(this).text('Hide'); |
| 69 |
} else { |
| 70 |
claudeApiKeyInput.attr('type', 'password'); |
| 71 |
$(this).text('Show'); |
| 72 |
} |
| 73 |
}); |
| 74 |
|
| 75 |
// Toggle visibility of Brave API Key |
| 76 |
$('#toggleBraveApiKeyVisibility').on('click', function() { |
| 77 |
var braveApiKeyInput = $('#brave_api_key'); |
| 78 |
if (braveApiKeyInput.attr('type') === 'password') { |
| 79 |
braveApiKeyInput.attr('type', 'text'); |
| 80 |
$(this).text('Hide'); |
| 81 |
} else { |
| 82 |
braveApiKeyInput.attr('type', 'password'); |
| 83 |
$(this).text('Show'); |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
|
| 88 |
const $addIntentButton = $('button[name="mxchat_add_intent"]'); |
| 89 |
|
| 90 |
// Handle the Add Intent form submission |
| 91 |
$('form').on('submit', function(event) { |
| 92 |
if ($addIntentButton.length) { |
| 93 |
// Show loading spinner and text, hide the add intent button on form submission |
| 94 |
$('#mxchat-intent-loading').show(); |
| 95 |
$('#mxchat-loading-text-intent').show(); |
| 96 |
$addIntentButton.hide(); |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
// Hide loader and show Add Intent button after form submission completes |
| 101 |
$(document).ajaxComplete(function(event, xhr, settings) { |
| 102 |
if (settings.url.includes('admin-post.php')) { |
| 103 |
$('#mxchat-intent-loading').hide(); |
| 104 |
$('#mxchat-loading-text-intent').hide(); |
| 105 |
$addIntentButton.show(); |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
// Click the Edit button |
| 110 |
$('.edit-button').on('click', function() { |
| 111 |
var row = $(this).closest('tr'); |
| 112 |
row.find('.content-view, .url-view').hide(); |
| 113 |
row.find('.content-edit, .url-edit').show(); |
| 114 |
row.find('.edit-button').hide(); |
| 115 |
row.find('.save-button').show(); |
| 116 |
}); |
| 117 |
|
| 118 |
// Click the Save button |
| 119 |
$('.save-button').on('click', function() { |
| 120 |
var button = $(this); |
| 121 |
var row = button.closest('tr'); |
| 122 |
var id = button.data('id'); |
| 123 |
var newContent = row.find('.content-edit').val(); |
| 124 |
var newUrl = row.find('.url-edit').val(); |
| 125 |
|
| 126 |
// Send an AJAX request to save the changes |
| 127 |
$.ajax({ |
| 128 |
url: ajaxurl, // ajaxurl is automatically available in WP admin |
| 129 |
type: 'POST', |
| 130 |
data: { |
| 131 |
action: 'mxchat_save_inline_prompt', |
| 132 |
id: id, |
| 133 |
article_content: newContent, |
| 134 |
article_url: newUrl, |
| 135 |
_ajax_nonce: mxchatInlineEdit.nonce // Use localized nonce |
| 136 |
}, |
| 137 |
success: function(response) { |
| 138 |
if (response.success) { |
| 139 |
row.find('.content-view').html(newContent.replace(/\n/g, "<br>")); |
| 140 |
row.find('.url-view a').attr('href', newUrl).text(newUrl); |
| 141 |
row.find('.content-edit, .url-edit').hide(); |
| 142 |
row.find('.content-view, .url-view').show(); |
| 143 |
row.find('.save-button').hide(); |
| 144 |
row.find('.edit-button').show(); |
| 145 |
} else { |
| 146 |
alert('Error saving content.'); |
| 147 |
} |
| 148 |
}, |
| 149 |
error: function() { |
| 150 |
alert('An error occurred.'); |
| 151 |
} |
| 152 |
}); |
| 153 |
}); |
| 154 |
|
| 155 |
|
| 156 |
}); |
| 157 |
|
| 158 |
jQuery(document).ready(function($) { |
| 159 |
console.log('Activation script loaded within mxchat-admin.js'); // Confirm script is loading |
| 160 |
|
| 161 |
// Select activation-related elements |
| 162 |
var form = $('#mxchat-activation-form'); |
| 163 |
var spinner = $('#mxchat-activation-spinner'); |
| 164 |
var submitButton = $('#activate_license_button'); |
| 165 |
var licenseStatus = $('#mxchat-license-status'); |
| 166 |
|
| 167 |
// Ensure essential elements exist |
| 168 |
if (form.length === 0 || licenseStatus.length === 0 || submitButton.length === 0) { |
| 169 |
console.error("Essential activation elements are missing from the page."); |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
// Function to handle the response from the activation AJAX request |
| 174 |
function handleActivationResponse(response) { |
| 175 |
spinner.hide(); // Hide the spinner |
| 176 |
|
| 177 |
if (response.success) { |
| 178 |
// Update UI on successful activation |
| 179 |
licenseStatus.text('Active'); |
| 180 |
licenseStatus.removeClass('inactive').addClass('active'); |
| 181 |
|
| 182 |
// Hide the activation form after successful activation |
| 183 |
form.hide(); |
| 184 |
} else { |
| 185 |
licenseStatus.text('Inactive'); |
| 186 |
alert(response.data || 'Activation failed. Please check your input.'); |
| 187 |
submitButton.prop('disabled', false); // Re-enable button on failure |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
// Event listener for form submission to activate the license |
| 192 |
form.on('submit', function(event) { |
| 193 |
event.preventDefault(); // Prevent the default form submission |
| 194 |
console.log("Activating license..."); |
| 195 |
|
| 196 |
// Show spinner and disable the submit button to prevent multiple submissions |
| 197 |
spinner.show(); |
| 198 |
submitButton.prop('disabled', true); |
| 199 |
|
| 200 |
// Gather form data |
| 201 |
var formData = { |
| 202 |
action: 'mxchat_activate_license', |
| 203 |
mxchat_pro_email: $('#mxchat_pro_email').val(), |
| 204 |
mxchat_activation_key: $('#mxchat_activation_key').val(), |
| 205 |
security: mxchatAdmin.nonce // Ensure this is localized in PHP |
| 206 |
}; |
| 207 |
|
| 208 |
// Send the AJAX request using jQuery |
| 209 |
$.post(mxchatAdmin.ajax_url, formData, function(response) { |
| 210 |
console.log("Activation response received:", response); |
| 211 |
handleActivationResponse(response); |
| 212 |
}).fail(function() { |
| 213 |
alert('Server error. Please try again.'); |
| 214 |
spinner.hide(); |
| 215 |
submitButton.prop('disabled', false); |
| 216 |
}); |
| 217 |
}); |
| 218 |
}); |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|