VladislavNechepaev

Untitled

Dec 30th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://freshservicecounter.ringteam.com/ringteam_portal_customization.js"></script>
  2. <script>
  3.   jQuery(document).on('ready', async function(){
  4.     console.log('[INIT]')
  5.     if (window.location.pathname === "/support/catalog/items/136" || window.location.pathname === "/support/catalog/items/149") {
  6.       const durationList = {
  7.         "...": false,
  8.         "Full day": true,
  9.         "Half day": true,
  10.         "Short visit (up to 2 hours)": false
  11.       }
  12.       const officeList = {
  13.         "...": false,
  14.         "Toronto": true,
  15.         "Lviv": true,
  16.         "Lab64": true,
  17.         "Lab72": true,
  18.         "Lab72 / 1": false,
  19.         "Rancho 1": false,
  20.         "Rancho 2": false,
  21.         "QA Studio": false,
  22.         "New QA Studio": false,
  23.         "Community": false,
  24.         "Lab62": true
  25.       }
  26.       const officeMeido = {
  27.         "...": false,
  28.         "Toronto": true,
  29.         "Lviv": false,
  30.         "Lab64": true,
  31.         "Lab72": true,
  32.         "Lab72 / 1": false,
  33.         "Rancho 1": false,
  34.         "Rancho 2": false,
  35.         "QA Studio": false,
  36.         "New QA Studio": false,
  37.         "Community": false,
  38.         "Lab62": true
  39.       }
  40.       const officeCapacity = ["Toronto","Lab64","Lab62"]
  41.       const officeAddress = {
  42.         "...": "",
  43.         "Toronto": "м. Київ, вул. Велика Васильківська 100, 8 поверх",
  44.         "Lviv": "м. Львів, вул. Поповича, 9",
  45.         "Lab64": "м. Київ, вул. Велика Васильківська 64",
  46.         "Lab72": "м. Київ, вул. Велика Васильківська 72",
  47.         "Lab72 / 1": "м. Київ, вул. Велика Васильківська 72",
  48.         "Rancho 1": "м. Київ, пров. Малокитаївський, 12",
  49.         "Rancho 2": "м. Київ, вул. Травнева 28",
  50.         "QA Studio": "м. Київ, вул. Північно-Сирецька 1-3",
  51.         "New QA Studio": "м. Київ, просп. Перемоги 53",
  52.         "Community": "м. Київ, вул. Євгена Коновальця 44, 2 поверх",
  53.         "Lab62": "м. Київ, вул. Велика Васильківська 62"
  54.       }
  55.       const accessWeek = {
  56.         "...": false,
  57.         "Current week": true,
  58.         "Next week": true
  59.       }
  60.       const mealTypes = [
  61.         "Non-vegan",
  62.         "Vegan"
  63.       ]
  64.         var fsFields
  65.           if (window.location.pathname === "/support/catalog/items/136") {
  66.           fsFields = {
  67.         duration: "requested_item_values_136_requested_item_value_attributes_cf_visit_duration_270753",
  68.         support_with_lunch: "requested_item_values_136_requested_item_value_attributes_cf_support_with_lunch_270753",
  69.         access_week: "requested_item_values_136_requested_item_value_attributes_cf_access_type_270753",
  70.         lunch_type: "requested_item_values_136_requested_item_value_attributes_cf_select_your_meal_preference_270753",
  71.         office: "requested_item_values_136_requested_item_value_attributes_cf_office_270753",
  72.         dates: [
  73.           "requested_item_values_136_requested_item_value_attributes_cf_day1_270753_date",
  74.           "requested_item_values_136_requested_item_value_attributes_cf_day2_270753_date",
  75.           "requested_item_values_136_requested_item_value_attributes_cf_day3_270753_date",
  76.           "requested_item_values_136_requested_item_value_attributes_cf_day4_270753_date",
  77.           "requested_item_values_136_requested_item_value_attributes_cf_day5_270753_date",
  78.           "requested_item_values_136_requested_item_value_attributes_cf_day6_270753_date",
  79.           "requested_item_values_136_requested_item_value_attributes_cf_day7_270753_date"            //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ РЕАЛЬНІЙ РЕКВЕСТ//
  80.         ],
  81.         additional_locations: [
  82.           "requested_item_values_136_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
  83.           "requested_item_values_136_requested_item_value_attributes_cf_additional_location_2_270753"
  84.         ],
  85.         meido: "requested_item_values_136_requested_item_value_attributes_cf_meido_body_270753",
  86.         document_text: "requested_item_values_136_requested_item_value_attributes_cf__270753",
  87.         document_check: "requested_item_values_136_requested_item_value_attributes_cf_v_270753",
  88.         addloc: "requested_item_values_136_requested_item_value_attributes_cf_additional_location_data_270753",
  89.         addloc_text: "requested_item_values_136_requested_item_value_attributes_cf_additional_location_270753"
  90.       }
  91.           } else if (window.location.pathname === "/support/catalog/items/149") {
  92.           fsFields = {
  93.         duration: "requested_item_values_149_requested_item_value_attributes_cf_visit_duration_270753",
  94.         support_with_lunch: "requested_item_values_149_requested_item_value_attributes_cf_support_with_lunch_270753",
  95.         access_week: "requested_item_values_149_requested_item_value_attributes_cf_access_type_270753",
  96.         lunch_type: "requested_item_values_149_requested_item_value_attributes_cf_select_your_meal_preference_270753",
  97.         office: "requested_item_values_149_requested_item_value_attributes_cf_office_270753",
  98.         dates: [
  99.           "requested_item_values_149_requested_item_value_attributes_cf_day1_270753_date",
  100.           "requested_item_values_149_requested_item_value_attributes_cf_day2_270753_date",
  101.           "requested_item_values_149_requested_item_value_attributes_cf_day3_270753_date",
  102.           "requested_item_values_149_requested_item_value_attributes_cf_day4_270753_date",
  103.           "requested_item_values_149_requested_item_value_attributes_cf_day5_270753_date"              //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ТЕСТОВІЙ РЕКВЕСТ//
  104.         ],
  105.         additional_locations: [
  106.           "requested_item_values_149_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
  107.           "requested_item_values_149_requested_item_value_attributes_cf_additional_location_2_270753"
  108.         ],
  109.         meido: "requested_item_values_149_requested_item_value_attributes_cf_meido_body_270753",
  110.         document_text: "requested_item_values_149_requested_item_value_attributes_cf__270753",
  111.         document_check: "requested_item_values_149_requested_item_value_attributes_cf_v_270753",
  112.         addloc: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_data_270753",
  113.         addloc_text: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_270753"
  114.       }
  115.           }
  116.  
  117.       // -------------------------
  118.         var meidoActive
  119.         if (window.location.pathname === "/support/catalog/items/136") {
  120.           meidoActive = false
  121.         } else if (window.location.pathname === "/support/catalog/items/149") {
  122.           meidoActive = true
  123.         }
  124.         meidoToken = "test"
  125.       // -------------------------
  126.  
  127.       // -------------------------
  128.         var capacityActive
  129.         if (window.location.pathname === "/support/catalog/items/136") {
  130.           capacityActive = true                                                              //замсемнить ФОЛс на ТРУ чтоб включить капасити в боевом. реквесте//
  131.         } else if (window.location.pathname === "/support/catalog/items/149") {
  132.           capacityActive = true
  133.         }
  134.       // -------------------------
  135.  
  136.           // ====================================================================
  137.           // ====================================================================
  138.           // ====================================================================
  139.  
  140.       const fsNative = {
  141.         duration: document.getElementById(fsFields.duration),
  142.         support_with_lunch: document.getElementById(fsFields.support_with_lunch).parentNode.childNodes.item(0),
  143.         access_week: document.getElementById(fsFields.access_week),
  144.         lunch_type: document.getElementById(fsFields.lunch_type),
  145.         office: document.getElementById(fsFields.office),
  146.         meido: document.getElementById(fsFields.meido),
  147.         dates: getElemList(fsFields.dates),
  148.         additional_locations: getElemList(fsFields.additional_locations),
  149.         document_text: document.getElementById(fsFields.document_text),
  150.         document_check: document.getElementById(fsFields.document_check).parentNode.childNodes.item(0),
  151.         addloc: document.getElementById(fsFields.addloc),
  152.         addloc_text: document.getElementById(fsFields.addloc_text)
  153.       }
  154.  
  155.       var activeDateCount = 0
  156.       const today = new Date()
  157.       const todayGlobal = today.toLocaleDateString()
  158.       const weekdayGlobal = today.getDay()
  159.       const currentHoursGlobal = today.getHours()
  160.         const currentMinutesGlobal = today.getMinutes()
  161.       var selectedDatesGlobal = []
  162.       var capacityCheck = true
  163.       var additionalLocationInfo = {}
  164.       var addLocationTable
  165.       var lastSelectedOffice
  166.  
  167.       const durationSelector = replaceInputWithDropdown(fsFields.duration, durationList, "duration")
  168.             durationSelector.parentNode.hidden = true
  169.       const officeSelector = replaceInputWithDropdown(fsFields.office, officeList, "office")
  170.       const accessWeekSelector = replaceInputWithDropdown(fsFields.access_week, accessWeek, "access-week")
  171.       const lunchTypeSelector = createSimplifiedDropdown(fsFields.lunch_type, mealTypes, "lunch_type")
  172.       const lunchCheckboxLabel = document.createTextNode("Please support me with lunch")                          // to add text Lunch will be provided in case your visit durayion is more than 2 hours//
  173.       const lunchCheckbox = createCustomCheckbox(document.getElementById(fsFields.support_with_lunch).parentNode, "show-lunch", lunchCheckboxLabel)
  174.       const dateList = createCustomDates(fsNative.dates)
  175.       const additionalOfficesList = createAdditionalOfficeSelectors(fsFields.additional_locations, officeList)
  176.       const capacityDisplay = createCapacityDisplay(fsNative.dates[0].parentNode.parentNode)
  177.       //--- capacity ---
  178.       if (capacityActive) {
  179.         fsNative.addloc.parentNode.hidden = true
  180.         fsNative.addloc_text.parentNode.hidden = true
  181.         fsNative.additional_locations.forEach(elem => { elem.parentNode.hidden = true })
  182.       }
  183.  
  184.  
  185.           //add hotDeskCheckbox
  186.       const hotdeskCheckboxLabel = document.createTextNode("I don`t have a permanent seat and would like to book a hot desk.");
  187.       const hotdeskCheckboxContainer = document.createElement('div');
  188.       document.getElementById(fsFields.office).parentNode.appendChild(hotdeskCheckboxContainer);
  189.       const hotdeskCheckbox = createCustomCheckbox(hotdeskCheckboxContainer, "show-hotdesk", hotdeskCheckboxLabel);
  190.       hotdeskCheckbox.checked = false;
  191.       const hotdeskText = document.createElement("p");
  192.       hotdeskText.innerHTML = "Please, follow the <a href='https://ringukraine.officespacesoftware.com/visual-directory/floors/139' style='color:blue;cursor:pointer;' target='_blank'>link</a> for hot desks booking system (applicable only for Full/half-day visit). Here`re <a href='https://docs.google.com/document/d/1llpCz3RbK0cBew7kSJhZPQwD5Om8Kgj0tTq-1kgONx4/edit' style='color:blue;cursor:pointer;' target='_blank'>instructions</a> on how to make a booking.";
  193.       hotdeskCheckboxContainer.appendChild(hotdeskText);
  194.  
  195.       const documentCheckboxLabel = document.createElement("span")
  196.       documentCheckboxLabel.innerHTML = "Я, {{ current_user.phone }}, ознайомився з документом та підтверджую що мій стан відповідає нормам відвідування офісу згідно з заявою.<br>*[✓] <i>означає, що дана відмітка прирівнюється до власноручного/факсимільного відтворення підпису особи.</i>"
  197.       const documentCheckbox = createCustomCheckbox(fsNative.document_check.parentNode, "document-check", documentCheckboxLabel)
  198.       const documentText = createDocumentSection(fsNative.document_text, todayGlobal)
  199.  
  200.       const dateControlAdd = document.createElement("button")
  201.       dateControlAdd.innerHTML = "+"
  202.       const dateControlRemove = document.createElement("button")
  203.       dateControlRemove.innerHTML = "-"
  204.  
  205.       lunchCheckbox.parentNode.hidden = true;
  206.       lunchTypeSelector.parentNode.hidden = true;
  207.       hotdeskCheckboxContainer.hidden = true;
  208.       hotdeskText.hidden = true;
  209.  
  210.       //durationSelector.addEventListener("change", function(){ renderController() })
  211.       officeSelector.addEventListener("change", function(){ renderController() })
  212.       accessWeekSelector.addEventListener("change", function(){ renderController() })
  213.       lunchCheckbox.addEventListener("change", function(){ renderController() })
  214.       hotdeskCheckbox.addEventListener("change", function(){ renderController() })
  215.       lunchTypeSelector.addEventListener("change", function(){ renderController() })
  216.  
  217.       dateList.forEach(dateElem => {
  218.         jQuery(dateElem).datepicker("option", {
  219.           onSelect: function() {
  220.             renderController()
  221.           }
  222.         })
  223.       })
  224.  
  225.       dateControlAdd.addEventListener("click", function(e){
  226.         e.preventDefault()
  227.         activeDateCount += 1
  228.         renderController()
  229.       })
  230.       dateControlRemove.addEventListener("click", function(e){
  231.         e.preventDefault()
  232.         activeDateCount -= 1
  233.         renderController()
  234.       })
  235.       additionalOfficesList.forEach(elem => {
  236.         elem.addEventListener("change", function(){ renderController() })
  237.       })
  238.  
  239.  
  240.       documentCheckbox.addEventListener("change", function(){ renderController() })
  241.  
  242.       var meidoMenu
  243.       document.getElementById(fsFields.meido).parentNode.style.display = "none"
  244.       if (meidoActive) {
  245.         const elems = document.getElementsByClassName("main pull-left")
  246.         meidoMenu = await meidoInit(elems[0], dateList, fsFields.meido, 125, false)  // change 125 to required limit
  247.         meidoMenu.hidden = true
  248.         renderController()
  249.       } else {
  250.         renderController()
  251.       }
  252.  
  253.       jQuery("input[type=\"submit\"]").each((index, elem) => {
  254.         elem.onclick = function(e){
  255.           if (!capacityCheck) {
  256.             e.stopImmediatePropagation()
  257.             e.preventDefault()
  258.               alert("Please check the capactiy for selected dates")                     //поменять нотифай если нужно!//
  259.           }
  260.         }
  261.       })
  262.  
  263.       function renderController(){
  264.         var values = {
  265.           duration: "Full day",
  266.           office: officeSelector.value,
  267.           access_week: accessWeekSelector.value
  268.         }
  269.  
  270.         fsNative.duration.value = values.duration === "..." ? "" : values.duration
  271.         fsNative.office.value = values.office === "..." ? "" : values.office
  272.  
  273.         if (capacityActive) {
  274.           if (values.office === "...") {
  275.             lastSelectedOffice = values.office
  276.             for (let elem of document.getElementsByClassName("addtable-container")) {
  277.               elem.innerHTML = ""
  278.             }
  279.             additionalLocationInfo = {}
  280.             populateAddLocation()
  281.           }
  282.           if (values.office !== "..." && values.office !== lastSelectedOffice) {
  283.             lastSelectedOffice = values.office
  284.             addLocationTable = buildAddLocationTable(values.office)
  285.             const addTableContainers = document.getElementsByClassName("addtable-container")
  286.             var index = 1
  287.             for (let elem of addTableContainers) {
  288.               elem.innerHTML = ""
  289.               const table = addLocationTable.cloneNode(true)
  290.               console.log(table.querySelectorAll('.add-office-label'))
  291.               for (let elem of table.querySelectorAll('.add-office-label')) {
  292.                 elem.htmlFor = elem.htmlFor + "_" + index
  293.               }
  294.               for (let elem of table.querySelectorAll('.add-office-checkbox')) {
  295.                 elem.id = elem.id + "_" + index
  296.                 elem.onclick = function(){ handleAddLocation(this) }
  297.               }
  298.               ++index
  299.               elem.appendChild(table)
  300.             }
  301.             additionalLocationInfo = {}
  302.             populateAddLocation()
  303.           }
  304.         }
  305.  
  306.         if (fsNative.office.value === 'Toronto') {
  307.           hotdeskCheckboxContainer.hidden = false;
  308.         } else {
  309.           hotdeskCheckbox.checked = false;
  310.           hotdeskCheckboxContainer.hidden = true;
  311.         }
  312.         if (!hotdeskCheckbox.checked) {
  313.           hotdeskText.hidden = true;
  314.         } else {
  315.           hotdeskText.hidden = false;
  316.         }
  317.  
  318.         const accessWeekChanged = fsNative.access_week.value === values.access_week ? false : true
  319.         fsNative.access_week.value = values.access_week === "..." ? "" : values.access_week
  320.         var datesInRequest = dateList.map(x => x.value).filter(x => !!x)
  321.         if (activeDateCount === 0) datesInRequest = datesInRequest[0] ? [datesInRequest[0]] : []
  322.         const today = new Date().toISOString().split("T")[0]
  323.         if (durationList[values.duration] && officeList[values.office] && accessWeek[values.access_week] && datesInRequest.length && !(datesInRequest.length === 1 && datesInRequest[0] === today) && !accessWeekChanged) {
  324.           lunchCheckbox.parentNode.hidden = false
  325.         } else {
  326.           lunchCheckbox.parentNode.hidden = true
  327.           lunchCheckbox.checked = false
  328.         }
  329.  
  330.         values.support_with_lunch = lunchCheckbox.checked
  331.         fsNative.support_with_lunch.value = lunchCheckbox.checked ? "1" : "0"
  332.         if (values.support_with_lunch) {
  333.           if (meidoActive) {
  334.             if (weekdayGlobal === 6 || weekdayGlobal === 0 || (weekdayGlobal === 5 && currentHoursGlobal >= 19 && currentMinutesGlobal >= 30) || values.access_week === "Current week" || !officeMeido[values.office]) {
  335.               lunchTypeSelector.parentNode.hidden = false
  336.               lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
  337.               meidoMenu.hidden = true
  338.             } else {
  339.               lunchTypeSelector.parentNode.hidden = true
  340.               lunchTypeSelector.value = null
  341.               meidoMenu.hidden = false
  342.             }
  343.           } else {
  344.             lunchTypeSelector.parentNode.hidden = false
  345.             lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
  346.           }
  347.         } else {
  348.           lunchTypeSelector.parentNode.hidden = true
  349.           lunchTypeSelector.value = null
  350.           if (meidoActive) meidoMenu.hidden = true
  351.         }
  352.  
  353.         values.lunch_type = lunchTypeSelector.value
  354.         fsNative.lunch_type.value = values.lunch_type ? values.lunch_type : ""
  355.  
  356.         const dateLimits = (values.access_week === "...") ? null : calcDateLimits(values.access_week === "Current week" ? true : false)
  357.         const dateLimitsRaw = dateLimits ? dateLimits.map(x => new Date(x).valueOf()) : null
  358.         var existingDates = []
  359.         var lastUsedFound = false;
  360.         if (accessWeekChanged) activeDateCount = 0
  361.         dateList.forEach((dateElem, index) => {
  362.           const dateNativeElem = fsNative.dates[index]
  363.           const timeNativeElem = document.getElementById(fsFields.dates[index].substring(0, fsFields.dates[index].length - 4) + "time")
  364.           const errorElem = document.getElementById("date_custom_" + (index+1) + "-error")
  365.           if (errorElem) errorElem.style.display = "none"
  366.           if (accessWeekChanged && index === 0) dateElem.value = null
  367.           const dateRawValue = new Date(dateElem.value).valueOf()
  368.           if (existingDates.includes(dateRawValue)) dateElem.value = null
  369.           if (dateLimits) {
  370.             jQuery("#date_custom_"+(index+1)).datepicker("option", {
  371.               minDate: new Date(dateLimits[0]),
  372.               maxDate: new Date(dateLimits[1])
  373.             })
  374.             dateElem.disabled = false
  375.             if (dateRawValue < dateLimitsRaw[0] || dateRawValue > dateLimitsRaw[1]) dateElem.value = null
  376.           } else {
  377.             dateElem.disabled = true
  378.           }
  379.           existingDates.push(dateRawValue)
  380.           const controlWrapper = document.getElementById("controls_" + index)
  381.           controlWrapper.innerHTML = ""
  382.           const addLocations = document.getElementById("addtable_" + (index+1)).querySelectorAll('.add-office-checkbox')
  383.           if (dateElem.value && dateElem.value !== "") {
  384.             dateNativeElem.value = reverseForFS(dateElem.value)
  385.             timeNativeElem.value = "00:00"
  386.             if (capacityActive) document.getElementById("addtable_wrapper_" + (index+1)).style.display = "block"
  387.           } else {
  388.             dateNativeElem.value = null
  389.             timeNativeElem.value = null
  390.             if (capacityActive) {
  391.               document.getElementById("addtable_wrapper_" + (index+1)).style.display = "none"
  392.               for (let checkbox of addLocations) {
  393.                 checkbox.checked = false
  394.               }
  395.             }
  396.           }
  397.           controlWrapper.style.display = "inline-block"
  398.           if (index < activeDateCount) {
  399.             dateElem.disabled = true
  400.             dateElem.parentNode.style.display = "block"
  401.           } else if (index === activeDateCount) {
  402.             if (dateLimits) dateElem.disabled = false
  403.             if (index > 0 && dateList[index-1].value) {
  404.                     const nextDate = new Date(dateList[index-1].value)
  405.                   nextDate.setDate(nextDate.getDate() + 1)
  406.               jQuery("#date_custom_"+(index+1)).datepicker("option", {
  407.                 minDate: nextDate
  408.               })
  409.                 }
  410.             dateElem.parentNode.style.display = "block"
  411.             if (activeDateCount > 0) controlWrapper.appendChild(dateControlRemove)
  412.             if (activeDateCount < dateList.length-1) {
  413.               controlWrapper.appendChild(dateControlAdd)
  414.               dateControlAdd.disabled = !dateElem.value
  415.             }
  416.           } else {
  417.             dateElem.parentNode.style.display = "none"
  418.             dateElem.value = null
  419.             dateNativeElem.value = null
  420.             timeNativeElem.value = null
  421.           }
  422.         })
  423.  
  424.  
  425.         if (capacityActive === true) {
  426.           const selectedDates = dateList.map(x => x.value).filter(x => !!x)
  427.           for (let date in additionalLocationInfo) {
  428.             if (!selectedDates.includes(date)) delete additionalLocationInfo[date]
  429.           }
  430.           populateAddLocation()
  431.           if (selectedDates.length && JSON.stringify(selectedDates) !== selectedDatesGlobal) {
  432.             fetch(`https://freshservicecounter.ringteam.com/v2/getcapacity?office=${JSON.stringify(officeCapacity)}&dates=${JSON.stringify(selectedDates)}`)
  433.             .then(res => {
  434.               return res.json()
  435.             })
  436.             .then(res => {
  437.             // main capacity
  438.               for (let officeName in res) {
  439.                 if (values.office === officeName) {
  440.                   capacityDisplay.innerHTML = ""
  441.                   const office = document.createElement("div")
  442.                   office.innerHTML = `<b>Office:</b> ${officeName}`
  443.                   const limit = document.createElement("div")
  444.                   limit.innerHTML = `<b>Limit:</b> ${res[officeName].limit} visitors per day`
  445.                   limit.style.borderBottom = "1px dotted grey"
  446.                   capacityDisplay.appendChild(office)
  447.                   capacityDisplay.appendChild(limit)
  448.                   var capacityDataArray = []
  449.                   for (let date in res[officeName].capacity) {
  450.                     capacityDataArray.push({ date: date, capacity: res[officeName].capacity[date] })
  451.                   }
  452.                   capacityDataArray.sort((x,y) => { return x.date > y.date ? 1 : -1 })
  453.                   capacityCheck = true
  454.                   capacityDataArray.forEach(obj => {
  455.                     const dateElem = document.createElement("div")
  456.                     dateElem.innerHTML = `<b>${obj.date}:</b> ${obj.capacity} visitors confirmed`
  457.                     //console.log(obj.capacity, res.limit)
  458.                     if (obj.capacity / res[officeName].limit >= 0.7) dateElem.style.color = "orange"
  459.                     if (obj.capacity >= res[officeName].limit) {
  460.                       dateElem.style.color = "red"
  461.                       capacityCheck = false
  462.                     }
  463.                     capacityDisplay.appendChild(dateElem)
  464.                   })
  465.                       capacityDisplay.hidden = false
  466.                 } else {
  467.                   //additional capacity
  468.                   dateList.forEach(dateElem => {
  469.                     var elem = dateElem.parentNode.getElementsByClassName("capacity_" + officeName)[0]
  470.                     elem.innerHTML = `${res[officeName].capacity[dateElem.value]}/${res[officeName].limit} confirmed`
  471.                   })
  472.                 }
  473.               }
  474.             })
  475.           } else {
  476.             capacityDisplay.hidden = true
  477.             capacityCheck = capacityDisplay.hidden
  478.           }
  479.             selectedDatesGlobal = JSON.stringify(selectedDates)
  480.         }
  481.  
  482.         if (meidoActive && values.access_week === "Next week") {
  483.           meidoCart.calcDateCollection()
  484.         } else {
  485.               fsNative.meido.innerHTML = null
  486.         }
  487.  
  488.         values.additional_offices = []
  489.         additionalOfficesList.forEach((elem, index) => {
  490.           values.additional_offices.push(elem.value)
  491.           if ((index === 0 && values.office !== "...") || (index > 0 && values.additional_offices[index-1] !== "...")) {
  492.             elem.parentNode.style.display = "block"
  493.           } else {
  494.             elem.parentNode.style.display = "none"
  495.             elem.value = "..."
  496.           }
  497.           fsNative.additional_locations[index].value = elem.value === "..." ? null : elem.value
  498.         })
  499.  
  500.         values.document_check = documentCheckbox.checked
  501.         fsNative.document_check.value = documentCheckbox.checked ? "1" : "0"
  502.         fsNative.document_check.checked = documentCheckbox.checked
  503.         const documentLocations = [values.office, values.additional_offices].flat().map(x => officeAddress[x]).filter(x => !!x).join(", ")
  504.         document.getElementById("doc-address").innerHTML = documentLocations
  505.         // =================================================
  506.         var text = `Заява на допуск до користування Простором Товариства з обмеженою відповідальністю «ТекХостинг» (далі – ТОВ «ТекХостинг»)
  507.  
  508. Я, фізична особа-підприємець ${"{{ current_user.phone }}"}, прошу допустити мене до користування офісним простором ТОВ «ТекХостинг» (далі – Простір), що знаходиться за адресою: ${documentLocations}.
  509.  
  510.  
  511. Я підтверджую, що на момент надання мені доступу до користування Простором:
  512.  
  513. • у мене відсутні будь-які ознаки ГРВІ, а саме: підвищена температура тіла (більше 37,2 С), кашель, утруднене дихання тощо;
  514. • я ознайомлений(а) з рекомендаціями МОЗ та ВООЗ щодо попередження зараження COVID-19 та їх дотримуюсь;
  515. • протягом останніх 14 днів я не перебував(ла) за межами України та не контактував(ла) з особами, щодо яких наявна підозра/хворими на COVID-19.
  516.  
  517. Я зобов’язуюсь під час користування Простором дотримуватися посилених санітарно-гігієнічних норм, а також рекомендацій МОЗ та ВООЗ щодо запобігання поширенню COVID-19, а саме:
  518.  
  519. • носити медичну маску/респіратор;
  520. • ретельно мити руки з милом протягом 20-40 сек. та регулярно обробляти їх антисептичним засобом під час перебування в Просторі;
  521. • дотримуватися дистанції min 1,5 (півтора) метри від інших відвідувачів Простору.
  522.  
  523. Дата: ${todayGlobal}`
  524.         // =================================================
  525.         fsNative.document_text.value = text
  526.       }
  527.  
  528.       function buildAddLocationTable(excluded){
  529.         const table = document.createElement('table')
  530.         table.style.margin = "10px"
  531.         const row = document.createElement('tr')
  532.         row.style.width = "800px"
  533.         row.style.display = "block"
  534.         table.appendChild(row)
  535.         var cellCount = 0
  536.         for (let office in officeList) {
  537.           if (office !== "..." && office !== excluded) {
  538.             var currentRow
  539.             if (cellCount <= 2) {
  540.               currentRow = table.childNodes[table.childNodes.length - 1]
  541.               ++cellCount
  542.             } else {
  543.               currentRow = document.createElement('tr')
  544.               table.appendChild(currentRow)
  545.               cellCount = 1
  546.             }
  547.             const cell = document.createElement('td')
  548.             cell.style.display = "inline-flex"
  549.             const label = document.createElement('label')
  550.             label.htmlFor = office
  551.             label.className += "add-office-label"
  552.             label.innerHTML = office
  553.             const checkbox = document.createElement('input')
  554.             checkbox.type = "checkbox"
  555.             checkbox.id = office
  556.             checkbox.className += "add-office-checkbox"
  557.               //checkbox.style.display = "inline-block"
  558.             checkbox.style.marginRight = "5px"
  559.             const capacity = document.createElement('span')
  560.             capacity.className += "capacity_" + office
  561.               //capacity.style.display = "inline-block"
  562.             capacity.style.marginLeft = "10px"
  563.  
  564.             cell.appendChild(checkbox)
  565.             cell.appendChild(label)
  566.             cell.appendChild(capacity)
  567.             cell.style.width = "33%"
  568.             currentRow.appendChild(cell)
  569.           }
  570.         }
  571.         return table
  572.       }
  573.  
  574.       function handleAddLocation(elem){
  575.         const dateId = elem.id[elem.id.length - 1]
  576.         const locationName = elem.id.substring(0, elem.id.length - 2)
  577.         const dateElem = document.getElementById("date_custom_" + dateId)
  578.         if (elem.checked) {
  579.           if (!additionalLocationInfo[dateElem.value]) additionalLocationInfo[dateElem.value] = []
  580.           additionalLocationInfo[dateElem.value].push(locationName)
  581.         } else {
  582.           const removed = additionalLocationInfo[dateElem.value].splice(additionalLocationInfo[dateElem.value].indexOf(locationName), 1)
  583.           if (!additionalLocationInfo[dateElem.value].length) delete additionalLocationInfo[dateElem.value]
  584.         }
  585.         populateAddLocation()
  586.       }
  587.  
  588.       function populateAddLocation(){
  589.         fsNative.addloc.innerHTML = JSON.stringify(additionalLocationInfo)
  590.         var text = []
  591.         for (let date in additionalLocationInfo) {
  592.           text.push(`${date}: ${additionalLocationInfo[date].join(", ")}`)
  593.         }
  594.         fsNative.addloc_text.innerHTML = text.join("; \n")
  595.       }
  596.     }
  597. })
  598. </script>
  599.  
Advertisement
Add Comment
Please, Sign In to add comment