script.js 2.8 KB

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