PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.4.6
MxChat – AI Chatbot & Content Generation for WordPress v2.4.6
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 / meta-box.js

meta-box.js in MxChat – AI Chatbot & Content Generation for WordPress 2.4.6, at js/meta-box.js

105 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 if (typeof wp !== 'undefined' && wp.editPost && wp.components && wp.element) {
3 var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;
4 var CheckboxControl = wp.components.CheckboxControl;
5 var SelectControl = wp.components.SelectControl;
6 var PanelRow = wp.components.PanelRow;
7 var Notice = wp.components.Notice;
8 var useSelect = wp.data.useSelect;
9 var useDispatch = wp.data.useDispatch;
10
11 function MxChatSettingsPanel() {
12 var meta = useSelect(function(select) {
13 return select('core/editor').getEditedPostAttribute('meta') || {};
14 });
15
16 var editPost = useDispatch('core/editor').editPost;
17 var hideChatbot = meta._mxchat_hide_chatbot === '1';
18 var selectedBot = meta._mxchat_selected_bot || '';
19
20 // Bot options will be populated from localized data
21 var botOptions = [
22 { label: mxchatMetaBox.strings.useGlobalSetting, value: '' }
23 ];
24
25 if (mxchatMetaBox.hasMultibot && mxchatMetaBox.availableBots) {
26 Object.keys(mxchatMetaBox.availableBots).forEach(function(botId) {
27 botOptions.push({
28 label: mxchatMetaBox.availableBots[botId],
29 value: botId
30 });
31 });
32 }
33
34 var elements = [
35 wp.element.createElement(
36 PanelRow,
37 null,
38 wp.element.createElement(CheckboxControl, {
39 label: mxchatMetaBox.strings.hideChatbot,
40 help: mxchatMetaBox.strings.hideChatbotHelp,
41 checked: hideChatbot,
42 onChange: function(value) {
43 editPost({
44 meta: Object.assign({}, meta, {
45 _mxchat_hide_chatbot: value ? '1' : ''
46 })
47 });
48 }
49 })
50 )
51 ];
52
53 // Add bot selection if multi-bot is available
54 if (mxchatMetaBox.hasMultibot && botOptions.length > 1) {
55 elements.push(
56 wp.element.createElement(
57 PanelRow,
58 null,
59 wp.element.createElement(SelectControl, {
60 label: mxchatMetaBox.strings.selectBot,
61 value: selectedBot,
62 options: botOptions,
63 onChange: function(value) {
64 editPost({
65 meta: Object.assign({}, meta, {
66 _mxchat_selected_bot: value
67 })
68 });
69 }
70 })
71 )
72 );
73
74 // Add info notice
75 elements.push(
76 wp.element.createElement(
77 Notice,
78 {
79 status: 'info',
80 isDismissible: false,
81 className: 'mxchat-info-notice'
82 },
83 mxchatMetaBox.globalAutoshow
84 ? mxchatMetaBox.strings.globalAutoshowOn
85 : mxchatMetaBox.strings.globalAutoshowOff
86 )
87 );
88 }
89
90 return wp.element.createElement(
91 PluginDocumentSettingPanel,
92 {
93 name: 'mxchat-settings',
94 title: mxchatMetaBox.strings.panelTitle,
95 className: 'mxchat-settings-panel'
96 },
97 elements
98 );
99 }
100
101 wp.plugins.registerPlugin('mxchat-settings', {
102 render: MxChatSettingsPanel
103 });
104 }
105 })();