Advertisement
bebo231312312321

Untitled

Jun 11th, 2023
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     const firstName = document.getElementById('first-name')
  4.     const lastName = document.getElementById("last-name");
  5.     const countInput = document.getElementById('people-count');
  6.     const dateInput = document.getElementById("from-date");
  7.     const daysInput = document.getElementById("days-count")
  8.  
  9.     const ticketPreview = document.querySelector('.ticket-info-list')
  10.     const confirmTicket = document.querySelector('.confirm-ticket')
  11.  
  12.     let nextBtn = document.getElementById('next-btn')
  13.  
  14.     nextBtn.addEventListener('click', onNext)
  15.     function onNext(e) {
  16.         e.preventDefault();
  17.         let firstnameValue = firstName.value
  18.         let lastNameValue = lastName.value;;
  19.         let countInputValue = countInput.value;
  20.         let dateInputValue = dateInput.value;
  21.         let daysInputValue = daysInput.value;
  22.  
  23.         if (!firstName.value || !lastName.value || !countInput.value || !dateInput.value || !daysInput.value) {
  24.             return
  25.         }
  26.  
  27.         let reviewTickets = elementCreate(firstnameValue, lastNameValue, countInputValue, dateInputValue, daysInputValue)
  28.         ticketPreview.appendChild(reviewTickets);
  29.         firstName.value = "";
  30.         lastName.value = "";
  31.         countInput.value = "";
  32.         dateInput.value = "";
  33.         daysInput.value = "";
  34.         nextBtn.disabled = true
  35.     }
  36.  
  37.     function elementCreate(firstnameValue, lastNameValue, countInputValue, dateInputValue, daysInputValue) {
  38.         let ticketLi = document.createElement("li");
  39.         ticketLi.classList.add('ticket');
  40.         let articleEl = document.createElement('article')
  41.  
  42.         let h3Element = document.createElement('h3')
  43.         h3Element.textContent = `Name: ${firstnameValue} ${lastNameValue}`;
  44.         articleEl.appendChild(h3Element)
  45.  
  46.         let pDate = document.createElement('p')
  47.         pDate.textContent = `From date: ${dateInputValue}`
  48.         articleEl.appendChild(pDate);
  49.  
  50.         let pDays = document.createElement('p')
  51.         pDays.textContent = `For ${daysInputValue} days`;
  52.         articleEl.appendChild(pDays);
  53.  
  54.         let pPeople = document.createElement('p');
  55.         pPeople.textContent = `For ${countInputValue} people`;
  56.         articleEl.appendChild(pPeople)
  57.  
  58.         let editBtn = document.createElement('button')
  59.         editBtn.classList.add('edit-btn')
  60.         editBtn.textContent = "Edit"
  61.  
  62.         let contBtn = document.createElement('button');
  63.         contBtn.classList.add('continue-btn')
  64.         contBtn.textContent = "Continue";
  65.         contBtn.addEventListener('click', onContinue);
  66.  
  67.  
  68.         ticketLi.appendChild(articleEl)
  69.         ticketLi.appendChild(editBtn);
  70.         ticketLi.appendChild(contBtn);
  71.  
  72.         editBtn.addEventListener('click', (e) => {
  73.  
  74.             let liThis = e.target.parentElement;
  75.             liThis.remove();
  76.             firstName.value = firstnameValue;
  77.             lastName.value = lastNameValue;
  78.             countInput.value = countInputValue;
  79.             dateInput.value = dateInputValue;
  80.             daysInput.value = daysInputValue;
  81.             nextBtn.disabled = false;
  82.  
  83.         });
  84.         return ticketLi;
  85.     }
  86.    
  87.     function onContinue(e) {
  88.         let liElement = e.target.parentElement;
  89.         let buttons = Array.from(liElement.querySelectorAll('button'));
  90.         buttons.forEach(x => x.remove());
  91.  
  92.         confirmTicket.appendChild(liElement)
  93.  
  94.         let confirmBtn = document.createElement('button')
  95.         confirmBtn.classList.add('confirm-btn')
  96.         confirmBtn.textContent = "Confirm"
  97.         confirmBtn.addEventListener('click', onConfirm)
  98.  
  99.         confirmTicket.appendChild(confirmBtn);
  100.  
  101.         let cancelBtn = document.createElement('button')
  102.         cancelBtn.classList.add('cancel-btn')
  103.         cancelBtn.textContent = "Cancel"
  104.  
  105.         cancelBtn.addEventListener('click', onCancel)
  106.         confirmTicket.appendChild(cancelBtn)
  107.     }
  108.     function onCancel(e) {
  109.  
  110.         let li = e.target.parentElement
  111.         li.remove();
  112.         nextBtn.disabled = false
  113.     };
  114.     function onConfirm(e) {
  115.         const body = document.getElementById('body')
  116.         const h1Text = document.createElement('h1')
  117.         h1Text.classList.add("thank-you")
  118.         h1Text.textContent = "Thank you, have a nice day!"
  119.  
  120.         const backBth = document.createElement('button')
  121.         backBth.classList.add('back-btn')
  122.         backBth.textContent = "Back "
  123.  
  124.         document.getElementById('main').remove();
  125.         body.appendChild(h1Text)
  126.         body.appendChild(backBth)
  127.         backBth.addEventListener('click', (e) => {
  128.             location.reload();
  129.         })
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement