PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 1.5.2
MxChat – AI Chatbot & Content Generation for WordPress v1.5.2
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 / mxchat-admin.js

mxchat-admin.js in MxChat – AI Chatbot & Content Generation for WordPress 1.5.2, at js/mxchat-admin.js

189 lines 7.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function($) {
2 //console.log('Script loaded'); // Confirm script is loading
3
4 // --- Tab Navigation and Toggles ---
5
6 $('.mxchat-nav-tab').on('click', function(e) {
7 e.preventDefault();
8 $('.mxchat-nav-tab').removeClass('mxchat-nav-tab-active');
9 $(this).addClass('mxchat-nav-tab-active');
10 $('.mxchat-tab-content').removeClass('active').hide();
11 var activeTab = $(this).attr('href');
12 $(activeTab).addClass('active').show();
13 });
14
15 // Activate the first tab by default
16 $('.mxchat-nav-tab-active').trigger('click');
17
18 // Toggle visibility of various API keys
19 function toggleVisibility(selector) {
20 $(selector).on('click', function() {
21 var inputField = $(this).prev('input');
22 if (inputField.attr('type') === 'password') {
23 inputField.attr('type', 'text');
24 $(this).text('Hide');
25 } else {
26 inputField.attr('type', 'password');
27 $(this).text('Show');
28 }
29 });
30 }
31 toggleVisibility('#toggleApiKeyVisibility');
32 toggleVisibility('#toggleWooCommerceSecretVisibility');
33 toggleVisibility('#toggleLoopsApiKeyVisibility');
34 toggleVisibility('#toggleXaiApiKeyVisibility');
35 toggleVisibility('#toggleClaudeApiKeyVisibility');
36 toggleVisibility('#toggleBraveApiKeyVisibility');
37 toggleVisibility('#toggleWebhookUrlVisibility');
38 toggleVisibility('#toggleSecretKeyVisibility');
39 toggleVisibility('#toggleBotTokenVisibility');
40
41 // --- Add Intent Form Submission ---
42
43 $('#mxchat-add-intent-form').on('submit', function(event) {
44 $('#mxchat-intent-loading').show();
45 $('#mxchat-intent-loading-text').show();
46 $(this).find('button[type="submit"]').hide(); // Hide the submit button to prevent multiple clicks
47 });
48
49 // --- Inline Edit Functionality ---
50
51 $('.edit-button').on('click', function() {
52 var row = $(this).closest('tr');
53 row.find('.content-view, .url-view').hide();
54 row.find('.content-edit, .url-edit').show();
55 row.find('.edit-button').hide();
56 row.find('.save-button').show();
57 });
58
59 $('.save-button').on('click', function() {
60 var button = $(this);
61 var row = button.closest('tr');
62 var id = button.data('id');
63 var newContent = row.find('.content-edit').val();
64 var newUrl = row.find('.url-edit').val();
65
66 // Send an AJAX request to save the changes
67 $.ajax({
68 url: ajaxurl, // ajaxurl is automatically available in WP admin
69 type: 'POST',
70 data: {
71 action: 'mxchat_save_inline_prompt',
72 id: id,
73 article_content: newContent,
74 article_url: newUrl,
75 _ajax_nonce: mxchatInlineEdit.nonce // Use localized nonce
76 },
77 success: function(response) {
78 if (response.success) {
79 row.find('.content-view').html(newContent.replace(/\n/g, "<br>"));
80 row.find('.url-view a').attr('href', newUrl).text(newUrl);
81 row.find('.content-edit, .url-edit').hide();
82 row.find('.content-view, .url-view').show();
83 row.find('.save-button').hide();
84 row.find('.edit-button').show();
85 } else {
86 alert('Error saving content.');
87 }
88 },
89 error: function() {
90 alert('An error occurred.');
91 }
92 });
93 });
94
95 // --- Activation Script ---
96
97 // Select activation-related elements
98 var form = $('#mxchat-activation-form');
99 var spinner = $('#mxchat-activation-spinner');
100 var submitButton = $('#activate_license_button');
101 var licenseStatus = $('#mxchat-license-status');
102
103 // Ensure essential elements exist before running activation-specific code
104 if (form.length && licenseStatus.length && submitButton.length) {
105 //console.log('Activation elements detected, running activation-specific code.');
106
107 // Function to handle the response from the activation AJAX request
108 function handleActivationResponse(response) {
109 spinner.hide(); // Hide the spinner
110
111 if (response.success) {
112 // Update UI on successful activation
113 licenseStatus.text('Active');
114 licenseStatus.removeClass('inactive').addClass('active');
115 form.hide(); // Hide the activation form after successful activation
116 } else {
117 licenseStatus.text('Inactive');
118 alert(response.data || 'Activation failed. Please check your input.');
119 submitButton.prop('disabled', false); // Re-enable button on failure
120 }
121 }
122
123 // Event listener for form submission to activate the license
124 form.on('submit', function(event) {
125 event.preventDefault(); // Prevent the default form submission
126 //console.log("Activating license...");
127
128 // Show spinner and disable the submit button to prevent multiple submissions
129 spinner.show();
130 submitButton.prop('disabled', true);
131
132 // Gather form data
133 var formData = {
134 action: 'mxchat_activate_license',
135 mxchat_pro_email: $('#mxchat_pro_email').val(),
136 mxchat_activation_key: $('#mxchat_activation_key').val(),
137 security: mxchatAdmin.nonce // Ensure this is localized in PHP
138 };
139
140 // Send the AJAX request using jQuery
141 $.post(mxchatAdmin.ajax_url, formData, function(response) {
142 //console.log("Activation response received:", response);
143 handleActivationResponse(response);
144 }).fail(function() {
145 alert('Server error. Please try again.');
146 spinner.hide();
147 submitButton.prop('disabled', false);
148 });
149 });
150 } else {
151 //console.log('Activation elements not found; skipping activation-specific code.');
152 }
153
154
155
156
157 // Add new question
158 $('.mxchat-add-question').on('click', function () {
159 const container = $('#mxchat-additional-questions-container');
160 const questionCount = container.find('.mxchat-question-row').length + 4;
161
162 const newQuestion = `
163 <div class="mxchat-question-row">
164 <input type="text" name="mxchat_options[additional_popular_questions][]" placeholder="Enter Additional Popular Question ${questionCount}" />
165 <button type="button" class="button mxchat-remove-question" aria-label="Remove question">Remove</button>
166 </div>
167 `;
168 container.append(newQuestion);
169 });
170
171 // Remove a question
172 $(document).on('click', '.mxchat-remove-question', function () {
173 $(this).closest('.mxchat-question-row').remove();
174 });
175
176
177
178 const statusToggle = document.getElementById('live_agent_status');
179 const statusText = statusToggle?.parentElement.nextElementSibling?.querySelector('.status-text');
180
181 if (statusToggle && statusText) {
182 statusToggle.addEventListener('change', function() {
183 statusText.textContent = this.checked ? 'Online' : 'Offline';
184 });
185 }
186
187
188 });
189