Site du proximo, utilisé pour gérer le stock.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ajaxManager.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. class AjaxManager {
  2. static async getAll() {
  3. let categories = await AjaxManager.get('category');
  4. let articles = await AjaxManager.get('article');
  5. let article_categories = await AjaxManager.get('article_categories');
  6. return {articles: articles, categories: categories, article_categories: article_categories};
  7. }
  8. static async get(type) {
  9. let data = {
  10. type: type,
  11. action: 'get',
  12. };
  13. let response = await $.ajax({
  14. type: "POST",
  15. url: "save_manager.php",
  16. data: JSON.stringify(data),
  17. dataType: "json",
  18. contentType: "application/json; charset=utf-8",
  19. });
  20. console.log(response);
  21. return response['data'];
  22. }
  23. static async delete(id, type) {
  24. let data = {
  25. type: type,
  26. action: 'remove',
  27. data: id,
  28. };
  29. let response = await $.ajax({
  30. type: "POST",
  31. url: "save_manager.php",
  32. data: JSON.stringify(data),
  33. dataType: "json",
  34. contentType: "application/json; charset=utf-8",
  35. });
  36. console.log(response);
  37. return response['status'];
  38. }
  39. static async save(data, isNew, type) {
  40. let formattedData = {
  41. type: type,
  42. action: isNew ? 'create' : 'update',
  43. data: data,
  44. };
  45. let response = await $.ajax({
  46. type: "POST",
  47. url: "save_manager.php",
  48. data: JSON.stringify(formattedData),
  49. dataType: "json",
  50. contentType: "application/json; charset=utf-8",
  51. });
  52. console.log(response);
  53. return response['data'];
  54. }
  55. }