Advertisement
Niicksana

01. Service

Jun 21st, 2022
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const input = {
  3.         typeProduct: document.getElementById('type-product'),
  4.         description: document.getElementById('description'),
  5.         clientName: document.getElementById('client-name'),
  6.         clientPhone: document.getElementById('client-phone'),
  7.     };
  8.  
  9.     const orders = {
  10.         received: document.getElementById('received-orders'),
  11.         completed: document.getElementById('completed-orders')
  12.     };
  13.  
  14.     document.querySelector('#right button[type=submit]').addEventListener('click', send);
  15.     document.querySelector('.clear-btn').addEventListener('click', clear);
  16.  
  17.     function send(event) {
  18.         event.preventDefault();
  19.  
  20.         // read input fields
  21.         const typeProduct = input.typeProduct.value;
  22.         const description = input.description.value;
  23.         const clientName = input.clientName.value;
  24.         const clientPhone = input.clientPhone.value;
  25.  
  26.         // validate input
  27.         if (!description || !clientName || !clientPhone) {
  28.             return;
  29.         }
  30.  
  31.         // create div item
  32.         const div = document.createElement('div');
  33.         div.className = 'container';
  34.         div.innerHTML = `
  35.             <h2>Product type for repair: ${typeProduct}</h2>
  36.             <h3>Client information: ${clientName}, ${clientPhone}</h3>
  37.             <h4>Description of the problem: ${description}</h4>
  38.             <button class="start-btn">Start repair</button>
  39.             <button class="finish-btn" disabled>Finish repair</button>`;
  40.  
  41.         // add functionality to buttons
  42.         const startRepairBtn = div.querySelector('.start-btn');
  43.         startRepairBtn.addEventListener('click', startRepair);
  44.         const finishRepairBtn = div.querySelector('.finish-btn');
  45.         finishRepairBtn.addEventListener('click', finishRepair);
  46.  
  47.         // append to first list
  48.         orders.received.appendChild(div);
  49.  
  50.         // clear input fields
  51.         //input.typeProduct.value = input.typeProduct[0].value;
  52.         input.description.value = '';
  53.         input.clientName.value = '';
  54.         input.clientPhone.value = '';
  55.  
  56.         function startRepair() {
  57.             startRepairBtn.disabled = true;
  58.             finishRepairBtn.disabled = false;
  59.         }
  60.  
  61.         function finishRepair() {
  62.             startRepairBtn.remove();
  63.             finishRepairBtn.remove();
  64.  
  65.             orders.completed.appendChild(div);
  66.         }
  67.     }
  68.  
  69.     function clear() {
  70.         const containers = Array.from(orders.completed.querySelectorAll('.container'));
  71.  
  72.         containers.forEach(div => {
  73.             div.remove();
  74.         });
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement