Advertisement
ilianrusev

task manager

Feb 2nd, 2022
106
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.  
  4. let buttonAdd = document.getElementById("add")
  5.  
  6. buttonAdd.addEventListener("click", onClick)
  7.  
  8. function onClick(ev) {
  9. ev.preventDefault()
  10. let taskInput = document.getElementById("task")
  11. let descriptionInput = document.getElementById("description")
  12. let dateInput = document.getElementById("date")
  13.  
  14. if (taskInput.value && descriptionInput.value && dateInput.value) {
  15. let article = document.createElement("article")
  16. let h3 = document.createElement("h3")
  17. let pDescription = document.createElement("p")
  18. let pDate = document.createElement("p")
  19. let div = document.createElement("div")
  20. div.classList.add("flex")
  21. let buttonStart = document.createElement("button")
  22. let buttonDelete = document.createElement("button")
  23. buttonStart.classList.add("green")
  24. buttonStart.textContent = "Start"
  25. buttonDelete.classList.add("red")
  26. buttonDelete.textContent = "Delete"
  27.  
  28. buttonStart.addEventListener("click", onStart)
  29. buttonDelete.addEventListener("click", onDelete)
  30.  
  31. h3.textContent = taskInput.value
  32. pDescription.textContent = `Description: ${descriptionInput.value}`
  33. pDate.textContent = `Due Date: ${dateInput.value}`
  34.  
  35. div.appendChild(buttonStart)
  36. div.appendChild(buttonDelete)
  37. article.appendChild(h3)
  38. article.appendChild(pDescription)
  39. article.appendChild(pDate)
  40. article.appendChild(div)
  41.  
  42. document.getElementsByClassName("orange")[0].parentNode.parentNode.children[1].appendChild(article)
  43.  
  44. taskInput.value = ""
  45. descriptionInput.value = ""
  46. dateInput.value = ""
  47. }
  48.  
  49. function onStart(ev) {
  50. let first = ev.target.parentNode.children[0] //selecting the start button
  51. let buttonFinish = document.createElement("button")
  52. buttonFinish.classList.add("orange")
  53. buttonFinish.textContent = "Finish"
  54.  
  55. buttonFinish.addEventListener("click", onFinish)
  56.  
  57. ev.target.parentNode.appendChild(buttonFinish)
  58. document.getElementById("in-progress").appendChild(ev.target.parentNode.parentNode)
  59. ev.target.parentNode.removeChild(first) //removing the start button
  60.  
  61. }
  62.  
  63. function onDelete(ev) {
  64. ev.target.parentNode.parentNode.remove()
  65. }
  66.  
  67. function onFinish(ev) {
  68. document.querySelector("h1.green").parentNode.parentNode.children[1].appendChild(ev.target.parentNode.parentNode)
  69.  
  70. ev.target.parentNode.remove() //remove all btns
  71.  
  72. }
  73. }
  74. }
Advertisement
RAW Paste Data Copied
Advertisement