Site-Proximo/assets/js/ajaxManager.js
2020-02-12 11:44:29 +01:00

63 lines
1.7 KiB
JavaScript

class AjaxManager {
static async getAll() {
let categories = await AjaxManager.get('category');
let articles = await AjaxManager.get('article');
let article_categories = await AjaxManager.get('article_categories');
return {articles: articles, categories: categories, article_categories: article_categories};
}
static async get(type) {
let data = {
type: type,
action: 'get',
};
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['data'];
}
static async delete(id, type) {
let data = {
type: type,
action: 'remove',
data: id,
};
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['status'];
}
static async save(data, isNew, type) {
let formattedData = {
type: type,
action: isNew ? 'create' : 'update',
data: data,
};
let response = await $.ajax({
type: "POST",
url: "save_manager.php",
data: JSON.stringify(formattedData),
dataType: "json",
contentType: "application/json; charset=utf-8",
});
console.log(response);
return response['data'];
}
}