2018-05-08 00:15:40 +02:00
|
|
|
class bluditAjax {
|
|
|
|
|
2019-05-10 11:35:23 +02:00
|
|
|
static async saveAsDraft(uuid, title, content) {
|
2019-05-09 19:31:55 +02:00
|
|
|
let url = HTML_PATH_ADMIN_ROOT+"ajax/save-as-draft"
|
|
|
|
try {
|
|
|
|
const response = await fetch(url, {
|
|
|
|
credentials: 'same-origin',
|
|
|
|
method: "POST",
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
}),
|
|
|
|
body: new URLSearchParams({
|
|
|
|
'tokenCSRF': tokenCSRF,
|
|
|
|
'uuid': "autosave-" + uuid,
|
|
|
|
'title': title,
|
|
|
|
'content': content
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
return true;
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
2019-05-09 19:31:55 +02:00
|
|
|
}
|
2018-05-08 00:15:40 +02:00
|
|
|
|
2019-05-10 11:35:23 +02:00
|
|
|
static async removeLogo() {
|
|
|
|
let url = HTML_PATH_ADMIN_ROOT+"ajax/remove-logo"
|
2019-05-09 19:31:55 +02:00
|
|
|
try {
|
|
|
|
const response = await fetch(url, {
|
|
|
|
credentials: 'same-origin',
|
|
|
|
method: "POST",
|
|
|
|
headers: new Headers({
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
|
|
|
|
}),
|
|
|
|
body: new URLSearchParams({
|
2019-05-10 11:35:23 +02:00
|
|
|
'tokenCSRF': tokenCSRF
|
2019-05-09 19:31:55 +02:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
|
|
|
|
2018-06-24 13:37:45 +02:00
|
|
|
// Alert the user when the user is not logged
|
|
|
|
userLogged(callBack) {
|
|
|
|
var ajaxRequest;
|
|
|
|
if (ajaxRequest) {
|
|
|
|
ajaxRequest.abort();
|
|
|
|
}
|
|
|
|
|
2018-07-02 00:24:53 +02:00
|
|
|
console.log("[INFO] [BLUDIT AJAX] [userLogged()] Checking if the user is logged.");
|
2018-06-24 13:37:45 +02:00
|
|
|
|
|
|
|
ajaxRequest = $.ajax({
|
2018-08-01 22:04:28 +02:00
|
|
|
type: "GET",
|
2018-07-28 18:33:37 +02:00
|
|
|
url: HTML_PATH_ADMIN_ROOT+"ajax/user-logged"
|
2018-06-24 13:37:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ajaxRequest.done(function (response, textStatus, jqXHR) {
|
2018-07-02 00:24:53 +02:00
|
|
|
console.log("[INFO] [BLUDIT AJAX] [userLogged()] The user is logged.");
|
2018-06-24 13:37:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ajaxRequest.fail(function (jqXHR, textStatus, errorThrown) {
|
|
|
|
// The fail is produced by admin.php when the user is not logged the ajax request is not possible and returns 401
|
2018-07-02 00:24:53 +02:00
|
|
|
console.log("[INFO] [BLUDIT AJAX] [userLogged()] The user is NOT logged.");
|
2018-06-24 13:37:45 +02:00
|
|
|
if (jqXHR.status==401) {
|
2018-07-17 13:53:50 +02:00
|
|
|
callBack("You are not logged in anymore, so Bludit can't save your settings and content.");
|
2018-06-24 13:37:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
generateSlug(text, parentKey, currentKey, callBack) {
|
|
|
|
var ajaxRequest;
|
|
|
|
if (ajaxRequest) {
|
|
|
|
ajaxRequest.abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
ajaxRequest = $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
tokenCSRF: tokenCSRF,
|
|
|
|
text: text,
|
|
|
|
parentKey: parentKey,
|
|
|
|
currentKey: currentKey
|
|
|
|
},
|
2018-07-28 18:33:37 +02:00
|
|
|
url: HTML_PATH_ADMIN_ROOT+"ajax/generate-slug"
|
2018-05-08 00:15:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ajaxRequest.done(function (response, textStatus, jqXHR) {
|
|
|
|
console.log("Bludit AJAX: generateSlug(): done handler");
|
|
|
|
callBack.val(response["slug"]);
|
|
|
|
});
|
|
|
|
|
|
|
|
ajaxRequest.fail(function (jqXHR, textStatus, errorThrown) {
|
|
|
|
console.log("Bludit AJAX: generateSlug(): fail handler");
|
|
|
|
});
|
|
|
|
|
|
|
|
ajaxRequest.always(function () {
|
|
|
|
console.log("Bludit AJAX: generateSlug(): always handler");
|
|
|
|
});
|
|
|
|
}
|
2018-10-17 22:35:30 +02:00
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|