Guest User

Untitled

a guest
Dec 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. if (cookie == 1) {
  2. alert("Oi, você enviou uma mensagem a pouco tempo, em breve vamos te responder, ok?");
  3. return;
  4. }
  5.  
  6. if (document.querySelector('.menu-help-box-form')) {
  7. document.querySelector('.menu-help-box-form').addEventListener('submit', function (event) {
  8.  
  9. var cookie = getCookieValue('form_help_box');
  10.  
  11. if (cookie == 1) {
  12. alert("Oi, você enviou uma mensagem a pouco tempo, em breve vamos te responder, ok?");
  13. return;
  14. }
  15.  
  16. event.preventDefault();
  17. var formD = new FormData(this);
  18. var helpBObject = {};
  19. var con = {
  20. 0: "name",
  21. 1: "email",
  22. 2: "reason",
  23. 3: "message"
  24. };
  25. var numCont = 0;
  26.  
  27. formD.forEach(function (element) {
  28. helpBObject[con[numCont]] = element;
  29. numCont++;
  30. });
  31.  
  32. $.ajax({
  33. url: "/api/dataentities/HB/documents",
  34. type: "POST",
  35. timeout: 0,
  36. headers: {
  37. "Content-Type": "application/json",
  38. "Accept": "application/vnd.vtex.ds.v10+json"
  39. },
  40. data: JSON.stringify(helpBObject),
  41. success: function () {
  42. document.querySelector('.success-send-form-help').style.display = "flex";
  43. var d = new Date();
  44. d.setTime(d.getTime() + (1 * 24 * 60 * 60 * 1000));
  45. var expires = "expires=" + d.toUTCString();
  46. document.cookie = "form_help_box=1; " + expires + "; path=/";
  47. },
  48. error: function (error) {
  49. console.log("Erro Help Box: ", error);
  50. }
  51. });
  52. });
  53.  
  54. document.querySelector('.cancel-send-form-help').addEventListener('click', function () {
  55. document.querySelector('.menu-help-box-form').style.display = "none";
  56. if (document.querySelector('.success-send-form-help')) {
  57. document.querySelector('.success-send-form-help').style.display = "none";
  58. }
  59. document.querySelector('.menu-help-box-ul').style.display = "block";
  60. });
  61. }
Add Comment
Please, Sign In to add comment