PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.2.0
MxChat – AI Chatbot & Content Generation for WordPress v2.2.0
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
mxchat-basic / js / activation-script.js

activation-script.js in MxChat – AI Chatbot & Content Generation for WordPress 2.2.0, at js/activation-script.js

95 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * MxChat License Activation JS
3 * Handles the license activation form submission with timeout handling
4 */
5 jQuery(document).ready(function($) {
6 // Activation handling
7 const form = $('#mxchat-activation-form');
8 const spinner = $('#mxchat-activation-spinner');
9 const submitButton = $('#activate_license_button');
10 const licenseStatus = $('#mxchat-license-status');
11
12 if (form.length && licenseStatus.length && submitButton.length) {
13 function handleActivationResponse(response) {
14 spinner.hide();
15 if (response.success) {
16 licenseStatus.text('Active');
17 licenseStatus.removeClass('inactive').addClass('active');
18 form.hide();
19 } else {
20 licenseStatus.text('Inactive');
21 alert(response.data || 'Activation failed. Please check your input.');
22 submitButton.prop('disabled', false);
23 }
24 }
25
26 function checkActivationStatus() {
27 const email = $('#mxchat_pro_email').val();
28 const key = $('#mxchat_activation_key').val();
29
30 $.ajax({
31 type: 'POST',
32 url: mxchatAdmin.ajax_url,
33 data: {
34 action: 'mxchat_check_license_status',
35 email: email,
36 key: key,
37 security: mxchatAdmin.license_nonce
38 },
39 success: function(response) {
40 if (response.is_active) {
41 // License is actually active, update UI
42 licenseStatus.text('Active');
43 licenseStatus.removeClass('inactive').addClass('active');
44 form.hide();
45 alert('Your license has been activated successfully!');
46 } else {
47 // Truly not activated
48 alert('License activation timed out. Please try again or contact support if the problem persists.');
49 submitButton.prop('disabled', false);
50 }
51 },
52 error: function() {
53 alert('Unable to verify license status. Please refresh the page to check if activation was successful.');
54 submitButton.prop('disabled', false);
55 }
56 });
57 }
58
59 form.on('submit', function(event) {
60 event.preventDefault();
61 spinner.show();
62 submitButton.prop('disabled', true);
63
64 var formData = {
65 action: 'mxchat_activate_license',
66 mxchat_pro_email: $('#mxchat_pro_email').val(),
67 mxchat_activation_key: $('#mxchat_activation_key').val(),
68 security: mxchatAdmin.license_nonce
69 };
70
71 // Use $.ajax instead of $.post to have more control
72 $.ajax({
73 type: 'POST',
74 url: mxchatAdmin.ajax_url,
75 data: formData,
76 timeout: 30000, // 30 seconds timeout
77 success: function(response) {
78 handleActivationResponse(response);
79 },
80 error: function(jqXHR, textStatus) {
81 if (textStatus === 'timeout') {
82 // If the request times out, check if the license was actually activated
83 spinner.hide();
84 checkActivationStatus();
85 } else {
86 // Handle other errors
87 alert('Server error. Please try again.');
88 spinner.hide();
89 submitButton.prop('disabled', false);
90 }
91 }
92 });
93 });
94 }
95 });