Advertisement
Grossos

autumn adventures

Feb 4th, 2024
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener('load', solve);
  2.  
  3. function solve() {
  4.  
  5.     const input = {
  6.         time: document.getElementById('time'),
  7.         date: document.getElementById('date'),
  8.         place: document.getElementById('place'),
  9.         name: document.getElementById('event-name'),
  10.         email: document.getElementById('email')
  11.     };
  12.  
  13.     const secondField = document.querySelector('.content-second').children[0].children[1];
  14.     const thirdField = document.querySelector('.content-first').children[1].children[1];
  15.     const fourthField = document.querySelector('.content-second').children[1].children[1];
  16.  
  17.     document.getElementById('add-btn').addEventListener('click', addEvent);
  18.  
  19.     function addEvent() {
  20.  
  21.         if (input.time.value == '' || input.date.value == '' || input.place.value == '' || input.name.value == '', input.email.value == '') {
  22.             return;
  23.         }
  24.  
  25.         const li = create('li', '', 'event-content');
  26.         secondField.appendChild(li);
  27.  
  28.         const article = create('article');
  29.         li.appendChild(article);
  30.  
  31.         const values = [input.time.value, input.date.value, input.place.value, input.name.value, input.email.value];
  32.  
  33.         const begins = create('p', `Begins: ${input.date.value} at: ${input.time.value}`);
  34.         const place = create('p', `In: ${input.place.value}`);
  35.         const event = create('p', `Event: ${input.name.value}`);
  36.         const contact = create('p', `Contact: ${input.email.value}`);
  37.         article.appendChild(begins);
  38.         article.appendChild(place);
  39.         article.appendChild(event);
  40.         article.appendChild(contact);
  41.  
  42.         document.getElementById('add-btn').disabled = true;
  43.         Object.values(input).forEach(el => el.value = '');
  44.  
  45.         const editBtn = create('button', 'Edit', 'edit-btn');
  46.         const continueBtn = create('button', 'Continue', 'continue-btn');
  47.         const finishedBtn = create('button', 'Move to Finished', 'finished-btn');
  48.  
  49.         li.appendChild(editBtn);
  50.         li.appendChild(continueBtn);
  51.         editBtn.addEventListener('click', onEdit);
  52.         continueBtn.addEventListener('click', onContinue);
  53.         finishedBtn.addEventListener('click', onFinished);
  54.         document.getElementById('clear').addEventListener('click', onClear);
  55.  
  56.         function onEdit() {
  57.             document.getElementById('time').value = values[0];
  58.             document.getElementById('date').value = values[1];
  59.             document.getElementById('place').value = values[2];
  60.             document.getElementById('event-name').value = values[3];
  61.             document.getElementById('email').value = values[4];
  62.             document.getElementById('add-btn').disabled = false;
  63.             li.remove();
  64.  
  65.         }
  66.  
  67.         function onContinue() {
  68.             thirdField.appendChild(li);
  69.             editBtn.remove();
  70.             continueBtn.remove();
  71.             li.appendChild(finishedBtn);
  72.         }
  73.  
  74.         function onFinished() {
  75.             finishedBtn.remove();
  76.             fourthField.appendChild(li);
  77.             document.getElementById('add-btn').disabled = false;
  78.         }
  79.  
  80.         function onClear(e) {
  81.             li.remove();
  82.         }
  83.     }
  84.  
  85.     function create(type, content, className) {
  86.         const element = document.createElement(type);
  87.         element.textContent = content;
  88.         if (className) {
  89.             element.className = className;
  90.         }
  91.         return element;
  92.     }
  93. }
  94.  
  95.  
  96.  
  97.  
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement