Advertisement
Guest User

Untitled

a guest
Dec 15th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(){
  2.  
  3.   let form = document.querySelector('form')
  4.  
  5.  let listSection = document.getElementById('list')
  6.  let sentSection = document.querySelector('.sent-list')
  7.  let deleteSection = document.querySelector('.delete-list')
  8.  
  9.  form.children[6].children[1].addEventListener('click', onReset)
  10.  function onReset(e){
  11.   e.preventDefault()
  12.   form.children[1].value = ''
  13.   form.children[3].value = ''
  14.   form.children[5].value = ''
  15.  }
  16.  
  17.  form.children[6].children[0].addEventListener('click', onNext)
  18.  function onNext(e){
  19.   e.preventDefault()
  20.  
  21. if(!form.children[1].value || !form.children[3].value || !form.children[5].value) return
  22. listSection.innerHTML += `<li>
  23. <h4>Title: ${form.children[3].value}</h4>
  24. <h4>Recipient Name: ${form.children[1].value}</h4>
  25. <span>${form.children[5].value}</span>
  26. <div id="list-action">
  27.     <button type="submit" id="send">Send</button>
  28.     <button type="submit" id="delete">Delete</button>
  29. </div>
  30. </li>
  31. `
  32. var nodeListSend = document.querySelectorAll('#send');
  33. var nodeListDel1 = document.querySelectorAll('#delete');
  34.  for (let i = 0; i < nodeListDel1.length; i++) {
  35.         nodeListSend[i].addEventListener('click', onSend);
  36.         nodeListDel1[i].addEventListener('click', clearOne);
  37. }
  38.  
  39. //let newArr = [form.children[1].value, form.children[3].value, form.children[5].value]
  40. form.children[1].value = ''
  41.   form.children[3].value = ''
  42.   form.children[5].value = ''  
  43.  
  44. //document.getElementById('send').addEventListener('click', onSend)
  45. function onSend(e){
  46.   e.preventDefault()
  47.   let currentMail = e.target.parentNode.parentNode;
  48.   let currentTitleRecipient = currentMail.querySelectorAll("h4");
  49.  
  50.   sentSection.innerHTML += `<li>
  51.   <span>To: ${currentTitleRecipient[1].textContent.split(": ")[1]}</span>
  52.   <span>${currentTitleRecipient[0].textContent}</span>
  53.   <div class="btn">
  54.       <button type="submit" class="delete">Delete</button>
  55.   </div>
  56. </li>
  57.   `
  58.   var nodeListDel2 = document.querySelectorAll('.delete');
  59.   for (let i = 0; i < nodeListDel2.length; i++) {
  60.         nodeListDel2[i].addEventListener('click', clearTwo);
  61. }
  62.   //addEventListener('click', clearTwo)
  63.   //listSection.innerHTML = ''
  64.   currentMail.remove();
  65.   e.preventDefault();
  66. }
  67.   //document.getElementById('delete').addEventListener('click', clearOne)
  68.   function clearOne(e){
  69.     e.preventDefault()
  70.    onDelete(e, 1)
  71.    let currentMail = e.target.parentNode.parentNode;
  72.    currentMail.remove();
  73.   //  listSection.innerHTML = ''
  74.   }
  75.   //document.querySelector('.delete').addEventListener('click', clearTwo)
  76.   function clearTwo(e){
  77.     e.preventDefault()
  78.    onDelete(e, 2)
  79.     let currentMail = e.target.parentNode.parentNode;
  80.    currentMail.remove();
  81.  //  sentSection.innerHTML = ''
  82.   }
  83.  function onDelete(e, type){
  84.   let currentData = e.target.parentElement.parentElement;
  85.   let dataArr = []
  86.   if (type == 1){
  87.       dataArr = [currentData.children[1].textContent.split(': ')[1], currentData.children[0].textContent.split(': ')[1]]
  88.   }
  89.   else{
  90.       dataArr = [currentData.children[0].textContent.split(': ')[1], currentData.children[1].textContent.split(': ')[1]]
  91.   }
  92.  
  93.   deleteSection.innerHTML += `
  94.   <li>
  95.       <span>To: ${dataArr[0]}</span>
  96.       <span>Title: ${dataArr[1]}</span>
  97.   </li>`
  98.  }
  99. }    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement