Advertisement
Grossos

taskmanager

Feb 3rd, 2024
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     const input = {
  4.         name: document.getElementById('task'),
  5.         description: document.getElementById('description'),
  6.         date: document.getElementById('date')
  7.     };
  8.  
  9.     const [_, openSection, progressSection, finishedSection] = Array.from(document.querySelectorAll('section')).map(el => el.children[1]);
  10.  
  11.     document.getElementById('add').addEventListener('click', addTask);
  12.  
  13.     function addTask(event) {
  14.         event.preventDefault();
  15.    
  16.         // create elements
  17.         const article = document.createElement('article');
  18.         article.appendChild(create('h3', input.name.value));
  19.         article.appendChild(create('p', `Description: ${input.description.value}`));
  20.         article.appendChild(create('p', `Due Date: ${input.date.value}`));
  21.         const div = create('div', '', 'flex');
  22.  
  23.         const startButton = create('button', 'Start', 'green');
  24.         const deleteButton = create('button', 'Delete', 'red');
  25.         const finishButton = create('button', 'Finish', 'orange');
  26.  
  27.         div.appendChild(startButton);
  28.         div.appendChild(deleteButton);
  29.         article.appendChild(div);
  30.  
  31.         // append to Open Section
  32.         openSection.appendChild(article);
  33.  
  34.         Object.values(input).forEach(el => el.value = '');
  35.         // ** add functionality for start, finish, delete task
  36.  
  37.         startButton.addEventListener('click', onStart);
  38.         deleteButton.addEventListener('click', onDelete);
  39.         finishButton.addEventListener('click', onFinish);
  40.  
  41.         function onDelete() {
  42.             article.remove();
  43.         }
  44.  
  45.         function onStart() {
  46.             startButton.remove();
  47.             div.appendChild(finishButton);
  48.             progressSection.appendChild(article);
  49.         }
  50.  
  51.         function onFinish() {
  52.             div.remove()
  53.             finishedSection.appendChild(article);
  54.         }
  55.     }
  56.  
  57.     function create(type, content, className) {
  58.         const element = document.createElement(type);
  59.         element.textContent = content;
  60.         if (className) {
  61.             element.className = className;
  62.         }
  63.         return element;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement