Skip to content
Snippets Groups Projects
Commit 7d12f4b6 authored by Matthias Konitzny's avatar Matthias Konitzny :fire:
Browse files

Data between server and client is now exchanged using the fetch API. #25

parent 5273818f
Branches
No related tags found
1 merge request!3Master into new editor
Pipeline #56330 failed
/*global ks_global*/ /*global ks_global*/
import jQuery from "jquery";
/** /**
* Returns the json object from the stored graph as promise. * Returns the json object from the stored graph as promise.
* *
...@@ -10,18 +8,18 @@ import jQuery from "jquery"; ...@@ -10,18 +8,18 @@ import jQuery from "jquery";
* @returns Promise returning graph object. * @returns Promise returning graph object.
*/ */
export function loadGraphJson(spaceId) { export function loadGraphJson(spaceId) {
let payload = { const data = new FormData();
action: "get_space", data.append("action", "get_space");
space: spaceId, data.append("space", spaceId);
let opts = {
method: "POST",
body: data,
}; };
return jQuery return fetch(ks_global.ajax_url, opts).then(function (response) {
.ajax({ return response.json();
type: "POST", });
url: ks_global.ajax_url,
data: payload,
})
.then((data) => JSON.parse(data));
} }
/** /**
...@@ -33,16 +31,18 @@ export function loadGraphJson(spaceId) { ...@@ -33,16 +31,18 @@ export function loadGraphJson(spaceId) {
* @returns Promise returning state of query. * @returns Promise returning state of query.
*/ */
export function saveGraphJson(spaceId, json) { export function saveGraphJson(spaceId, json) {
let payload = { const data = new FormData();
action: "update_space", data.append("action", "update_space");
graph: JSON.stringify(json), data.append("space", spaceId);
space: spaceId, data.append("graph", JSON.stringify(json));
let opts = {
method: "POST",
body: data,
}; };
return jQuery.ajax({ return fetch(ks_global.ajax_url, opts).then(function (response) {
type: "POST", return response.json();
url: ks_global.ajax_url,
data: payload,
}); });
} }
...@@ -52,15 +52,17 @@ export function saveGraphJson(spaceId, json) { ...@@ -52,15 +52,17 @@ export function saveGraphJson(spaceId, json) {
* @returns A promise containing an array containing all available space ids. * @returns A promise containing an array containing all available space ids.
*/ */
export function listAllSpaces() { export function listAllSpaces() {
let payload = { const data = new FormData();
action: "list_spaces", data.append("action", "list_spaces");
let opts = {
method: "POST",
body: data,
}; };
return jQuery return fetch(ks_global.ajax_url, opts)
.ajax({ .then(function (response) {
type: "POST", return response.json();
url: ks_global.ajax_url,
data: payload,
}) })
.then((data) => JSON.parse(data)["spaces"]); .then((data) => data.spaces);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment