Advertisement
Liliana797979

locked profile - js apllications

Nov 5th, 2021
1,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lockedProfile() {
  2.     createElement();
  3.  
  4.     document.getElementById(`main`).addEventListener(`click`, onToggle);
  5.  
  6.     function onToggle(event) {
  7.         const button = event.target;
  8.         const profile = button.parentNode;
  9.         const moreInformation = profile.getElementsByTagName(`div`)[0];
  10.         const lockStatus = profile.querySelector(`input[type="radio"]:checked`).value;
  11.  
  12.         if (lockStatus === `unlock`) {
  13.             if (button.textContent === `Show more`) {
  14.                 moreInformation.style.display = `inline-block`;
  15.                 button.textContent = `Hide it`;
  16.             } else if (button.textContent === `Hide it`) {
  17.                 moreInformation.style.display = `none`;
  18.                 button.textContent = `Show more`;
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. const main = document.getElementById(`main`);
  25.  
  26. async function getProfiles() {
  27.     const urlProfiles = `http://localhost:3030/jsonstore/advanced/profiles`;
  28.  
  29.     const res = await fetch(urlProfiles);
  30.     const data = await res.json();
  31.  
  32.     return data;
  33. }
  34.  
  35. async function createElement() {
  36.     main.replaceChildren();
  37.  
  38.     const data = await getProfiles();
  39.  
  40.     Object.entries(data).forEach(profile => {
  41.  
  42.         let profileDiv = document.createElement(`div`);
  43.         profileDiv.classList.add(`profile`);
  44.  
  45.         let name = profile[1].username;
  46.         let age = profile[1].age;
  47.         let email = profile[1].email;
  48.  
  49.         profileDiv.innerHTML = `<img src="./iconProfile2.png" class="userIcon" />
  50. <label>Lock</label>
  51. <input type="radio" name="user1Locked" value="lock" checked>
  52. <label>Unlock</label>
  53. <input type="radio" name="user1Locked" value="unlock"><br>
  54. <hr>
  55. <label>Username</label>
  56. <input type="text" name="user1Username" value="${name}" disabled readonly />
  57. <div id="user1HiddenFields">
  58. <hr>
  59. <label>Email:</label>
  60. <input type="email" name="user1Email" value="${email}" disabled readonly />
  61. <label>Age:</label>
  62. <input type="email" name="user1Age" value="${age}" disabled readonly />
  63. </div>
  64. <button>Show more</button>`;
  65.  
  66.         main.appendChild(profileDiv);
  67.     });
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement