PluginProbe
Tableberg – Simple Gutenberg Table Block / 1.1.5
Tableberg – Simple Gutenberg Table Block v1.1.5
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / admin / src / functions / index.js

index.js in Tableberg – Simple Gutenberg Table Block 1.1.5, at admin/src/functions/index.js

79 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 export const updateBlockProperties = (value, propertyName) => {
2 const data = tablebergAdminMenuData?.block_properties;
3
4 const { url, action, nonce } = data.ajax.blockProperties;
5 const formData = new FormData();
6
7 formData.append("property_name", propertyName);
8 formData.append("value", JSON.stringify(value));
9 formData.append("action", action);
10 formData.append("_wpnonce", nonce);
11
12 fetch(url, {
13 method: "POST",
14 body: formData,
15 });
16 };
17 export const toggleControl = (status, name) => {
18 const data = tablebergAdminMenuData?.[name];
19
20 const { url, action, nonce } = data.ajax.toggleControl;
21 const formData = new FormData();
22
23 formData.append("toggle_name", "tableberg_" + name);
24 formData.append("enable", JSON.stringify(status));
25 formData.append("action", action);
26 formData.append("_wpnonce", nonce);
27
28 fetch(url, {
29 method: "POST",
30 body: formData,
31 });
32 };
33
34 export const testAIConnection = async apiKey => {
35 const data = tablebergAdminMenuData?.ai_settings;
36
37 if (!data?.ajax?.testConnection) {
38 throw new Error("AI settings not available");
39 }
40
41 const { url, action, nonce } = data.ajax.testConnection;
42 const formData = new FormData();
43
44 formData.append("api_key", apiKey);
45 formData.append("action", action);
46 formData.append("_wpnonce", nonce);
47
48 const response = await fetch(url, {
49 method: "POST",
50 body: formData,
51 });
52
53 const result = await response.json();
54 return result;
55 };
56
57 export const saveAISettings = async settings => {
58 const data = tablebergAdminMenuData?.ai_settings;
59
60 if (!data?.ajax?.saveSettings) {
61 throw new Error("AI settings not available");
62 }
63
64 const { url, action, nonce } = data.ajax.saveSettings;
65 const formData = new FormData();
66
67 formData.append("settings", JSON.stringify(settings));
68 formData.append("action", action);
69 formData.append("_wpnonce", nonce);
70
71 const response = await fetch(url, {
72 method: "POST",
73 body: formData,
74 });
75
76 const result = await response.json();
77 return result;
78 };
79