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

180 lines 6.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 $('#mxchat-activation-form').on('submit', function(event) {
3 event.preventDefault();
4
5 var formData = {
6 action: 'mxchat_activate_license',
7 email: $('#mxchat_pro_email').val(),
8 key: $('#mxchat_activation_key').val(),
9 security: mxchatAdmin.nonce
10 };
11
12 $.post(mxchatAdmin.ajax_url, formData, function(response) {
13 if (response.success) {
14 $('#mxchat-license-status').text('Active');
15 } else {
16 $('#mxchat-license-status').text('Inactive');
17 alert(response.data);
18 }
19 });
20 });
21
22 $('.mxchat-nav-tab').on('click', function(e) {
23 e.preventDefault();
24 $('.mxchat-nav-tab').removeClass('mxchat-nav-tab-active');
25 $(this).addClass('mxchat-nav-tab-active');
26 $('.mxchat-tab-content').removeClass('active').hide();
27 var activeTab = $(this).attr('href');
28 $(activeTab).addClass('active').show();
29 });
30
31 // Activate the first tab by default
32 $('.mxchat-nav-tab-active').trigger('click');
33
34 // Toggle visibility of API key
35 $('#toggleApiKeyVisibility').on('click', function() {
36 var apiKeyInput = $('#api_key');
37 if (apiKeyInput.attr('type') === 'password') {
38 apiKeyInput.attr('type', 'text');
39 $(this).text('Hide');
40 } else {
41 apiKeyInput.attr('type', 'password');
42 $(this).text('Show');
43 }
44 });
45
46 // Toggle visibility of WooCommerce Consumer Secret
47 $('#toggleWooCommerceSecretVisibility').on('click', function() {
48 var secretInput = $('#woocommerce_consumer_secret');
49 if (secretInput.attr('type') === 'password') {
50 secretInput.attr('type', 'text');
51 $(this).text('Hide');
52 } else {
53 secretInput.attr('type', 'password');
54 $(this).text('Show');
55 }
56 });
57
58 // Toggle visibility of Loops API Key
59 $('#toggleLoopsApiKeyVisibility').on('click', function() {
60 var loopsApiKeyInput = $('#loops_api_key');
61 if (loopsApiKeyInput.attr('type') === 'password') {
62 loopsApiKeyInput.attr('type', 'text');
63 $(this).text('Hide');
64 } else {
65 loopsApiKeyInput.attr('type', 'password');
66 $(this).text('Show');
67 }
68 });
69
70 // Toggle visibility of X.AI API Key
71 $('#toggleXaiApiKeyVisibility').on('click', function() {
72 var xaiApiKeyInput = $('#xai_api_key');
73 if (xaiApiKeyInput.attr('type') === 'password') {
74 xaiApiKeyInput.attr('type', 'text');
75 $(this).text('Hide');
76 } else {
77 xaiApiKeyInput.attr('type', 'password');
78 $(this).text('Show');
79 }
80 });
81
82 // Toggle visibility of Claude API Key
83 $('#toggleClaudeApiKeyVisibility').on('click', function() {
84 var claudeApiKeyInput = $('#claude_api_key');
85 if (claudeApiKeyInput.attr('type') === 'password') {
86 claudeApiKeyInput.attr('type', 'text');
87 $(this).text('Hide');
88 } else {
89 claudeApiKeyInput.attr('type', 'password');
90 $(this).text('Show');
91 }
92 });
93
94 // Toggle visibility of Brave API Key
95 $('#toggleBraveApiKeyVisibility').on('click', function() {
96 var braveApiKeyInput = $('#brave_api_key');
97 if (braveApiKeyInput.attr('type') === 'password') {
98 braveApiKeyInput.attr('type', 'text');
99 $(this).text('Hide');
100 } else {
101 braveApiKeyInput.attr('type', 'password');
102 $(this).text('Show');
103 }
104 });
105
106
107 const $addIntentButton = $('button[name="mxchat_add_intent"]');
108
109 // Handle the Add Intent form submission
110 $('form').on('submit', function(event) {
111 if ($addIntentButton.length) {
112 // Show loading spinner and text, hide the add intent button on form submission
113 $('#mxchat-intent-loading').show();
114 $('#mxchat-loading-text-intent').show();
115 $addIntentButton.hide();
116 }
117 });
118
119 // Hide loader and show Add Intent button after form submission completes
120 $(document).ajaxComplete(function(event, xhr, settings) {
121 if (settings.url.includes('admin-post.php')) {
122 $('#mxchat-intent-loading').hide();
123 $('#mxchat-loading-text-intent').hide();
124 $addIntentButton.show();
125 }
126 });
127
128 // Click the Edit button
129 $('.edit-button').on('click', function() {
130 var row = $(this).closest('tr');
131 row.find('.content-view, .url-view').hide();
132 row.find('.content-edit, .url-edit').show();
133 row.find('.edit-button').hide();
134 row.find('.save-button').show();
135 });
136
137 // Click the Save button
138 $('.save-button').on('click', function() {
139 var button = $(this);
140 var row = button.closest('tr');
141 var id = button.data('id');
142 var newContent = row.find('.content-edit').val();
143 var newUrl = row.find('.url-edit').val();
144
145 // Send an AJAX request to save the changes
146 $.ajax({
147 url: ajaxurl, // ajaxurl is automatically available in WP admin
148 type: 'POST',
149 data: {
150 action: 'mxchat_save_inline_prompt',
151 id: id,
152 article_content: newContent,
153 article_url: newUrl,
154 _ajax_nonce: mxchatInlineEdit.nonce // Use localized nonce
155 },
156 success: function(response) {
157 if (response.success) {
158 row.find('.content-view').html(newContent.replace(/\n/g, "<br>"));
159 row.find('.url-view a').attr('href', newUrl).text(newUrl);
160 row.find('.content-edit, .url-edit').hide();
161 row.find('.content-view, .url-view').show();
162 row.find('.save-button').hide();
163 row.find('.edit-button').show();
164 } else {
165 alert('Error saving content.');
166 }
167 },
168 error: function() {
169 alert('An error occurred.');
170 }
171 });
172 });
173
174
175 });
176
177
178
179
180