script.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //========================================================================================
  2. // Registration
  3. const registrationForm = document.forms.registration;
  4. if (registrationForm) {
  5. registrationForm.addEventListener("submit", (event) => {
  6. event.preventDefault(); //остановка поведения браузера по дефолту
  7. //Создаем FormData, передаем в него элемент формы
  8. const formData = new FormData(registrationForm);
  9. const name = formData.get("name");
  10. const surname = formData.get("surname");
  11. const address = formData.get("address");
  12. const email = formData.get("email");
  13. const password = formData.get("password");
  14. const user = { name, surname, address, email, password };
  15. //Не имеет значение "" или ''
  16. if (email === "" || password === '')
  17. return
  18. registrationForm.reset()
  19. registrationAddUser(user).then(
  20. data => {
  21. console.log(data);
  22. }).catch(ex => console.log(ex))
  23. })
  24. async function registrationAddUser(user) {
  25. const url = "http://todo/services/registration.php"
  26. const response = await fetch(url, {
  27. method: "POST",
  28. headers: {
  29. "Content-Type": "application/json;charset=utf-8"
  30. },
  31. body: JSON.stringify(user) //преобразует JavaScript в строку JSON
  32. });
  33. const info = await response.json()
  34. return info;
  35. }
  36. }
  37. //========================================================================================
  38. // Login
  39. // Modal =================================================================================
  40. const modals = document.querySelectorAll('[data-name]')
  41. const modalButtons = document.querySelectorAll('button[data-for]')
  42. modalButtons.forEach(button => {
  43. const modalName = button.getAttribute('data-for')
  44. const modal = Array.from(modals).find(element => element.getAttribute('data-name') === modalName)
  45. if (!modal) return;
  46. const closeButton = modal.querySelector('button.task-form__actions_close')
  47. const confirmButton = modal.querySelector('button.task-form__actions_confirm')
  48. button.addEventListener('click', () => {
  49. modal.classList.add('active')
  50. })
  51. modal.addEventListener('click', (event) => {
  52. if (event.target === modal || event.target === closeButton) {
  53. modal.classList.remove('active')
  54. }
  55. })
  56. confirmButton?.addEventListener('click', sendFormHandler)
  57. })
  58. function sendFormHandler(event) {
  59. }
  60. function addCategory(form) {
  61. }
  62. async function createCategory(task) {
  63. }
  64. function addTask(form) {
  65. }
  66. async function createTask(task) {
  67. }
  68. //========================================================================================
  69. // Menu links
  70. //========================================================================================
  71. // Change category to create a task