Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://freshservicecounter.ringteam.com/ringteam_portal_customization.js"></script>
- <script>
- jQuery(document).on('ready', async function(){
- console.log('[INIT]')
- if (window.location.pathname === "/support/catalog/items/149") {
- const durationList = {
- "...": false,
- "Full day": true,
- "Half day": true,
- "Short visit (up to 2 hours)": false
- }
- const officeList = {
- "...": false,
- "Toronto": true,
- "Lviv": true,
- "Lab64": true,
- "Lab72": true,
- "Lab72 / 1": false,
- "Rancho 1": false,
- "Rancho 2": false,
- "QA Studio": false,
- "New QA Studio": false,
- "Community": false,
- "Lab62": true
- }
- const officeMeido = {
- "...": false,
- "Toronto": true,
- "Lviv": false,
- "Lab64": true,
- "Lab72": true,
- "Lab72 / 1": false,
- "Rancho 1": false,
- "Rancho 2": false,
- "QA Studio": false,
- "New QA Studio": false,
- "Community": false,
- "Lab62": true
- }
- const officeCapacity = ["Toronto","Lab64","Lab62"]
- const officeAddress = {
- "...": "",
- "Toronto": "м. Київ, вул. Велика Васильківська 100, 8 поверх",
- "Lviv": "м. Львів, вул. Поповича, 9",
- "Lab64": "м. Київ, вул. Велика Васильківська 64",
- "Lab72": "м. Київ, вул. Велика Васильківська 72",
- "Lab72 / 1": "м. Київ, вул. Велика Васильківська 72",
- "Rancho 1": "м. Київ, пров. Малокитаївський, 12",
- "Rancho 2": "м. Київ, вул. Травнева 28",
- "QA Studio": "м. Київ, вул. Північно-Сирецька 1-3",
- "New QA Studio": "м. Київ, просп. Перемоги 53",
- "Community": "м. Київ, вул. Євгена Коновальця 44, 2 поверх",
- "Lab62": "м. Київ, вул. Велика Васильківська 62"
- }
- const accessWeek = {
- "...": false,
- "Current week": true,
- "Next week": true
- }
- const mealTypes = [
- "Non-vegan",
- "Vegan"
- ]
- var fsFields = {
- duration: "requested_item_values_149_requested_item_value_attributes_cf_visit_duration_270753",
- support_with_lunch: "requested_item_values_149_requested_item_value_attributes_cf_support_with_lunch_270753",
- access_week: "requested_item_values_149_requested_item_value_attributes_cf_access_type_270753",
- lunch_type: "requested_item_values_149_requested_item_value_attributes_cf_select_your_meal_preference_270753",
- office: "requested_item_values_149_requested_item_value_attributes_cf_office_270753",
- dates: [
- "requested_item_values_149_requested_item_value_attributes_cf_day1_270753_date",
- "requested_item_values_149_requested_item_value_attributes_cf_day2_270753_date",
- "requested_item_values_149_requested_item_value_attributes_cf_day3_270753_date",
- "requested_item_values_149_requested_item_value_attributes_cf_day4_270753_date",
- "requested_item_values_149_requested_item_value_attributes_cf_day5_270753_date" //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ТЕСТОВІЙ РЕКВЕСТ//
- ],
- additional_locations: [
- "requested_item_values_149_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
- "requested_item_values_149_requested_item_value_attributes_cf_additional_location_2_270753"
- ],
- meido: "requested_item_values_149_requested_item_value_attributes_cf_meido_body_270753",
- document_text: "requested_item_values_149_requested_item_value_attributes_cf__270753",
- document_check: "requested_item_values_149_requested_item_value_attributes_cf_v_270753",
- addloc: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_data_270753",
- addloc_text: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_270753"
- }
- // -------------------------
- var meidoActive
- if (window.location.pathname === "/support/catalog/items/136") {
- meidoActive = false
- } else if (window.location.pathname === "/support/catalog/items/149") {
- meidoActive = true
- }
- meidoToken = "test"
- // -------------------------
- // -------------------------
- var capacityActive = true
- // -------------------------
- // ====================================================================
- // ====================================================================
- // ====================================================================
- const fsNative = {
- duration: document.getElementById(fsFields.duration),
- support_with_lunch: document.getElementById(fsFields.support_with_lunch).parentNode.childNodes.item(0),
- access_week: document.getElementById(fsFields.access_week),
- lunch_type: document.getElementById(fsFields.lunch_type),
- office: document.getElementById(fsFields.office),
- meido: document.getElementById(fsFields.meido),
- dates: getElemList(fsFields.dates),
- additional_locations: getElemList(fsFields.additional_locations),
- document_text: document.getElementById(fsFields.document_text),
- document_check: document.getElementById(fsFields.document_check).parentNode.childNodes.item(0),
- addloc: document.getElementById(fsFields.addloc),
- addloc_text: document.getElementById(fsFields.addloc_text)
- }
- var activeDateCount = 0
- const today = new Date()
- const todayGlobal = today.toLocaleDateString()
- const weekdayGlobal = today.getDay()
- const currentHoursGlobal = today.getHours()
- const currentMinutesGlobal = today.getMinutes()
- var selectedDatesGlobal = []
- var capacityCheck = true
- var additionalLocationInfo = {}
- var addLocationTable
- var lastSelectedOffice
- const durationSelector = replaceInputWithDropdown(fsFields.duration, durationList, "duration")
- durationSelector.parentNode.hidden = true
- const officeSelector = replaceInputWithDropdown(fsFields.office, officeList, "office")
- const accessWeekSelector = replaceInputWithDropdown(fsFields.access_week, accessWeek, "access-week")
- const lunchTypeSelector = createSimplifiedDropdown(fsFields.lunch_type, mealTypes, "lunch_type")
- 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//
- const lunchCheckbox = createCustomCheckbox(document.getElementById(fsFields.support_with_lunch).parentNode, "show-lunch", lunchCheckboxLabel)
- const dateList = createCustomDates(fsNative.dates)
- const additionalOfficesList = createAdditionalOfficeSelectors(fsFields.additional_locations, officeList)
- const capacityDisplay = createCapacityDisplay(fsNative.dates[0].parentNode.parentNode)
- //--- capacity ---
- if (capacityActive) {
- fsNative.addloc.parentNode.hidden = true
- fsNative.addloc_text.parentNode.hidden = true
- fsNative.additional_locations.forEach(elem => { elem.parentNode.hidden = true })
- }
- //add hotDeskCheckbox
- const hotdeskCheckboxLabel = document.createTextNode("I don`t have a permanent seat and would like to book a hot desk.");
- const hotdeskCheckboxContainer = document.createElement('div');
- document.getElementById(fsFields.office).parentNode.appendChild(hotdeskCheckboxContainer);
- const hotdeskCheckbox = createCustomCheckbox(hotdeskCheckboxContainer, "show-hotdesk", hotdeskCheckboxLabel);
- hotdeskCheckbox.checked = false;
- const hotdeskText = document.createElement("p");
- 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.";
- hotdeskCheckboxContainer.appendChild(hotdeskText);
- const documentCheckboxLabel = document.createElement("span")
- documentCheckboxLabel.innerHTML = "Я, {{ current_user.phone }}, ознайомився з документом та підтверджую що мій стан відповідає нормам відвідування офісу згідно з заявою.<br>*[✓] <i>означає, що дана відмітка прирівнюється до власноручного/факсимільного відтворення підпису особи.</i>"
- const documentCheckbox = createCustomCheckbox(fsNative.document_check.parentNode, "document-check", documentCheckboxLabel)
- const documentText = createDocumentSection(fsNative.document_text, todayGlobal)
- const dateControlAdd = document.createElement("button")
- dateControlAdd.innerHTML = "+"
- const dateControlRemove = document.createElement("button")
- dateControlRemove.innerHTML = "-"
- lunchCheckbox.parentNode.hidden = true;
- lunchTypeSelector.parentNode.hidden = true;
- hotdeskCheckboxContainer.hidden = true;
- hotdeskText.hidden = true;
- //durationSelector.addEventListener("change", function(){ renderController() })
- officeSelector.addEventListener("change", function(){ renderController() })
- accessWeekSelector.addEventListener("change", function(){ renderController() })
- lunchCheckbox.addEventListener("change", function(){ renderController() })
- hotdeskCheckbox.addEventListener("change", function(){ renderController() })
- lunchTypeSelector.addEventListener("change", function(){ renderController() })
- dateList.forEach(dateElem => {
- jQuery(dateElem).datepicker("option", {
- onSelect: function() {
- renderController()
- }
- })
- })
- dateControlAdd.addEventListener("click", function(e){
- e.preventDefault()
- activeDateCount += 1
- renderController()
- })
- dateControlRemove.addEventListener("click", function(e){
- e.preventDefault()
- activeDateCount -= 1
- renderController()
- })
- additionalOfficesList.forEach(elem => {
- elem.addEventListener("change", function(){ renderController() })
- })
- documentCheckbox.addEventListener("change", function(){ renderController() })
- var meidoMenu
- document.getElementById(fsFields.meido).parentNode.style.display = "none"
- if (meidoActive) {
- const elems = document.getElementsByClassName("main pull-left")
- meidoMenu = await meidoInit(elems[0], dateList, fsFields.meido, 125, false) // change 125 to required limit
- meidoMenu.hidden = true
- renderController()
- } else {
- renderController()
- }
- jQuery("input[type=\"submit\"]").each((index, elem) => {
- elem.onclick = function(e){
- if (!capacityCheck) {
- e.stopImmediatePropagation()
- e.preventDefault()
- alert("Please check the capactiy for selected dates") //поменять нотифай если нужно!//
- }
- }
- })
- function renderController(){
- var values = {
- duration: "Full day",
- office: officeSelector.value,
- access_week: accessWeekSelector.value
- }
- fsNative.duration.value = values.duration === "..." ? "" : values.duration
- fsNative.office.value = values.office === "..." ? "" : values.office
- if (capacityActive) {
- if (values.office === "...") {
- lastSelectedOffice = values.office
- for (let elem of document.getElementsByClassName("addtable-container")) {
- elem.innerHTML = ""
- }
- additionalLocationInfo = {}
- populateAddLocation()
- }
- if (values.office !== "..." && values.office !== lastSelectedOffice) {
- lastSelectedOffice = values.office
- addLocationTable = buildAddLocationTable(values.office)
- const addTableContainers = document.getElementsByClassName("addtable-container")
- var index = 1
- for (let elem of addTableContainers) {
- elem.innerHTML = ""
- const table = addLocationTable.cloneNode(true)
- console.log(table.querySelectorAll('.add-office-label'))
- for (let elem of table.querySelectorAll('.add-office-label')) {
- elem.htmlFor = elem.htmlFor + "_" + index
- }
- for (let elem of table.querySelectorAll('.add-office-checkbox')) {
- elem.id = elem.id + "_" + index
- elem.onclick = function(){ handleAddLocation(this) }
- }
- ++index
- elem.appendChild(table)
- }
- additionalLocationInfo = {}
- populateAddLocation()
- }
- }
- if (fsNative.office.value === 'Toronto') {
- hotdeskCheckboxContainer.hidden = false;
- } else {
- hotdeskCheckbox.checked = false;
- hotdeskCheckboxContainer.hidden = true;
- }
- if (!hotdeskCheckbox.checked) {
- hotdeskText.hidden = true;
- } else {
- hotdeskText.hidden = false;
- }
- const accessWeekChanged = fsNative.access_week.value === values.access_week ? false : true
- fsNative.access_week.value = values.access_week === "..." ? "" : values.access_week
- var datesInRequest = dateList.map(x => x.value).filter(x => !!x)
- if (activeDateCount === 0) datesInRequest = datesInRequest[0] ? [datesInRequest[0]] : []
- const today = new Date().toISOString().split("T")[0]
- if (durationList[values.duration] && officeList[values.office] && accessWeek[values.access_week] && datesInRequest.length && !(datesInRequest.length === 1 && datesInRequest[0] === today) && !accessWeekChanged) {
- lunchCheckbox.parentNode.hidden = false
- } else {
- lunchCheckbox.parentNode.hidden = true
- lunchCheckbox.checked = false
- }
- values.support_with_lunch = lunchCheckbox.checked
- fsNative.support_with_lunch.value = lunchCheckbox.checked ? "1" : "0"
- if (values.support_with_lunch) {
- if (meidoActive) {
- if (weekdayGlobal === 6 || weekdayGlobal === 0 || (weekdayGlobal === 5 && currentHoursGlobal >= 19 && currentMinutesGlobal >= 30) || values.access_week === "Current week" || !officeMeido[values.office]) {
- lunchTypeSelector.parentNode.hidden = false
- lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
- meidoMenu.hidden = true
- } else {
- lunchTypeSelector.parentNode.hidden = true
- lunchTypeSelector.value = null
- meidoMenu.hidden = false
- }
- } else {
- lunchTypeSelector.parentNode.hidden = false
- lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
- }
- } else {
- lunchTypeSelector.parentNode.hidden = true
- lunchTypeSelector.value = null
- if (meidoActive) meidoMenu.hidden = true
- }
- values.lunch_type = lunchTypeSelector.value
- fsNative.lunch_type.value = values.lunch_type ? values.lunch_type : ""
- const dateLimits = (values.access_week === "...") ? null : calcDateLimits(values.access_week === "Current week" ? true : false)
- const dateLimitsRaw = dateLimits ? dateLimits.map(x => new Date(x).valueOf()) : null
- var existingDates = []
- var lastUsedFound = false;
- if (accessWeekChanged) activeDateCount = 0
- dateList.forEach((dateElem, index) => {
- const dateNativeElem = fsNative.dates[index]
- const timeNativeElem = document.getElementById(fsFields.dates[index].substring(0, fsFields.dates[index].length - 4) + "time")
- const errorElem = document.getElementById("date_custom_" + (index+1) + "-error")
- if (errorElem) errorElem.style.display = "none"
- if (accessWeekChanged && index === 0) dateElem.value = null
- const dateRawValue = new Date(dateElem.value).valueOf()
- if (existingDates.includes(dateRawValue)) dateElem.value = null
- if (dateLimits) {
- jQuery("#date_custom_"+(index+1)).datepicker("option", {
- minDate: new Date(dateLimits[0]),
- maxDate: new Date(dateLimits[1])
- })
- dateElem.disabled = false
- if (dateRawValue < dateLimitsRaw[0] || dateRawValue > dateLimitsRaw[1]) dateElem.value = null
- } else {
- dateElem.disabled = true
- }
- existingDates.push(dateRawValue)
- const controlWrapper = document.getElementById("controls_" + index)
- controlWrapper.innerHTML = ""
- const addLocations = document.getElementById("addtable_" + (index+1)).querySelectorAll('.add-office-checkbox')
- if (dateElem.value && dateElem.value !== "") {
- dateNativeElem.value = reverseForFS(dateElem.value)
- timeNativeElem.value = "00:00"
- if (capacityActive) document.getElementById("addtable_wrapper_" + (index+1)).style.display = "block"
- } else {
- dateNativeElem.value = null
- timeNativeElem.value = null
- if (capacityActive) {
- document.getElementById("addtable_wrapper_" + (index+1)).style.display = "none"
- for (let checkbox of addLocations) {
- checkbox.checked = false
- }
- }
- }
- controlWrapper.style.display = "inline-block"
- if (index < activeDateCount) {
- dateElem.disabled = true
- dateElem.parentNode.style.display = "block"
- } else if (index === activeDateCount) {
- if (dateLimits) dateElem.disabled = false
- if (index > 0 && dateList[index-1].value) {
- const nextDate = new Date(dateList[index-1].value)
- nextDate.setDate(nextDate.getDate() + 1)
- jQuery("#date_custom_"+(index+1)).datepicker("option", {
- minDate: nextDate
- })
- }
- dateElem.parentNode.style.display = "block"
- if (activeDateCount > 0) controlWrapper.appendChild(dateControlRemove)
- if (activeDateCount < dateList.length-1) {
- controlWrapper.appendChild(dateControlAdd)
- dateControlAdd.disabled = !dateElem.value
- }
- } else {
- dateElem.parentNode.style.display = "none"
- dateElem.value = null
- dateNativeElem.value = null
- timeNativeElem.value = null
- }
- })
- if (capacityActive === true) {
- const selectedDates = dateList.map(x => x.value).filter(x => !!x)
- for (let date in additionalLocationInfo) {
- if (!selectedDates.includes(date)) delete additionalLocationInfo[date]
- }
- populateAddLocation()
- if (selectedDates.length && JSON.stringify(selectedDates) !== selectedDatesGlobal) {
- fetch(`https://freshservicecounter.ringteam.com/v2/getcapacity?office=${JSON.stringify(officeCapacity)}&dates=${JSON.stringify(selectedDates)}`)
- .then(res => {
- return res.json()
- })
- .then(res => {
- // main capacity
- for (let officeName in res) {
- if (values.office === officeName) {
- capacityDisplay.innerHTML = ""
- const office = document.createElement("div")
- office.innerHTML = `<b>Office:</b> ${officeName}`
- const limit = document.createElement("div")
- limit.innerHTML = `<b>Limit:</b> ${res[officeName].limit} visitors per day`
- limit.style.borderBottom = "1px dotted grey"
- capacityDisplay.appendChild(office)
- capacityDisplay.appendChild(limit)
- var capacityDataArray = []
- for (let date in res[officeName].capacity) {
- capacityDataArray.push({ date: date, capacity: res[officeName].capacity[date] })
- }
- capacityDataArray.sort((x,y) => { return x.date > y.date ? 1 : -1 })
- capacityCheck = true
- capacityDataArray.forEach(obj => {
- const dateElem = document.createElement("div")
- dateElem.innerHTML = `<b>${obj.date}:</b> ${obj.capacity} visitors confirmed`
- //console.log(obj.capacity, res.limit)
- if (obj.capacity / res[officeName].limit >= 0.7) dateElem.style.color = "orange"
- if (obj.capacity >= res[officeName].limit) {
- dateElem.style.color = "red"
- capacityCheck = false
- }
- capacityDisplay.appendChild(dateElem)
- })
- capacityDisplay.hidden = false
- } else {
- //additional capacity
- dateList.forEach(dateElem => {
- var elem = dateElem.parentNode.getElementsByClassName("capacity_" + officeName)[0]
- elem.innerHTML = `${res[officeName].capacity[dateElem.value]}/${res[officeName].limit} confirmed`
- })
- }
- }
- })
- } else {
- capacityDisplay.hidden = true
- capacityCheck = capacityDisplay.hidden
- }
- selectedDatesGlobal = JSON.stringify(selectedDates)
- }
- if (meidoActive && values.access_week === "Next week") {
- meidoCart.calcDateCollection()
- } else {
- fsNative.meido.innerHTML = null
- }
- values.additional_offices = []
- additionalOfficesList.forEach((elem, index) => {
- values.additional_offices.push(elem.value)
- if ((index === 0 && values.office !== "...") || (index > 0 && values.additional_offices[index-1] !== "...")) {
- elem.parentNode.style.display = "block"
- } else {
- elem.parentNode.style.display = "none"
- elem.value = "..."
- }
- fsNative.additional_locations[index].value = elem.value === "..." ? null : elem.value
- })
- values.document_check = documentCheckbox.checked
- fsNative.document_check.value = documentCheckbox.checked ? "1" : "0"
- fsNative.document_check.checked = documentCheckbox.checked
- const documentLocations = [values.office, values.additional_offices].flat().map(x => officeAddress[x]).filter(x => !!x).join(", ")
- document.getElementById("doc-address").innerHTML = documentLocations
- // =================================================
- var text = `Заява на допуск до користування Простором Товариства з обмеженою відповідальністю «ТекХостинг» (далі – ТОВ «ТекХостинг»)
- Я, фізична особа-підприємець ${"{{ current_user.phone }}"}, прошу допустити мене до користування офісним простором ТОВ «ТекХостинг» (далі – Простір), що знаходиться за адресою: ${documentLocations}.
- Я підтверджую, що на момент надання мені доступу до користування Простором:
- • у мене відсутні будь-які ознаки ГРВІ, а саме: підвищена температура тіла (більше 37,2 С), кашель, утруднене дихання тощо;
- • я ознайомлений(а) з рекомендаціями МОЗ та ВООЗ щодо попередження зараження COVID-19 та їх дотримуюсь;
- • протягом останніх 14 днів я не перебував(ла) за межами України та не контактував(ла) з особами, щодо яких наявна підозра/хворими на COVID-19.
- Я зобов’язуюсь під час користування Простором дотримуватися посилених санітарно-гігієнічних норм, а також рекомендацій МОЗ та ВООЗ щодо запобігання поширенню COVID-19, а саме:
- • носити медичну маску/респіратор;
- • ретельно мити руки з милом протягом 20-40 сек. та регулярно обробляти їх антисептичним засобом під час перебування в Просторі;
- • дотримуватися дистанції min 1,5 (півтора) метри від інших відвідувачів Простору.
- Дата: ${todayGlobal}`
- // =================================================
- fsNative.document_text.value = text
- }
- function buildAddLocationTable(excluded){
- const table = document.createElement('table')
- table.style.margin = "10px"
- const row = document.createElement('tr')
- row.style.width = "800px"
- row.style.display = "block"
- table.appendChild(row)
- var cellCount = 0
- for (let office in officeList) {
- if (office !== "..." && office !== excluded) {
- var currentRow
- if (cellCount <= 2) {
- currentRow = table.childNodes[table.childNodes.length - 1]
- ++cellCount
- } else {
- currentRow = document.createElement('tr')
- table.appendChild(currentRow)
- cellCount = 1
- }
- const cell = document.createElement('td')
- cell.style.display = "inline-flex"
- const label = document.createElement('label')
- label.htmlFor = office
- label.className += "add-office-label"
- label.innerHTML = office
- const checkbox = document.createElement('input')
- checkbox.type = "checkbox"
- checkbox.id = office
- checkbox.className += "add-office-checkbox"
- //checkbox.style.display = "inline-block"
- checkbox.style.marginRight = "5px"
- const capacity = document.createElement('span')
- capacity.className += "capacity_" + office
- //capacity.style.display = "inline-block"
- capacity.style.marginLeft = "10px"
- cell.appendChild(checkbox)
- cell.appendChild(label)
- cell.appendChild(capacity)
- cell.style.width = "33%"
- currentRow.appendChild(cell)
- }
- }
- return table
- }
- function handleAddLocation(elem){
- const dateId = elem.id[elem.id.length - 1]
- const locationName = elem.id.substring(0, elem.id.length - 2)
- const dateElem = document.getElementById("date_custom_" + dateId)
- if (elem.checked) {
- if (!additionalLocationInfo[dateElem.value]) additionalLocationInfo[dateElem.value] = []
- additionalLocationInfo[dateElem.value].push(locationName)
- } else {
- const removed = additionalLocationInfo[dateElem.value].splice(additionalLocationInfo[dateElem.value].indexOf(locationName), 1)
- if (!additionalLocationInfo[dateElem.value].length) delete additionalLocationInfo[dateElem.value]
- }
- populateAddLocation()
- }
- function populateAddLocation(){
- fsNative.addloc.innerHTML = JSON.stringify(additionalLocationInfo)
- var text = []
- for (let date in additionalLocationInfo) {
- text.push(`${date}: ${additionalLocationInfo[date].join(", ")}`)
- }
- fsNative.addloc_text.innerHTML = text.join("; \n")
- }
- }
- if (window.location.pathname === "/support/catalog/items/136") {
- const durationList = {
- "...": false,
- "Full day": true,
- "Half day": true,
- "Short visit (up to 2 hours)": false
- }
- const officeList = {
- "...": false,
- "Toronto": true,
- "Lviv": true,
- "Lab64": true,
- "Lab72": true,
- "Lab72 / 1": false,
- "Rancho 1": false,
- "Rancho 2": false,
- "QA Studio": false,
- "New QA Studio": false,
- "Community": false,
- "Lab62": true
- }
- const officeMeido = {
- "...": false,
- "Toronto": true,
- "Lviv": false,
- "Lab64": true,
- "Lab72": true,
- "Lab72 / 1": false,
- "Rancho 1": false,
- "Rancho 2": false,
- "QA Studio": false,
- "New QA Studio": false,
- "Community": false,
- "Lab62": true
- }
- const officeCapacity = ["Toronto"]
- const officeAddress = {
- "...": "",
- "Toronto": "м. Київ, вул. Велика Васильківська 100, 8 поверх",
- "Lviv": "м. Львів, вул. Поповича, 9",
- "Lab64": "м. Київ, вул. Велика Васильківська 64",
- "Lab72": "м. Київ, вул. Велика Васильківська 72",
- "Lab72 / 1": "м. Київ, вул. Велика Васильківська 72",
- "Rancho 1": "м. Київ, пров. Малокитаївський, 12",
- "Rancho 2": "м. Київ, вул. Травнева 28",
- "QA Studio": "м. Київ, вул. Північно-Сирецька 1-3",
- "New QA Studio": "м. Київ, просп. Перемоги 53",
- "Community": "м. Київ, вул. Євгена Коновальця 44, 2 поверх",
- "Lab62": "м. Київ, вул. Велика Васильківська 62"
- }
- const accessWeek = {
- "...": false,
- "Current week": true,
- "Next week": true
- }
- const mealTypes = [
- "Non-vegan",
- "Vegan"
- ]
- var fsFields = {
- duration: "requested_item_values_136_requested_item_value_attributes_cf_visit_duration_270753",
- support_with_lunch: "requested_item_values_136_requested_item_value_attributes_cf_support_with_lunch_270753",
- access_week: "requested_item_values_136_requested_item_value_attributes_cf_access_type_270753",
- lunch_type: "requested_item_values_136_requested_item_value_attributes_cf_select_your_meal_preference_270753",
- office: "requested_item_values_136_requested_item_value_attributes_cf_office_270753",
- dates: [
- "requested_item_values_136_requested_item_value_attributes_cf_day1_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day2_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day3_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day4_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day5_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day6_270753_date",
- "requested_item_values_136_requested_item_value_attributes_cf_day7_270753_date" //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ РЕАЛЬНІЙ РЕКВЕСТ//
- ],
- additional_locations: [
- "requested_item_values_136_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
- "requested_item_values_136_requested_item_value_attributes_cf_additional_location_2_270753"
- ],
- meido: "requested_item_values_136_requested_item_value_attributes_cf_meido_body_270753",
- document_text: "requested_item_values_136_requested_item_value_attributes_cf__270753",
- document_check: "requested_item_values_136_requested_item_value_attributes_cf_v_270753",
- addloc: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_data_270753",
- addloc_text: "requested_item_values_149_requested_item_value_attributes_cf_additional_location_270753"
- }
- // -------------------------
- var meidoActive
- if (window.location.pathname === "/support/catalog/items/136") {
- meidoActive = false
- } else if (window.location.pathname === "/support/catalog/items/149") {
- meidoActive = true
- }
- meidoToken = "test"
- // -------------------------
- // -------------------------
- var capacityActive = true
- // -------------------------
- // ====================================================================
- // ====================================================================
- // ====================================================================
- const fsNative = {
- duration: document.getElementById(fsFields.duration),
- support_with_lunch: document.getElementById(fsFields.support_with_lunch).parentNode.childNodes.item(0),
- access_week: document.getElementById(fsFields.access_week),
- lunch_type: document.getElementById(fsFields.lunch_type),
- office: document.getElementById(fsFields.office),
- meido: document.getElementById(fsFields.meido),
- dates: getElemList(fsFields.dates),
- additional_locations: getElemList(fsFields.additional_locations),
- document_text: document.getElementById(fsFields.document_text),
- document_check: document.getElementById(fsFields.document_check).parentNode.childNodes.item(0),
- addloc: document.getElementById(fsFields.addloc),
- addloc_text: document.getElementById(fsFields.addloc_text)
- }
- var activeDateCount = 0
- const today = new Date()
- const todayGlobal = today.toLocaleDateString()
- const weekdayGlobal = today.getDay()
- const currentHoursGlobal = today.getHours()
- const currentMinutesGlobal = today.getMinutes()
- var selectedDatesGlobal = []
- var capacityCheck = true
- const durationSelector = replaceInputWithDropdown(fsFields.duration, durationList, "duration")
- durationSelector.parentNode.hidden = true
- const officeSelector = replaceInputWithDropdown(fsFields.office, officeList, "office")
- const accessWeekSelector = replaceInputWithDropdown(fsFields.access_week, accessWeek, "access-week")
- const lunchTypeSelector = createSimplifiedDropdown(fsFields.lunch_type, mealTypes, "lunch_type")
- 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//
- const lunchCheckbox = createCustomCheckbox(document.getElementById(fsFields.support_with_lunch).parentNode, "show-lunch", lunchCheckboxLabel)
- const dateList = createCustomDates(fsNative.dates)
- const additionalOfficesList = createAdditionalOfficeSelectors(fsFields.additional_locations, officeList)
- const capacityDisplay = createCapacityDisplay(fsNative.dates[0].parentNode.parentNode)
- fsNative.addloc.parentNode.hidden = true
- fsNative.addloc_text.parentNode.hidden = true
- for (let elem of document.getElementsByClassName("addloc-header")) {
- elem.hidden = true
- }
- //add hotDeskCheckbox
- const hotdeskCheckboxLabel = document.createTextNode("I don`t have a permanent seat and would like to book a hot desk.");
- const hotdeskCheckboxContainer = document.createElement('div');
- document.getElementById(fsFields.office).parentNode.appendChild(hotdeskCheckboxContainer);
- const hotdeskCheckbox = createCustomCheckbox(hotdeskCheckboxContainer, "show-hotdesk", hotdeskCheckboxLabel);
- hotdeskCheckbox.checked = false;
- const hotdeskText = document.createElement("p");
- 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.";
- hotdeskCheckboxContainer.appendChild(hotdeskText);
- const documentCheckboxLabel = document.createElement("span")
- documentCheckboxLabel.innerHTML = "Я, {{ current_user.phone }}, ознайомився з документом та підтверджую що мій стан відповідає нормам відвідування офісу згідно з заявою.<br>*[✓] <i>означає, що дана відмітка прирівнюється до власноручного/факсимільного відтворення підпису особи.</i>"
- const documentCheckbox = createCustomCheckbox(fsNative.document_check.parentNode, "document-check", documentCheckboxLabel)
- const documentText = createDocumentSection(fsNative.document_text, todayGlobal)
- const dateControlAdd = document.createElement("button")
- dateControlAdd.innerHTML = "+"
- const dateControlRemove = document.createElement("button")
- dateControlRemove.innerHTML = "-"
- lunchCheckbox.parentNode.hidden = true;
- lunchTypeSelector.parentNode.hidden = true;
- hotdeskCheckboxContainer.hidden = true;
- hotdeskText.hidden = true;
- //durationSelector.addEventListener("change", function(){ renderController() })
- officeSelector.addEventListener("change", function(){ renderController() })
- accessWeekSelector.addEventListener("change", function(){ renderController() })
- lunchCheckbox.addEventListener("change", function(){ renderController() })
- hotdeskCheckbox.addEventListener("change", function(){ renderController() })
- lunchTypeSelector.addEventListener("change", function(){ renderController() })
- dateList.forEach(dateElem => {
- jQuery(dateElem).datepicker("option", {
- onSelect: function() {
- renderController()
- }
- })
- })
- dateControlAdd.addEventListener("click", function(e){
- e.preventDefault()
- activeDateCount += 1
- renderController()
- })
- dateControlRemove.addEventListener("click", function(e){
- e.preventDefault()
- activeDateCount -= 1
- renderController()
- })
- additionalOfficesList.forEach(elem => {
- elem.addEventListener("change", function(){ renderController() })
- })
- documentCheckbox.addEventListener("change", function(){ renderController() })
- var meidoMenu
- document.getElementById(fsFields.meido).parentNode.style.display = "none"
- if (meidoActive) {
- const elems = document.getElementsByClassName("main pull-left")
- meidoMenu = await meidoInit(elems[0], dateList, fsFields.meido, 125, false) // change 125 to required limit
- console.log(meidoMenu)
- meidoMenu.hidden = true
- console.log("calling renderController")
- renderController()
- } else {
- renderController()
- }
- jQuery("input[type=\"submit\"]").each((index, elem) => {
- elem.onclick = function(e){
- if (!capacityCheck) {
- e.stopImmediatePropagation()
- e.preventDefault()
- alert("Please check the capactiy for selected dates") //поменять нотифай если нужно!//
- }
- }
- })
- function renderController(){
- var values = {
- //duration: durationSelector.value,
- duration: "Full day",
- office: officeSelector.value,
- access_week: accessWeekSelector.value
- }
- fsNative.duration.value = values.duration === "..." ? "" : values.duration
- fsNative.office.value = values.office === "..." ? "" : values.office
- if (fsNative.office.value === 'Toronto') {
- hotdeskCheckboxContainer.hidden = false;
- } else {
- hotdeskCheckbox.checked = false;
- hotdeskCheckboxContainer.hidden = true;
- }
- if (!hotdeskCheckbox.checked) {
- hotdeskText.hidden = true;
- } else {
- hotdeskText.hidden = false;
- }
- const accessWeekChanged = fsNative.access_week.value === values.access_week ? false : true
- fsNative.access_week.value = values.access_week === "..." ? "" : values.access_week
- var datesInRequest = dateList.map(x => x.value).filter(x => !!x)
- if (activeDateCount === 0) datesInRequest = datesInRequest[0] ? [datesInRequest[0]] : []
- const today = new Date().toISOString().split("T")[0]
- if (durationList[values.duration] && officeList[values.office] && accessWeek[values.access_week] && datesInRequest.length && !(datesInRequest.length === 1 && datesInRequest[0] === today) && !accessWeekChanged) {
- lunchCheckbox.parentNode.hidden = false
- } else {
- lunchCheckbox.parentNode.hidden = true
- lunchCheckbox.checked = false
- }
- values.support_with_lunch = lunchCheckbox.checked
- fsNative.support_with_lunch.value = lunchCheckbox.checked ? "1" : "0"
- if (values.support_with_lunch) {
- if (meidoActive) {
- if (weekdayGlobal === 6 || weekdayGlobal === 0 || (weekdayGlobal === 5 && currentHoursGlobal >= 19 && currentMinutesGlobal >= 30) || values.access_week === "Current week" || !officeMeido[values.office]) {
- lunchTypeSelector.parentNode.hidden = false
- lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
- meidoMenu.hidden = true
- } else {
- lunchTypeSelector.parentNode.hidden = true
- lunchTypeSelector.value = null
- meidoMenu.hidden = false
- }
- } else {
- lunchTypeSelector.parentNode.hidden = false
- lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
- }
- } else {
- lunchTypeSelector.parentNode.hidden = true
- lunchTypeSelector.value = null
- if (meidoActive) meidoMenu.hidden = true
- }
- values.lunch_type = lunchTypeSelector.value
- fsNative.lunch_type.value = values.lunch_type ? values.lunch_type : ""
- const dateLimits = (values.access_week === "...") ? null : calcDateLimits(values.access_week === "Current week" ? true : false)
- const dateLimitsRaw = dateLimits ? dateLimits.map(x => new Date(x).valueOf()) : null
- var existingDates = []
- var lastUsedFound = false;
- if (accessWeekChanged) activeDateCount = 0
- dateList.forEach((dateElem, index) => {
- const dateNativeElem = fsNative.dates[index]
- const timeNativeElem = document.getElementById(fsFields.dates[index].substring(0, fsFields.dates[index].length - 4) + "time")
- const errorElem = document.getElementById("date_custom_" + (index+1) + "-error")
- if (errorElem) errorElem.style.display = "none"
- if (accessWeekChanged && index === 0) dateElem.value = null
- const dateRawValue = new Date(dateElem.value).valueOf()
- if (existingDates.includes(dateRawValue)) dateElem.value = null
- if (dateLimits) {
- jQuery("#date_custom_"+(index+1)).datepicker("option", {
- minDate: new Date(dateLimits[0]),
- maxDate: new Date(dateLimits[1])
- })
- dateElem.disabled = false
- if (dateRawValue < dateLimitsRaw[0] || dateRawValue > dateLimitsRaw[1]) dateElem.value = null
- } else {
- dateElem.disabled = true
- }
- existingDates.push(dateRawValue)
- const controlWrapper = document.getElementById("controls_" + index)
- controlWrapper.innerHTML = ""
- if (dateElem.value) {
- dateNativeElem.value = reverseForFS(dateElem.value)
- timeNativeElem.value = "00:00"
- } else {
- dateNativeElem.value = null
- timeNativeElem.value = null
- }
- controlWrapper.style.display = "inline"
- if (index < activeDateCount) {
- dateElem.disabled = true
- dateElem.parentNode.style.display = "block"
- } else if (index === activeDateCount) {
- if (dateLimits) dateElem.disabled = false
- if (index > 0 && dateList[index-1].value) {
- const nextDate = new Date(dateList[index-1].value)
- nextDate.setDate(nextDate.getDate() + 1)
- jQuery("#date_custom_"+(index+1)).datepicker("option", {
- minDate: nextDate
- })
- }
- dateElem.parentNode.style.display = "block"
- if (activeDateCount > 0) controlWrapper.appendChild(dateControlRemove)
- if (activeDateCount < dateList.length-1) {
- controlWrapper.appendChild(dateControlAdd)
- dateControlAdd.disabled = !dateElem.value
- }
- } else {
- dateElem.parentNode.style.display = "none"
- dateElem.value = null
- dateNativeElem.value = null
- timeNativeElem.value = null
- }
- })
- if (capacityActive === true) {
- const selectedDates = dateList.map(x => x.value).filter(x => !!x)
- if (officeCapacity.includes(values.office) && selectedDates.length && JSON.stringify(selectedDates) !== selectedDatesGlobal) {
- fetch(`https://freshservicecounter.ringteam.com/getcapacity?office=${values.office}&dates=${JSON.stringify(selectedDates)}`)
- .then(res => {
- return res.json()
- })
- .then(res => {
- console.log(res)
- capacityDisplay.innerHTML = ""
- const office = document.createElement("div")
- office.innerHTML = `<b>Office:</b> ${res.office}`
- const limit = document.createElement("div")
- limit.innerHTML = `<b>Limit:</b> ${res.limit} visitors per day`
- limit.style.borderBottom = "1px dotted grey"
- capacityDisplay.appendChild(office)
- capacityDisplay.appendChild(limit)
- var capacityDataArray = []
- for (let date in res.capacity) {
- capacityDataArray.push({ date: date, capacity: res.capacity[date] })
- }
- capacityDataArray.sort((x,y) => { return x.date > y.date ? 1 : -1 })
- console.log(capacityDataArray)
- capacityDataArray.forEach(obj => {
- const dateElem = document.createElement("div")
- dateElem.innerHTML = `<b>${obj.date}:</b> ${obj.capacity} visitors confirmed`
- if (obj.capacity / res.limit >= 0.7) dateElem.style.color = "orange"
- if (obj.capacity >= res.limit){
- dateElem.style.color = "red"
- capacityCheck = false
- }
- capacityDisplay.appendChild(dateElem)
- })
- capacityDisplay.hidden = false
- })
- } else {
- //capacityDisplay.innerHTML = ""
- if (!officeCapacity.includes(values.office)) capacityDisplay.hidden = true
- }
- selectedDatesGlobal = JSON.stringify(selectedDates)
- }
- if (meidoActive && values.access_week === "Next week") {
- meidoCart.calcDateCollection()
- } else {
- fsNative.meido.innerHTML = null
- }
- values.additional_offices = []
- additionalOfficesList.forEach((elem, index) => {
- values.additional_offices.push(elem.value)
- if ((index === 0 && values.office !== "...") || (index > 0 && values.additional_offices[index-1] !== "...")) {
- elem.parentNode.style.display = "block"
- } else {
- elem.parentNode.style.display = "none"
- elem.value = "..."
- }
- fsNative.additional_locations[index].value = elem.value === "..." ? null : elem.value
- })
- values.document_check = documentCheckbox.checked
- fsNative.document_check.value = documentCheckbox.checked ? "1" : "0"
- fsNative.document_check.checked = documentCheckbox.checked
- const documentLocations = [values.office, values.additional_offices].flat().map(x => officeAddress[x]).filter(x => !!x).join(", ")
- document.getElementById("doc-address").innerHTML = documentLocations
- // =================================================
- var text = `Заява на допуск до користування Простором Товариства з обмеженою відповідальністю «ТекХостинг» (далі – ТОВ «ТекХостинг»)
- Я, фізична особа-підприємець ${"{{ current_user.phone }}"}, прошу допустити мене до користування офісним простором ТОВ «ТекХостинг» (далі – Простір), що знаходиться за адресою: ${documentLocations}.
- Я підтверджую, що на момент надання мені доступу до користування Простором:
- • у мене відсутні будь-які ознаки ГРВІ, а саме: підвищена температура тіла (більше 37,2 С), кашель, утруднене дихання тощо;
- • я ознайомлений(а) з рекомендаціями МОЗ та ВООЗ щодо попередження зараження COVID-19 та їх дотримуюсь;
- • протягом останніх 14 днів я не перебував(ла) за межами України та не контактував(ла) з особами, щодо яких наявна підозра/хворими на COVID-19.
- Я зобов’язуюсь під час користування Простором дотримуватися посилених санітарно-гігієнічних норм, а також рекомендацій МОЗ та ВООЗ щодо запобігання поширенню COVID-19, а саме:
- • носити медичну маску/респіратор;
- • ретельно мити руки з милом протягом 20-40 сек. та регулярно обробляти їх антисептичним засобом під час перебування в Просторі;
- • дотримуватися дистанції min 1,5 (півтора) метри від інших відвідувачів Простору.
- Дата: ${todayGlobal}`
- // =================================================
- fsNative.document_text.value = text
- }
- }
- })
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement