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.

post-review.js 1.7KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. document.addEventListener("DOMContentLoaded", function(){
  2. document.getElementById("cancelBtn").onclick = function(){
  3. window.location = "/main";
  4. }
  5. var id;
  6. async function loadPost(){
  7. var response = await fetch("/getReviewPost", {
  8. method: "GET",
  9. headers: {
  10. "Accept":"application/json",
  11. "Content-Type":"application/json"
  12. }
  13. })
  14. var data = await response.json();
  15. id = data.post[0].postid;
  16. document.getElementsByClassName("canvas")[0].style.backgroundColor = data.post[0].bcolor;
  17. document.getElementsByClassName("canvas")[1].style.backgroundColor = data.post[0].bcolor;
  18. document.getElementById("title-canvas").innerHTML = data.post[0].title;
  19. document.getElementById("editor-canvas").innerHTML = data.post[0].text;
  20. if(data.post[0].showpost) {
  21. document.getElementById("submit-post").innerHTML = "Suspend Post"
  22. } else {
  23. document.getElementById("submit-post").innerHTML = "Confirm Post"
  24. }
  25. };
  26. loadPost();
  27. document.getElementById("submit-post").onclick = function(){
  28. toggleShow(id);
  29. }
  30. async function toggleShow(pun){
  31. var response = await fetch("/toggleShow", {
  32. method: "POST",
  33. headers: {
  34. "Accept":"application/json",
  35. "Content-Type":"application/json"
  36. },
  37. body:JSON.stringify({postid:pun})
  38. })
  39. var data = await response.json();
  40. console.log(data);
  41. if(data.suc || !data.suc){
  42. window.location = "/main"
  43. }
  44. };
  45. });