Advertisement
VladislavNechepaev

Untitled

Mar 23rd, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const officeParking = ["Toronto","Lab62","Lab64","Lab72","Lab72/1","Zeus Lab"]
  2.  
  3. // ===============================
  4.  
  5. var hasParkingId = false
  6.  
  7. // ===============================
  8.  
  9. const dateList = createCustomDates(fsNative.dates, parkingActive, true)
  10.  
  11. // ===============================
  12.  
  13. const userEmail = "{{current_user.email}}"
  14.       console.log(userEmail)
  15.       fetch(`https://freshservicecounter.ringteam.com/getparkingidentry?email=${userEmail}`).then(res => {
  16.         console.log(res.status)
  17.         if (res.status === 200) hasParkingId = true
  18.       })
  19.  
  20. // ===============================
  21.  
  22. const parkingElems = document.getElementsByClassName("parkingwrapper")
  23.         if (officeParking.includes(values.office) && hasParkingId) {
  24.           for(let elem of parkingElems) {
  25.             elem.style.display = "inline-flex"
  26.           }
  27.         } else {
  28.           for(let elem of parkingElems) {
  29.             elem.style.display = "none"
  30.             elem.querySelector("input").checked = false
  31.           }
  32.         }
  33.  
  34. // ===============================
  35.  
  36. function createCustomDates(nativeList, parkingActive, createAddLocation = false){
  37.     var customDateCollection = []
  38.     nativeList.forEach((dateNativeField, index) => {
  39.       dateNativeField.parentNode.style.display = "none"
  40.       const dateField = document.createElement("input")
  41.       const elemId = "date_custom_" + (index + 1)
  42.       dateField.id = elemId
  43.       const controlWrapper = document.createElement("span")
  44.       controlWrapper.id = "controls_" + index
  45.       controlWrapper.style.marginLeft = "5px"
  46.       controlWrapper.style.minWidth = "50px"
  47.       controlWrapper.style.display = "inline-block"
  48.       dateNativeField.parentNode.parentNode.append(dateField)
  49.       dateNativeField.parentNode.parentNode.append(controlWrapper)
  50.        
  51.       if (createAddLocation) {
  52.         const addLocationWrapper = document.createElement("div")
  53.         addLocationWrapper.id = "addtable_wrapper_" + (index+1)
  54.         const addLocationHeader = document.createElement("div")
  55.         addLocationHeader.style.textColor = "lightgrey"
  56.         addLocationHeader.style.fontSize = "16px"
  57.         const addLocationArrow = document.createElement("span")
  58.         addLocationHeader.appendChild(addLocationArrow)
  59.         addLocationArrow.innerHTML = "►"
  60.         addLocationHeader.innerHTML += "Select additional locations"
  61.         const addLocationTableContainer = document.createElement("div")
  62.         addLocationTableContainer.id = "addtable_" + (index+1)
  63.         addLocationTableContainer.className += "addtable-container"
  64.         jQuery(addLocationTableContainer).hide()
  65.         addLocationHeader.onclick = function(){
  66.           console.log(addLocationArrow.innerHTML, addLocationArrow.innerHTML === "►")
  67.           addLocationArrow.innerHTML = (addLocationArrow.innerHTML === "►") ? "▼" : "►"
  68.           jQuery(addLocationTableContainer).toggle(200)
  69.         }
  70.         addLocationWrapper.appendChild(addLocationHeader)
  71.         addLocationWrapper.appendChild(addLocationTableContainer)
  72.         if (parkingActive) {
  73.           const parkingWrapper = document.createElement("div")
  74.           parkingWrapper.className += "parkingwrapper"
  75.           parkingWrapper.id = "parkingwrapper_" + (index+1)
  76.           parkingWrapper.style.display = "inline-flex"
  77.           const parkingCheckbox = document.createElement("input")
  78.           parkingCheckbox.type = "checkbox"
  79.           parkingCheckbox.id = "parking_" + (index+1)
  80.           const parkingLabel = document.createElement("label")
  81.           parkingLabel.htmlFor = "parking_" + (index+1)
  82.           parkingLabel.innerHTML = "Request parking"
  83.           parkingLabel.style.marginLeft = "5px"
  84.           const parkingCapacity = document.createElement("span")
  85.           parkingCapacity.id = "parkingcapacity_" + (index+1)
  86.           parkingCapacity.style.marginLeft = "5px"
  87.           parkingWrapper.appendChild(parkingCheckbox)
  88.           parkingWrapper.appendChild(parkingLabel)
  89.           parkingWrapper.appendChild(parkingCapacity)
  90.           addLocationWrapper.appendChild(parkingWrapper)
  91.           //parkingWrapper.hidden = true
  92.         }
  93.         dateNativeField.parentNode.parentNode.append(addLocationWrapper)
  94.       }      
  95.      
  96.       if (index > 0) dateNativeField.parentNode.parentNode.style.display = "none"
  97.       customDateCollection.push(dateField)
  98.       jQuery("#"+elemId).datepicker({
  99.         dateFormat: "yy-mm-dd",
  100.         firstDay: 1
  101.       })
  102.     })
  103.     return customDateCollection
  104.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement