VladislavNechepaev

Untitled

Jan 15th, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function replaceInputWithDropdown(targetId, dataset, facsId = null){
  2.   const nativeContainer = document.getElementById(targetId).parentNode
  3.   document.getElementById(targetId).style.display = "none"
  4.   const selector = document.createElement("select")
  5.   selector.id = facsId
  6.   for (let optionName in dataset) {
  7.     const option = document.createElement("option")
  8.     option.innerHTML = optionName
  9.     option.value = optionName
  10.     selector.appendChild(option)
  11.   }
  12.   nativeContainer.appendChild(selector)
  13.   return selector
  14. }
  15.  
  16. function createSimplifiedDropdown(targetId, dataset, facsId = null){
  17.   const nativeContainer = document.getElementById(targetId).parentNode
  18.   document.getElementById(targetId).style.display = "none"
  19.   const selector = document.createElement("select")
  20.   selector.id = facsId
  21.   dataset.forEach(optionName => {
  22.     const option = document.createElement("option")
  23.     option.innerHTML = optionName
  24.     option.value = optionName
  25.     selector.appendChild(option)
  26.   })
  27.   nativeContainer.appendChild(selector)
  28.   return selector
  29. }
  30.  
  31. function createCustomCheckbox(container, id, labelText){
  32.   container.childNodes.forEach(elem => {
  33.     elem.style.display = "none"
  34.   })
  35.   const checkboxWrapper = document.createElement("div")
  36.   const checkbox = document.createElement("input")
  37.   checkbox.type = "checkbox"
  38.   checkbox.id = id
  39.   const checkboxLabel = document.createElement("label")
  40.   checkboxLabel.htmlFor = id
  41.   checkboxLabel.style.display = "inline"
  42.   checkboxLabel.style.marginLeft = "5px"
  43.   checkboxLabel.appendChild(labelText)
  44.   checkboxWrapper.appendChild(checkbox)
  45.   checkboxWrapper.appendChild(checkboxLabel)
  46.   container.appendChild(checkboxWrapper)
  47.   return checkbox
  48. }
  49.  
  50. function createCustomDates(nativeList){
  51.   var customDateCollection = []
  52.   nativeList.forEach((dateNativeField, index) => {
  53.     dateNativeField.parentNode.style.display = "none"
  54.     const dateField = document.createElement("input")
  55.     const elemId = "date_custom_" + (index + 1)
  56.     dateField.id = elemId
  57.     const controlWrapper = document.createElement("span")
  58.     controlWrapper.id = "controls_" + index
  59.     controlWrapper.style.marginLeft = "5px"
  60.     controlWrapper.style.minWidth = "50px"
  61.     controlWrapper.style.display = "inline-block"
  62.  
  63.     const addLocationWrapper = document.createElement("div")
  64.     addLocationWrapper.id = "addtable_wrapper_" + (index+1)
  65.     const addLocationHeader = document.createElement("div")
  66.     addLocationHeader.className += "addloc-header"
  67.     addLocationHeader.style.textColor = "lightgrey"
  68.     addLocationHeader.style.fontSize = "16px"
  69.     const addLocationArrow = document.createElement("span")
  70.     addLocationHeader.appendChild(addLocationArrow)
  71.     addLocationArrow.innerHTML = "►"
  72.     addLocationHeader.innerHTML += "Click here to select additional locations"
  73.     const addLocationTableContainer = document.createElement("div")
  74.     addLocationTableContainer.id = "addtable_" + (index+1)
  75.     addLocationTableContainer.className += "addtable-container"
  76.     jQuery(addLocationTableContainer).hide()
  77.     addLocationHeader.onclick = function(){
  78.       console.log(addLocationArrow.innerHTML, addLocationArrow.innerHTML === "►")
  79.       addLocationArrow.innerHTML = (addLocationArrow.innerHTML === "►") ? "▼" : "►"
  80.       jQuery(addLocationTableContainer).toggle(200)
  81.     }
  82.     addLocationWrapper.appendChild(addLocationHeader)
  83.     addLocationWrapper.appendChild(addLocationTableContainer)
  84.  
  85.     dateNativeField.parentNode.parentNode.append(dateField)
  86.     dateNativeField.parentNode.parentNode.append(controlWrapper)
  87.     dateNativeField.parentNode.parentNode.append(addLocationWrapper)
  88.     if (index > 0) dateNativeField.parentNode.parentNode.style.display = "none"
  89.     customDateCollection.push(dateField)
  90.     jQuery("#"+elemId).datepicker({
  91.       dateFormat: "yy-mm-dd",
  92.       firstDay: 1
  93.     })
  94.   })
  95.   return customDateCollection
  96. }
  97.  
  98.   function createInputWithRestrictions(elem, pattern){
  99. const parent = elem.parentNode
  100. const input = document.createElement("input")
  101. if (pattern) input.pattern = pattern
  102. elem.style.display = "none"
  103. parent.appendChild(input)
  104. return input
  105. }
  106.  
  107. function createDocumentSection(target, todayGlobal){
  108.   target.parentNode.childNodes.forEach(node => {
  109.     node.style.display = "none"
  110.   })
  111.   const documentTextWrapper = document.createElement("div")
  112.   const documentTextHeader = document.createElement("div")
  113.   documentTextHeader.style.fontSize = "16px"
  114.   const headerArrow = document.createElement("span")
  115.   headerArrow.innerHTML = "▼"
  116.   const headerTitle = document.createElement("span")
  117.   headerTitle.innerHTML = "Текст документа (click to view)"
  118.   documentTextHeader.appendChild(headerArrow)
  119.   documentTextHeader.appendChild(headerTitle)
  120.   const documentTextContent = document.createElement("div")
  121.   documentTextHeader.onclick = function(){
  122.     documentTextContent.hidden = !documentTextContent.hidden
  123.     headerArrow.innerHTML = (headerArrow.innerHTML === "►" ? "▼" : "►")
  124.   }
  125.   documentTextContent.style.width = "600px"
  126.   documentTextContent.style.margin = "15px"
  127.   documentTextContent.insertAdjacentHTML('beforeend', '<div style="text-align: center">         <b>Заява на допуск до користування Простором Товариства з обмеженою відповідальністю «ТекХостинг» (далі – ТОВ «ТекХостинг»)</b>       </div>       <br>       <div style="text-align: justify">         <p>           Я, <b>фізична особа-підприємець</b> {{ current_user.phone }}, прошу допустити мене до користування офісним простором ТОВ «ТекХостинг» (далі – Простір), що знаходиться за адресою: <span id="doc-address"></span>.         </p>         <br>         <p>           <b>Я підтверджую</b>, що на момент надання мені доступу до користування Простором:           <ul>             <li>у мене відсутні будь-які ознаки ГРВІ, а саме: підвищена температура тіла (більше 37,2 С), кашель, утруднене дихання тощо;</li>             <li>я ознайомлений(а) з рекомендаціями МОЗ та ВООЗ щодо попередження зараження COVID-19 та їх дотримуюсь;</li>             <li>протягом останніх 14 днів я не перебував(ла) за межами України та не контактував(ла) з особами, щодо яких наявна підозра/хворими на COVID-19.</li>           </ul>         </p>         <br>         <p>           <b>Я зобов’язуюсь</b> під час користування Простором дотримуватися посилених санітарно-гігієнічних норм, а також рекомендацій МОЗ та ВООЗ щодо запобігання поширенню COVID-19, а саме:           <ul>             <li>носити медичну маску/респіратор;</li>             <li>ретельно мити руки з милом протягом 20-40 сек. та регулярно обробляти їх антисептичним засобом під час перебування в Просторі;</li>             <li>дотримуватися дистанції min 1,5 (півтора) метри від інших відвідувачів Простору.</li>           </ul>         </p>       </div><br>       <div>         <b>Дата</b>: ' + todayGlobal + '       </div>')
  128.   documentTextContent.hidden = true
  129.   documentTextWrapper.appendChild(documentTextHeader)
  130.   documentTextWrapper.appendChild(documentTextContent)
  131.   target.parentNode.appendChild(documentTextWrapper)
  132.   return documentTextContent
  133. }
  134.  
  135. function createAdditionalOfficeSelectors(ids, datalist){
  136.   var list = []
  137.   ids.forEach((id, index) => {
  138.     const newID = "additional_office_" + (index+1)
  139.     const selector = replaceInputWithDropdown(id, datalist, newID)
  140.     selector.parentNode.style.display = "none"
  141.     if (index > 0) selector.parentNode.childNodes.item("LABEL").style.display = "none"
  142.     list.push(selector)
  143.   })
  144.   return list
  145. }
  146.  
  147. function calcDateLimits(thisWeek){
  148.   const nowDate = new Date()
  149.   var limits = []
  150.   if (thisWeek) {
  151.     const dateMin = nowDate.toISOString().split("T")[0]
  152.     const nowWeekDay = nowDate.getDay()
  153.     const daysToAdd = !nowWeekDay ? 0 : 7 - nowWeekDay
  154.     nowDate.setDate(nowDate.getDate() + daysToAdd)
  155.     const dateMax = nowDate.toISOString().split("T")[0]
  156.     limits.push(dateMin)
  157.     limits.push(dateMax)
  158.   } else {
  159.     const nowWeekDay = nowDate.getDay()
  160.     const daysToAdd = !nowWeekDay ? 1 : 7 - nowWeekDay + 1
  161.     nowDate.setDate(nowDate.getDate() + daysToAdd)
  162.     const dateMin = nowDate.toISOString().split("T")[0]
  163.     nowDate.setDate(nowDate.getDate() + 6)
  164.     const dateMax = nowDate.toISOString().split("T")[0]
  165.     limits.push(dateMin)
  166.     limits.push(dateMax)
  167.   }
  168.   return limits
  169. }
  170.  
  171. function reverseForFS(date){
  172.   if (!date) return null
  173.   const vals = date.split("-")
  174.   //return `${vals[2]}-${vals[1]}-${vals[0]}`
  175.   return vals[2]+"-"+vals[1]+"-"+vals[0]
  176. }
  177.  
  178. function getElemList(idList){
  179.   var collection = []
  180.   idList.forEach(id => {
  181.     collection.push(document.getElementById(id))
  182.   })
  183.   return collection
  184. }
  185.  
  186. function createCapacityDisplay(nextElement){
  187.   const wrapper = document.createElement("div")
  188.   wrapper.style.border = "3px solid #70c9e9"
  189.   wrapper.style.minHeight = "100px"
  190.   wrapper.style.width = "250px"
  191.   wrapper.style.margin = "5px 0px 5px 0px"
  192.   wrapper.style.padding = "5px"
  193.   const mainWrapper = nextElement.parentNode
  194.   mainWrapper.insertBefore(wrapper, nextElement)
  195.   wrapper.hidden = true
  196.   return wrapper
  197. }
Advertisement
Add Comment
Please, Sign In to add comment