123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //========================================================================================
- // Registration
- const registrationForm = document.forms.registration;
- if (registrationForm) {
- registrationForm.addEventListener("submit", (event) => {
- event.preventDefault(); //остановка поведения браузера по дефолту
- //Создаем FormData, передаем в него элемент формы
- const formData = new FormData(registrationForm);
- const name = formData.get("name");
- const surname = formData.get("surname");
- const address = formData.get("address");
- const email = formData.get("email");
- const password = formData.get("password");
- const user = { name, surname, address, email, password };
- //Не имеет значение "" или ''
- if (email === "" || password === '')
- return
- registrationForm.reset()
- registrationAddUser(user).then(
- data => {
- console.log(data);
- }).catch(ex => console.log(ex))
- })
- async function registrationAddUser(user) {
- const url = "http://todo/services/registration.php"
- const response = await fetch(url, {
- method: "POST",
- headers: {
- "Content-Type": "application/json;charset=utf-8"
- },
- body: JSON.stringify(user) //преобразует JavaScript в строку JSON
- });
- const info = await response.json()
- return info;
- }
- }
- //========================================================================================
- // Login
- // Modal =================================================================================
- const modals = document.querySelectorAll('[data-name]')
- const modalButtons = document.querySelectorAll('button[data-for]')
- modalButtons.forEach(button => {
- const modalName = button.getAttribute('data-for')
- const modal = Array.from(modals).find(element => element.getAttribute('data-name') === modalName)
- if (!modal) return;
- const closeButton = modal.querySelector('button.task-form__actions_close')
- const confirmButton = modal.querySelector('button.task-form__actions_confirm')
- button.addEventListener('click', () => {
- modal.classList.add('active')
- })
- modal.addEventListener('click', (event) => {
- if (event.target === modal || event.target === closeButton) {
- modal.classList.remove('active')
- }
- })
- confirmButton?.addEventListener('click', sendFormHandler)
- })
- function sendFormHandler(event) {
- }
- function addCategory(form) {
- }
- async function createCategory(task) {
- }
- function addTask(form) {
- }
- async function createTask(task) {
- }
- //========================================================================================
- // Menu links
- //========================================================================================
- // Change category to create a task
|