Advertisement
vvsvvs

Untitled

Oct 4th, 2022
771
0
120 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     const inputTask = document.getElementById('task');
  4.     const inputDescription = document.getElementById('description');
  5.     const inputDate = document.getElementById('date');
  6.     const addButton = document.getElementById('add');
  7.  
  8.     console.log(inputTask);
  9.  
  10.     let allSections = document.querySelectorAll('section');
  11.  
  12.     let openSection = allSections[1];
  13.     let progressSection = allSections[2];
  14.     let completeSection = allSections[3];
  15.  
  16.     addButton.addEventListener('click', addClick);
  17.  
  18.     function clickFirstBtn(e) {
  19.         let target = e.target;
  20.         let movedArticle = target.parentElement.parentElement;
  21.  
  22.         if (target.className === "green") {
  23.             let finishBtn = document.createElement('button');
  24.             finishBtn.className = 'orange';
  25.             finishBtn.textContent = 'Finish';
  26.  
  27.             target.remove();
  28.  
  29.             let newArticle = movedArticle.cloneNode(true);
  30.  
  31.             finishBtn.addEventListener('click', clickFirstBtn);
  32.             newArticle.children[3].appendChild(finishBtn);
  33.             newArticle.children[3].children[0].addEventListener('click', clickSecondBtn)
  34.  
  35.             movedArticle.remove();
  36.  
  37.             progressSection.children[1].appendChild(newArticle);
  38.         } else if (target.className === "orange") {
  39.             movedArticle.children[3].remove();
  40.             let newArticle = movedArticle.cloneNode(true);
  41.             movedArticle.remove();
  42.  
  43.             completeSection.children[1].appendChild(newArticle);
  44.         }
  45.     }
  46.  
  47.     function clickSecondBtn(e) {
  48.         let movedArticle = e.target.parentElement.parentElement;
  49.         movedArticle.remove();
  50.     }
  51.    
  52.     function addClick(e) {
  53.         e.preventDefault();
  54.         let task = inputTask.value;
  55.         let descr = inputDescription.value;
  56.         let date = inputDate.value;
  57.         console.log(inputTask.value);
  58.  
  59.         if (task === '' || descr === '' || date === '') {
  60.             return;
  61.         }
  62.  
  63.         let articleElement = document.createElement('article');
  64.         let divElement = document.createElement('div');
  65.         divElement.className = "flex";
  66.  
  67.         let startBtn = document.createElement('button');
  68.         let deleteBtn = document.createElement('button');
  69.         startBtn.className = "green";
  70.         deleteBtn.className = "red";
  71.  
  72.         startBtn.textContent = 'Start';
  73.         deleteBtn.textContent = 'Delete';
  74.  
  75.         startBtn.addEventListener('click', clickFirstBtn);
  76.         deleteBtn.addEventListener('click', clickSecondBtn);
  77.  
  78.         divElement.appendChild(startBtn);
  79.         divElement.appendChild(deleteBtn);
  80.  
  81.         articleElement.innerHTML = `<h3>${task}</h3><p>Description: ${descr}</p><p>Due Date: ${date}</p>`;
  82.  
  83.         articleElement.appendChild(divElement);
  84.  
  85.         openSection.children[1].appendChild(articleElement);
  86.     }
  87.  
  88.  
  89.  
  90.  
  91.     console.log(allSections)
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement