Advertisement
drak138

01.Tech Troubleshoot Hub

Jun 15th, 2024
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solution() {
  2.   const emplyeeRef=document.getElementById("employee")
  3.   const categoryRef=document.getElementById("category")
  4.   const urgencyRef=document.getElementById("urgency")
  5.   const teamRef=document.getElementById("team");
  6.   const descriptionRef=document.getElementById("description")
  7.   const addBtnRef=document.getElementById("add-btn")
  8.   const previewListRef=document.querySelector(".preview-list")
  9.   const pendingListRef=document.querySelector(".pending-list")
  10.   const resolvedListRef=document.querySelector(".resolved-list")
  11.   addBtnRef.setAttribute("type","button")
  12.  
  13.   addBtnRef.addEventListener("click",add)
  14.  
  15.   function add(){
  16.  
  17.     function create(element,attribute,attributeName,functionName,name){
  18.       const result=document.createElement(element)
  19.       result.textContent=name
  20.       result.setAttribute(`${attribute}`,`${attributeName}`)
  21.       if(element==="button"){
  22.       result.textContent=name
  23.       result.addEventListener("click",functionName)
  24.       }
  25.       return result
  26.     }
  27.  
  28.     const inputArr=[
  29.       emplyeeRef,
  30.       categoryRef,
  31.       urgencyRef,
  32.       teamRef,
  33.       descriptionRef
  34.     ]
  35.     if(!inputArr.some(el=>el.value==="")){
  36.       const previewList=createPreview(emplyeeRef.value,
  37.         categoryRef.value,
  38.         urgencyRef.value,
  39.         teamRef.value,
  40.         descriptionRef.value)
  41.         previewListRef.appendChild(previewList)
  42.     }
  43.     function createPreview(employee,category,urgency,team,description){
  44.       const pEmployee=document.createElement("p")
  45.       pEmployee.textContent=`From: ${employee}`
  46.  
  47.       const pCategory=document.createElement("p")
  48.       pCategory.textContent=`Category: ${category}`
  49.  
  50.       const pUrgency=document.createElement("p")
  51.       pUrgency.textContent=`Urgency: ${urgency}`
  52.  
  53.       const pTeam=document.createElement("p")
  54.       pTeam.textContent=`Assigned to: ${team}`
  55.  
  56.       const pDescription=document.createElement("p")
  57.       pDescription.textContent=`Description: ${description}`
  58.  
  59.       const article=document.createElement("article")
  60.       article.appendChild(pEmployee)
  61.       article.appendChild(pCategory)
  62.       article.appendChild(pUrgency)
  63.       article.appendChild(pTeam)
  64.       article.appendChild(pDescription)
  65.  
  66.       const editBtn=create("button","class","edit-btn",edit,"Edit")
  67.       const continueBtn=create("button","class","continue-btn",onContinue,"Continue")
  68.  
  69.  
  70.       const li= create("li","class","problem-content")
  71.       li.appendChild(article)
  72.       li.appendChild(editBtn)
  73.       li.appendChild(continueBtn)
  74.  
  75.         emplyeeRef.value=""
  76.         categoryRef.value=""
  77.         urgencyRef.value=""
  78.         teamRef.value=""
  79.         descriptionRef.value=""
  80.  
  81.         addBtnRef.disabled=true
  82.  
  83.         function edit(){
  84.           //remove li
  85.           li.remove()
  86.           //copy Info
  87.           emplyeeRef.value=employee
  88.         categoryRef.value=category
  89.         urgencyRef.value=urgency
  90.         teamRef.value=team
  91.         descriptionRef.value=description
  92.           //enable btn
  93.           addBtnRef.disabled=false
  94.  
  95.         }
  96.  
  97.         function onContinue(){
  98.           //remove li
  99.           li.remove()
  100.           //copyInfo
  101.           const pendingArticle=article
  102.           //add resolve
  103.           const resolveBtn=create("button","class","resolve-btn",resolve,"Resolved")
  104.           //append info
  105.           const pendingLi=create("li","class","problem-content")
  106.           pendingLi.appendChild(pendingArticle)
  107.           pendingLi.appendChild(resolveBtn)
  108.           pendingListRef.appendChild(pendingLi)
  109.           //enableBtn
  110.           addBtnRef.disabled=false
  111.  
  112.  
  113.           function resolve(){
  114.             //remove list
  115.             pendingLi.remove()
  116.             //copy info
  117.             const resolveArticle=pendingArticle
  118.             //add clear
  119.             const clearBtn=create("button","class","clear-btn",clear,"Clear")
  120.             //append Info
  121.             const resolvedLi=create("li","class","problem-content")
  122.             resolvedLi.appendChild(resolveArticle)
  123.             resolvedLi.appendChild(clearBtn)
  124.             resolvedListRef.appendChild(resolvedLi)
  125.             //enableBtn
  126.             addBtnRef.disabled=false
  127.  
  128.             function clear(){
  129.               resolvedLi.remove()
  130.               addBtnRef.disabled=false
  131.  
  132.             }
  133.           }
  134.         }
  135.  
  136.       return li
  137.     }
  138.   }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement