PluginProbe
wpForo Forum / 3.1.6
wpForo Forum v3.1.6
3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 138 releases
wpforo / blocks / online-members / index.js

index.js in wpForo Forum 3.1.6, at blocks/online-members/index.js

101 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function (blocks, editor, components, i18n, element) {
2 var el = element.createElement;
3 var Fragment = element.Fragment;
4 var __ = i18n.__;
5 var InspectorControls = editor.InspectorControls;
6 var useBlockProps = editor.useBlockProps;
7 var PanelBody = components.PanelBody;
8 var TextControl = components.TextControl;
9 var ToggleControl = components.ToggleControl;
10 var SelectControl = components.SelectControl;
11
12 // Check for NumberControl existence, fallback to TextControl if needed
13 var NumberControl = components.NumberControl || components.TextControl;
14
15 blocks.registerBlockType('wpforo/online-members', {
16 title: __('wpForo Online Members', 'wpforo'),
17 icon: 'groups',
18 category: 'widgets',
19 edit: function (props) {
20 var attributes = props.attributes;
21 var setAttributes = props.setAttributes;
22 var blockProps = useBlockProps();
23
24 var userGroups = window.wpforo_block_data ? window.wpforo_block_data.user_groups : [];
25 if (userGroups.length === 0) {
26 console.warn('wpForo Online Members: No user groups found in window.wpforo_block_data');
27 }
28 var options = userGroups.map(function (group) {
29 return { value: String(group.groupid), label: group.name + ' (' + group.count + ')' };
30 });
31
32 var groupids = attributes.groupids || [];
33 var selectedGroupids = groupids.map(String);
34
35 return el(Fragment, null,
36 el(InspectorControls, { key: 'inspector' },
37 el(PanelBody, { title: __('Settings', 'wpforo') },
38 el(TextControl, {
39 label: __('Title', 'wpforo'),
40 value: attributes.title,
41 onChange: function (value) {
42 setAttributes({ title: value });
43 },
44 }),
45 el(SelectControl, {
46 multiple: true,
47 label: __('User Groups', 'wpforo'),
48 value: selectedGroupids,
49 options: options,
50 onChange: function (value) {
51 setAttributes({ groupids: value.map(Number) });
52 },
53 }),
54 el(NumberControl, {
55 label: __('Number of Items', 'wpforo'),
56 value: attributes.count,
57 min: 1,
58 type: 'number',
59 onChange: function (value) {
60 setAttributes({ count: parseInt(value) || 1 });
61 },
62 }),
63 el(ToggleControl, {
64 label: __('Display with avatars', 'wpforo'),
65 checked: attributes.display_avatar,
66 onChange: function (value) {
67 setAttributes({ display_avatar: value });
68 },
69 }),
70 el(NumberControl, {
71 label: __('Auto Refresh Interval Seconds', 'wpforo'),
72 help: __('Set 0 to disable autorefresh', 'wpforo'),
73 value: attributes.refresh_interval,
74 min: 0,
75 type: 'number',
76 onChange: function (value) {
77 setAttributes({ refresh_interval: parseInt(value) || 0 });
78 },
79 }),
80 ),
81 ),
82 el('div', blockProps,
83 el('div', { className: 'wpf-block-placeholder' },
84 el('span', { className: 'dashicons dashicons-groups' }),
85 __('wpForo Online Members', 'wpforo'),
86 ),
87 ),
88 );
89 },
90 save: function () {
91 return null;
92 },
93 });
94 })(
95 window.wp.blocks,
96 window.wp.blockEditor,
97 window.wp.components,
98 window.wp.i18n,
99 window.wp.element,
100 );
101