Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function lockedProfile() {
- const mainRef=document.getElementById("main")
- const profileRef=document.querySelector(".profile")
- const url=`http://localhost:3030/jsonstore/advanced/profiles`
- //get the needed data
- const data=await getData(url)
- //make i so i have user1,user2...
- let i=1
- //go trought all users and make a page for each of them
- Object.entries(data).forEach(el=>{
- profileRef.remove()
- //make a template
- const clone=profileRef.cloneNode(true)
- //get radio buttons
- const unlock=clone.querySelector('input[value="unlock"]')
- const lock=clone.querySelector('input[value="lock"]')
- unlock.setAttribute("name",`user${i}Locked`)
- lock.setAttribute("name",`user${i}Locked`)
- //get dropdownMenu
- const moreInfo=clone.querySelector(".user1Username")
- moreInfo.setAttribute("id",`user${i}HiddenFields`)
- moreInfo.removeAttribute("class")
- //get needed inputs
- const username=clone.querySelector('input[name="user1Username"]')
- username.setAttribute("name",`user${i}Username`)
- username.setAttribute("value",`${el[1].username}`)
- const email=clone.querySelector('input[name="user1Email"]')
- email.setAttribute("name",`user${i}Email`)
- email.setAttribute("value",`${el[1].email}`)
- const age=clone.querySelector('input[name="user1Age"]')
- age.setAttribute("value",`${el[1].age}`)
- age.setAttribute("name",`user${i}Age`)
- //get button
- const showBtn=clone.querySelector("button")
- showBtn.disabled=true
- showBtn.addEventListener("click",onClick)
- //make radioFunction
- lock.addEventListener('change', checkRadioButtons);
- unlock.addEventListener('change', checkRadioButtons);
- //set info from data
- username.value=el[1].username
- email.value=el[1].email
- age.value=el[1].age
- moreInfo.style.display="none"
- //append it all
- mainRef.appendChild(clone)
- //radio function
- function checkRadioButtons(){
- if(lock.checked){
- showBtn.disabled=true
- }
- else if(unlock.checked){
- showBtn.disabled=false
- }
- }
- i++
- })
- //show button function
- function onClick(e){
- const profile=e.currentTarget
- const info=profile.previousElementSibling
- if(e.currentTarget.textContent==="Show more"){
- info.style.display="block"
- e.currentTarget.textContent="Hide it"
- }
- else{
- info.style.display="none"
- e.currentTarget.textContent="Show more"
- }
- }
- //get Data
- async function getData(url){
- const response=await fetch(url)
- return response.json()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement