Advertisement
VladislavNechepaev

Untitled

Dec 29th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.   jQuery(document).on('ready', async function(){
  3.     try {
  4.       document.getElementById("show_request_for").remove()
  5.     } catch {
  6.       console.log('No elements to remove')
  7.     }
  8.       //    document.getElementById("add-cc-button").remove()
  9.  
  10.  
  11.     console.log('[INIT]')
  12.     if (window.location.pathname === "/support/catalog/items/136" || window.location.pathname === "/support/catalog/items/149") {
  13.       const durationList = {
  14.         "...": false,
  15.         "Full day": true,
  16.         "Half day": true,
  17.         "Short visit (up to 2 hours)": false
  18.       }
  19.       const officeList = {
  20.         "...": false,
  21.         "Toronto": true,
  22.         "Lviv": true,
  23.         "Lab64": true,
  24.         "Lab72": true,
  25.         "Lab72 / 1": false,
  26.         "Rancho 1": false,
  27.         "Rancho 2": false,
  28.         "QA Studio": false,
  29.         "New QA Studio": false,
  30.         "Community": false,
  31.         "Lab62": true
  32.       }
  33.       const officeMeido = {
  34.         "...": false,
  35.         "Toronto": true,
  36.         "Lviv": false,
  37.         "Lab64": true,
  38.         "Lab72": true,
  39.         "Lab72 / 1": false,
  40.         "Rancho 1": false,
  41.         "Rancho 2": false,
  42.         "QA Studio": false,
  43.         "New QA Studio": false,
  44.         "Community": false,
  45.         "Lab62": true
  46.       }
  47.       const officeCapacity = ["Toronto","Lab64","Lab62"]
  48.       const officeAddress = {
  49.         "...": "",
  50.         "Toronto": "м. Київ, вул. Велика Васильківська 100, 8 поверх",
  51.         "Lviv": "м. Львів, вул. Поповича, 9",
  52.         "Lab64": "м. Київ, вул. Велика Васильківська 64",
  53.         "Lab72": "м. Київ, вул. Велика Васильківська 72",
  54.         "Lab72 / 1": "м. Київ, вул. Велика Васильківська 72",
  55.         "Rancho 1": "м. Київ, пров. Малокитаївський, 12",
  56.         "Rancho 2": "м. Київ, вул. Травнева 28",
  57.         "QA Studio": "м. Київ, вул. Північно-Сирецька 1-3",
  58.         "New QA Studio": "м. Київ, просп. Перемоги 53",
  59.         "Community": "м. Київ, вул. Євгена Коновальця 44, 2 поверх",
  60.         "Lab62": "м. Київ, вул. Велика Васильківська 62"
  61.       }
  62.       const accessWeek = {
  63.         "...": false,
  64.         "Current week": true,
  65.         "Next week": true
  66.       }
  67.       const mealTypes = [
  68.         "Non-vegan",
  69.         "Vegan"
  70.       ]
  71.         var fsFields
  72.           if (window.location.pathname === "/support/catalog/items/136") {
  73.           fsFields = {
  74.         duration: "requested_item_values_136_requested_item_value_attributes_cf_visit_duration_270753",
  75.         support_with_lunch: "requested_item_values_136_requested_item_value_attributes_cf_support_with_lunch_270753",
  76.         access_week: "requested_item_values_136_requested_item_value_attributes_cf_access_type_270753",
  77.         lunch_type: "requested_item_values_136_requested_item_value_attributes_cf_select_your_meal_preference_270753",
  78.         office: "requested_item_values_136_requested_item_value_attributes_cf_office_270753",
  79.         dates: [
  80.           "requested_item_values_136_requested_item_value_attributes_cf_day1_270753_date",
  81.           "requested_item_values_136_requested_item_value_attributes_cf_day2_270753_date",
  82.           "requested_item_values_136_requested_item_value_attributes_cf_day3_270753_date",
  83.           "requested_item_values_136_requested_item_value_attributes_cf_day4_270753_date",
  84.           "requested_item_values_136_requested_item_value_attributes_cf_day5_270753_date",
  85.           "requested_item_values_136_requested_item_value_attributes_cf_day6_270753_date",
  86.           "requested_item_values_136_requested_item_value_attributes_cf_day7_270753_date"            //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ РЕАЛЬНІЙ РЕКВЕСТ//
  87.         ],
  88.         additional_locations: [
  89.           "requested_item_values_136_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
  90.           "requested_item_values_136_requested_item_value_attributes_cf_additional_location_2_270753"
  91.         ],
  92.         meido: "requested_item_values_136_requested_item_value_attributes_cf_meido_body_270753",
  93.         document_text: "requested_item_values_136_requested_item_value_attributes_cf__270753",
  94.         document_check: "requested_item_values_136_requested_item_value_attributes_cf_v_270753",
  95.         addloc: "",
  96.         addloc_text: ""
  97.       }
  98.           } else if (window.location.pathname === "/support/catalog/items/149") {
  99.           fsFields = {
  100.         duration: "requested_item_values_149_requested_item_value_attributes_cf_visit_duration_270753",
  101.         support_with_lunch: "requested_item_values_149_requested_item_value_attributes_cf_support_with_lunch_270753",
  102.         access_week: "requested_item_values_149_requested_item_value_attributes_cf_access_type_270753",
  103.         lunch_type: "requested_item_values_149_requested_item_value_attributes_cf_select_your_meal_preference_270753",
  104.         office: "requested_item_values_149_requested_item_value_attributes_cf_office_270753",
  105.         dates: [
  106.           "requested_item_values_149_requested_item_value_attributes_cf_day1_270753_date",
  107.           "requested_item_values_149_requested_item_value_attributes_cf_day2_270753_date",
  108.           "requested_item_values_149_requested_item_value_attributes_cf_day3_270753_date",
  109.           "requested_item_values_149_requested_item_value_attributes_cf_day4_270753_date",
  110.           "requested_item_values_149_requested_item_value_attributes_cf_day5_270753_date"              //ДОБАВИТЬ ДОПОЛНИТЕЛЬНІЕ ДНИ - скопировать айдишники каждого поля_ТЕСТОВІЙ РЕКВЕСТ//
  111.         ],
  112.         additional_locations: [
  113.           "requested_item_values_149_requested_item_value_attributes_cf_do_you_plan_to_visit_any_additional_location_during_the_requested_period_nbsp_270753",
  114.           "requested_item_values_149_requested_item_value_attributes_cf_additional_location_2_270753"
  115.         ],
  116.         meido: "requested_item_values_149_requested_item_value_attributes_cf_meido_body_270753",
  117.         document_text: "requested_item_values_149_requested_item_value_attributes_cf__270753",
  118.         document_check: "requested_item_values_149_requested_item_value_attributes_cf_v_270753",
  119.         addloc: "",
  120.         addloc_text: ""
  121.       }
  122.           }
  123.  
  124.       // -------------------------
  125.         var meidoActive
  126.         if (window.location.pathname === "/support/catalog/items/136") {
  127.           meidoActive = false
  128.         } else if (window.location.pathname === "/support/catalog/items/149") {
  129.           meidoActive = true
  130.         }
  131.         meidoToken = "test"
  132.       // -------------------------
  133.  
  134.       // -------------------------
  135.         var capacityActive
  136.         if (window.location.pathname === "/support/catalog/items/136") {
  137.           capacityActive = true                                                              //замсемнить ФОЛс на ТРУ чтоб включить капасити в боевом. реквесте//
  138.         } else if (window.location.pathname === "/support/catalog/items/149") {
  139.           capacityActive = true
  140.         }
  141.       // -------------------------
  142.  
  143.           // ====================================================================
  144.           // ====================================================================
  145.           // ====================================================================
  146.  
  147.       const fsNative = {
  148.         duration: document.getElementById(fsFields.duration),
  149.         support_with_lunch: document.getElementById(fsFields.support_with_lunch).parentNode.childNodes.item(0),
  150.         access_week: document.getElementById(fsFields.access_week),
  151.         lunch_type: document.getElementById(fsFields.lunch_type),
  152.         office: document.getElementById(fsFields.office),
  153.         meido: document.getElementById(fsFields.meido),
  154.         dates: getElemList(fsFields.dates),
  155.         additional_locations: getElemList(fsFields.additional_locations),
  156.         document_text: document.getElementById(fsFields.document_text),
  157.         document_check: document.getElementById(fsFields.document_check).parentNode.childNodes.item(0),
  158.         addloc: document.getElementById(fsFields.addloc),
  159.         addloc_text: document.getElementById(fsFields.addloc_text)
  160.       }
  161.  
  162.       var activeDateCount = 0
  163.       const today = new Date()
  164.       const todayGlobal = today.toLocaleDateString()
  165.       const weekdayGlobal = today.getDay()
  166.       const currentHoursGlobal = today.getHours()
  167.         const currentMinutesGlobal = today.getMinutes()
  168.       var selectedDatesGlobal = []
  169.       var capacityCheck = true
  170.       var additionalLocationInfo = {}
  171.       var addLocationTable
  172.       var lastSelectedOffice
  173.  
  174.       const durationSelector = replaceInputWithDropdown(fsFields.duration, durationList, "duration")
  175.             durationSelector.parentNode.hidden = true
  176.       const officeSelector = replaceInputWithDropdown(fsFields.office, officeList, "office")
  177.       const accessWeekSelector = replaceInputWithDropdown(fsFields.access_week, accessWeek, "access-week")
  178.       const lunchTypeSelector = createSimplifiedDropdown(fsFields.lunch_type, mealTypes, "lunch_type")
  179.       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//
  180.       const lunchCheckbox = createCustomCheckbox(document.getElementById(fsFields.support_with_lunch).parentNode, "show-lunch", lunchCheckboxLabel)
  181.       const dateList = createCustomDates(fsNative.dates)
  182.       const additionalOfficesList = createAdditionalOfficeSelectors(fsFields.additional_locations, officeList)
  183.       const capacityDisplay = createCapacityDisplay(fsNative.dates[0].parentNode.parentNode)
  184.       //--- capacity ---
  185.       if (capacityActive) {
  186.         fsNative.addloc.parentNode.hidden = true
  187.         fsNative.addloc_text.parentNode.hidden = true
  188.         fsNative.additional_locations.forEach(elem => { elem.parentNode.hidden = true })
  189.       }
  190.  
  191.  
  192.           //add hotDeskCheckbox
  193.       const hotdeskCheckboxLabel = document.createTextNode("I don`t have a permanent seat and would like to book a hot desk.");
  194.       const hotdeskCheckboxContainer = document.createElement('div');
  195.       document.getElementById(fsFields.office).parentNode.appendChild(hotdeskCheckboxContainer);
  196.       const hotdeskCheckbox = createCustomCheckbox(hotdeskCheckboxContainer, "show-hotdesk", hotdeskCheckboxLabel);
  197.       hotdeskCheckbox.checked = false;
  198.       const hotdeskText = document.createElement("p");
  199.       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.";
  200.       hotdeskCheckboxContainer.appendChild(hotdeskText);
  201.  
  202.       const documentCheckboxLabel = document.createElement("span")
  203.       documentCheckboxLabel.innerHTML = "Я, {{ current_user.phone }}, ознайомився з документом та підтверджую що мій стан відповідає нормам відвідування офісу згідно з заявою.<br>*[✓] <i>означає, що дана відмітка прирівнюється до власноручного/факсимільного відтворення підпису особи.</i>"
  204.       const documentCheckbox = createCustomCheckbox(fsNative.document_check.parentNode, "document-check", documentCheckboxLabel)
  205.       const documentText = createDocumentSection(fsNative.document_text, todayGlobal)
  206.  
  207.       const dateControlAdd = document.createElement("button")
  208.       dateControlAdd.innerHTML = "+"
  209.       const dateControlRemove = document.createElement("button")
  210.       dateControlRemove.innerHTML = "-"
  211.  
  212.       lunchCheckbox.parentNode.hidden = true;
  213.       lunchTypeSelector.parentNode.hidden = true;
  214.       hotdeskCheckboxContainer.hidden = true;
  215.       hotdeskText.hidden = true;
  216.  
  217.       //durationSelector.addEventListener("change", function(){ renderController() })
  218.       officeSelector.addEventListener("change", function(){ renderController() })
  219.       accessWeekSelector.addEventListener("change", function(){ renderController() })
  220.       lunchCheckbox.addEventListener("change", function(){ renderController() })
  221.       hotdeskCheckbox.addEventListener("change", function(){ renderController() })
  222.       lunchTypeSelector.addEventListener("change", function(){ renderController() })
  223.  
  224.       dateList.forEach(dateElem => {
  225.         jQuery(dateElem).datepicker("option", {
  226.           onSelect: function() {
  227.             renderController()
  228.           }
  229.         })
  230.       })
  231.  
  232.       dateControlAdd.addEventListener("click", function(e){
  233.         e.preventDefault()
  234.         activeDateCount += 1
  235.         renderController()
  236.       })
  237.       dateControlRemove.addEventListener("click", function(e){
  238.         e.preventDefault()
  239.         activeDateCount -= 1
  240.         renderController()
  241.       })
  242.       additionalOfficesList.forEach(elem => {
  243.         elem.addEventListener("change", function(){ renderController() })
  244.       })
  245.  
  246.  
  247.       documentCheckbox.addEventListener("change", function(){ renderController() })
  248.  
  249.       var meidoMenu
  250.       document.getElementById(fsFields.meido).parentNode.style.display = "none"
  251.       if (meidoActive) {
  252.         const elems = document.getElementsByClassName("main pull-left")
  253.         meidoMenu = await meidoInit(elems[0], dateList, fsFields.meido, 125, false)  // change 125 to required limit
  254.         meidoMenu.hidden = true
  255.         renderController()
  256.       } else {
  257.         renderController()
  258.       }
  259.  
  260.       jQuery("input[type=\"submit\"]").each((index, elem) => {
  261.         elem.onclick = function(e){
  262.           if (!capacityCheck) {
  263.             e.stopImmediatePropagation()
  264.             e.preventDefault()
  265.               alert("Please check the capactiy for selected dates")                     //поменять нотифай если нужно!//
  266.           }
  267.         }
  268.       })
  269.  
  270.       function renderController(){
  271.         var values = {
  272.           duration: "Full day",
  273.           office: officeSelector.value,
  274.           access_week: accessWeekSelector.value
  275.         }
  276.  
  277.         fsNative.duration.value = values.duration === "..." ? "" : values.duration
  278.         fsNative.office.value = values.office === "..." ? "" : values.office
  279.  
  280.         if (capacityActive) {
  281.           if (values.office === "...") {
  282.             lastSelectedOffice = values.office
  283.             for (let elem of document.getElementsByClassName("addtable-container")) {
  284.               elem.innerHTML = ""
  285.             }
  286.             additionalLocationInfo = {}
  287.             populateAddLocation()
  288.           }
  289.           if (values.office !== "..." && values.office !== lastSelectedOffice) {
  290.             lastSelectedOffice = values.office
  291.             addLocationTable = buildAddLocationTable(values.office)
  292.             const addTableContainers = document.getElementsByClassName("addtable-container")
  293.             var index = 1
  294.             for (let elem of addTableContainers) {
  295.               elem.innerHTML = ""
  296.               const table = addLocationTable.cloneNode(true)
  297.               console.log(table.querySelectorAll('.add-office-label'))
  298.               for (let elem of table.querySelectorAll('.add-office-label')) {
  299.                 elem.htmlFor = elem.htmlFor + "_" + index
  300.               }
  301.               for (let elem of table.querySelectorAll('.add-office-checkbox')) {
  302.                 elem.id = elem.id + "_" + index
  303.                 elem.onclick = function(){ handleAddLocation(this) }
  304.               }
  305.               ++index
  306.               elem.appendChild(table)
  307.             }
  308.             additionalLocationInfo = {}
  309.             populateAddLocation()
  310.           }
  311.         }
  312.  
  313.         if (fsNative.office.value === 'Toronto') {
  314.           hotdeskCheckboxContainer.hidden = false;
  315.         } else {
  316.           hotdeskCheckbox.checked = false;
  317.           hotdeskCheckboxContainer.hidden = true;
  318.         }
  319.         if (!hotdeskCheckbox.checked) {
  320.           hotdeskText.hidden = true;
  321.         } else {
  322.           hotdeskText.hidden = false;
  323.         }
  324.  
  325.         const accessWeekChanged = fsNative.access_week.value === values.access_week ? false : true
  326.         fsNative.access_week.value = values.access_week === "..." ? "" : values.access_week
  327.         var datesInRequest = dateList.map(x => x.value).filter(x => !!x)
  328.         if (activeDateCount === 0) datesInRequest = datesInRequest[0] ? [datesInRequest[0]] : []
  329.         const today = new Date().toISOString().split("T")[0]
  330.         if (durationList[values.duration] && officeList[values.office] && accessWeek[values.access_week] && datesInRequest.length && !(datesInRequest.length === 1 && datesInRequest[0] === today) && !accessWeekChanged) {
  331.           lunchCheckbox.parentNode.hidden = false
  332.         } else {
  333.           lunchCheckbox.parentNode.hidden = true
  334.           lunchCheckbox.checked = false
  335.         }
  336.  
  337.         values.support_with_lunch = lunchCheckbox.checked
  338.         fsNative.support_with_lunch.value = lunchCheckbox.checked ? "1" : "0"
  339.         if (values.support_with_lunch) {
  340.           if (meidoActive) {
  341.             if (weekdayGlobal === 6 || weekdayGlobal === 0 || (weekdayGlobal === 5 && currentHoursGlobal >= 19 && currentMinutesGlobal >= 30) || values.access_week === "Current week" || !officeMeido[values.office]) {
  342.               lunchTypeSelector.parentNode.hidden = false
  343.               lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
  344.               meidoMenu.hidden = true
  345.             } else {
  346.               lunchTypeSelector.parentNode.hidden = true
  347.               lunchTypeSelector.value = null
  348.               meidoMenu.hidden = false
  349.             }
  350.           } else {
  351.             lunchTypeSelector.parentNode.hidden = false
  352.             lunchTypeSelector.value = lunchTypeSelector.value ? lunchTypeSelector.value : mealTypes[0]
  353.           }
  354.         } else {
  355.           lunchTypeSelector.parentNode.hidden = true
  356.           lunchTypeSelector.value = null
  357.           if (meidoActive) meidoMenu.hidden = true
  358.         }
  359.  
  360.         values.lunch_type = lunchTypeSelector.value
  361.         fsNative.lunch_type.value = values.lunch_type ? values.lunch_type : ""
  362.  
  363.         const dateLimits = (values.access_week === "...") ? null : calcDateLimits(values.access_week === "Current week" ? true : false)
  364.         const dateLimitsRaw = dateLimits ? dateLimits.map(x => new Date(x).valueOf()) : null
  365.         var existingDates = []
  366.         var lastUsedFound = false;
  367.         if (accessWeekChanged) activeDateCount = 0
  368.         dateList.forEach((dateElem, index) => {
  369.           const dateNativeElem = fsNative.dates[index]
  370.           const timeNativeElem = document.getElementById(fsFields.dates[index].substring(0, fsFields.dates[index].length - 4) + "time")
  371.           const errorElem = document.getElementById("date_custom_" + (index+1) + "-error")
  372.           if (errorElem) errorElem.style.display = "none"
  373.           if (accessWeekChanged && index === 0) dateElem.value = null
  374.           const dateRawValue = new Date(dateElem.value).valueOf()
  375.           if (existingDates.includes(dateRawValue)) dateElem.value = null
  376.           if (dateLimits) {
  377.             jQuery("#date_custom_"+(index+1)).datepicker("option", {
  378.               minDate: new Date(dateLimits[0]),
  379.               maxDate: new Date(dateLimits[1])
  380.             })
  381.             dateElem.disabled = false
  382.             if (dateRawValue < dateLimitsRaw[0] || dateRawValue > dateLimitsRaw[1]) dateElem.value = null
  383.           } else {
  384.             dateElem.disabled = true
  385.           }
  386.           existingDates.push(dateRawValue)
  387.           const controlWrapper = document.getElementById("controls_" + index)
  388.           controlWrapper.innerHTML = ""
  389.           const addLocations = document.getElementById("addtable_" + (index+1)).querySelectorAll('.add-office-checkbox')
  390.           if (dateElem.value && dateElem.value !== "") {
  391.             dateNativeElem.value = reverseForFS(dateElem.value)
  392.             timeNativeElem.value = "00:00"
  393.             if (capacityActive) document.getElementById("addtable_wrapper_" + (index+1)).style.display = "block"
  394.           } else {
  395.             dateNativeElem.value = null
  396.             timeNativeElem.value = null
  397.             if (capacityActive) {
  398.               document.getElementById("addtable_wrapper_" + (index+1)).style.display = "none"
  399.               for (let checkbox of addLocations) {
  400.                 checkbox.checked = false
  401.               }
  402.             }
  403.           }
  404.           controlWrapper.style.display = "inline-block"
  405.           if (index < activeDateCount) {
  406.             dateElem.disabled = true
  407.             dateElem.parentNode.style.display = "block"
  408.           } else if (index === activeDateCount) {
  409.             if (dateLimits) dateElem.disabled = false
  410.             if (index > 0 && dateList[index-1].value) {
  411.                     const nextDate = new Date(dateList[index-1].value)
  412.                   nextDate.setDate(nextDate.getDate() + 1)
  413.               jQuery("#date_custom_"+(index+1)).datepicker("option", {
  414.                 minDate: nextDate
  415.               })
  416.                 }
  417.             dateElem.parentNode.style.display = "block"
  418.             if (activeDateCount > 0) controlWrapper.appendChild(dateControlRemove)
  419.             if (activeDateCount < dateList.length-1) {
  420.               controlWrapper.appendChild(dateControlAdd)
  421.               dateControlAdd.disabled = !dateElem.value
  422.             }
  423.           } else {
  424.             dateElem.parentNode.style.display = "none"
  425.             dateElem.value = null
  426.             dateNativeElem.value = null
  427.             timeNativeElem.value = null
  428.           }
  429.         })
  430.  
  431.  
  432.         if (capacityActive === true) {
  433.           const selectedDates = dateList.map(x => x.value).filter(x => !!x)
  434.           for (let date in additionalLocationInfo) {
  435.             if (!selectedDates.includes(date)) delete additionalLocationInfo[date]
  436.           }
  437.           populateAddLocation()
  438.           if (selectedDates.length && JSON.stringify(selectedDates) !== selectedDatesGlobal) {
  439.             fetch(`https://freshservicecounter.ringteam.com/v2/getcapacity?office=${JSON.stringify(officeCapacity)}&dates=${JSON.stringify(selectedDates)}`)
  440.             .then(res => {
  441.               return res.json()
  442.             })
  443.             .then(res => {
  444.             // main capacity
  445.               for (let officeName in res) {
  446.                 if (values.office === officeName) {
  447.                   capacityDisplay.innerHTML = ""
  448.                   const office = document.createElement("div")
  449.                   office.innerHTML = `<b>Office:</b> ${officeName}`
  450.                   const limit = document.createElement("div")
  451.                   limit.innerHTML = `<b>Limit:</b> ${res[officeName].limit} visitors per day`
  452.                   limit.style.borderBottom = "1px dotted grey"
  453.                   capacityDisplay.appendChild(office)
  454.                   capacityDisplay.appendChild(limit)
  455.                   var capacityDataArray = []
  456.                   for (let date in res[officeName].capacity) {
  457.                     capacityDataArray.push({ date: date, capacity: res[officeName].capacity[date] })
  458.                   }
  459.                   capacityDataArray.sort((x,y) => { return x.date > y.date ? 1 : -1 })
  460.                   capacityCheck = true
  461.                   capacityDataArray.forEach(obj => {
  462.                     const dateElem = document.createElement("div")
  463.                     dateElem.innerHTML = `<b>${obj.date}:</b> ${obj.capacity} visitors confirmed`
  464.                     //console.log(obj.capacity, res.limit)
  465.                     if (obj.capacity / res[officeName].limit >= 0.7) dateElem.style.color = "orange"
  466.                     if (obj.capacity >= res[officeName].limit) {
  467.                       dateElem.style.color = "red"
  468.                       capacityCheck = false
  469.                     }
  470.                     capacityDisplay.appendChild(dateElem)
  471.                   })
  472.                       capacityDisplay.hidden = false
  473.                 } else {
  474.                   //additional capacity
  475.                   dateList.forEach(dateElem => {
  476.                     var elem = dateElem.parentNode.getElementsByClassName("capacity_" + officeName)[0]
  477.                     elem.innerHTML = `${res[officeName].capacity[dateElem.value]}/${res[officeName].limit} confirmed`
  478.                   })
  479.                 }
  480.               }
  481.             })
  482.           } else {
  483.             capacityDisplay.hidden = true
  484.             capacityCheck = capacityDisplay.hidden
  485.           }
  486.             selectedDatesGlobal = JSON.stringify(selectedDates)
  487.         }
  488.  
  489.         if (meidoActive && values.access_week === "Next week") {
  490.           meidoCart.calcDateCollection()
  491.         } else {
  492.               fsNative.meido.innerHTML = null
  493.         }
  494.  
  495.         values.additional_offices = []
  496.         additionalOfficesList.forEach((elem, index) => {
  497.           values.additional_offices.push(elem.value)
  498.           if ((index === 0 && values.office !== "...") || (index > 0 && values.additional_offices[index-1] !== "...")) {
  499.             elem.parentNode.style.display = "block"
  500.           } else {
  501.             elem.parentNode.style.display = "none"
  502.             elem.value = "..."
  503.           }
  504.           fsNative.additional_locations[index].value = elem.value === "..." ? null : elem.value
  505.         })
  506.  
  507.         values.document_check = documentCheckbox.checked
  508.         fsNative.document_check.value = documentCheckbox.checked ? "1" : "0"
  509.         fsNative.document_check.checked = documentCheckbox.checked
  510.         const documentLocations = [values.office, values.additional_offices].flat().map(x => officeAddress[x]).filter(x => !!x).join(", ")
  511.         document.getElementById("doc-address").innerHTML = documentLocations
  512.         // =================================================
  513.         var text = `Заява на допуск до користування Простором Товариства з обмеженою відповідальністю «ТекХостинг» (далі – ТОВ «ТекХостинг»)
  514.  
  515. Я, фізична особа-підприємець ${"{{ current_user.phone }}"}, прошу допустити мене до користування офісним простором ТОВ «ТекХостинг» (далі – Простір), що знаходиться за адресою: ${documentLocations}.
  516.  
  517.  
  518. Я підтверджую, що на момент надання мені доступу до користування Простором:
  519.  
  520. • у мене відсутні будь-які ознаки ГРВІ, а саме: підвищена температура тіла (більше 37,2 С), кашель, утруднене дихання тощо;
  521. • я ознайомлений(а) з рекомендаціями МОЗ та ВООЗ щодо попередження зараження COVID-19 та їх дотримуюсь;
  522. • протягом останніх 14 днів я не перебував(ла) за межами України та не контактував(ла) з особами, щодо яких наявна підозра/хворими на COVID-19.
  523.  
  524. Я зобов’язуюсь під час користування Простором дотримуватися посилених санітарно-гігієнічних норм, а також рекомендацій МОЗ та ВООЗ щодо запобігання поширенню COVID-19, а саме:
  525.  
  526. • носити медичну маску/респіратор;
  527. • ретельно мити руки з милом протягом 20-40 сек. та регулярно обробляти їх антисептичним засобом під час перебування в Просторі;
  528. • дотримуватися дистанції min 1,5 (півтора) метри від інших відвідувачів Простору.
  529.  
  530. Дата: ${todayGlobal}`
  531.         // =================================================
  532.         fsNative.document_text.value = text
  533.       }
  534.  
  535.       function buildAddLocationTable(excluded){
  536.         const table = document.createElement('table')
  537.         table.style.margin = "10px"
  538.         const row = document.createElement('tr')
  539.         row.style.width = "800px"
  540.         row.style.display = "block"
  541.         table.appendChild(row)
  542.         var cellCount = 0
  543.         for (let office in officeList) {
  544.           if (office !== "..." && office !== excluded) {
  545.             var currentRow
  546.             if (cellCount <= 2) {
  547.               currentRow = table.childNodes[table.childNodes.length - 1]
  548.               ++cellCount
  549.             } else {
  550.               currentRow = document.createElement('tr')
  551.               table.appendChild(currentRow)
  552.               cellCount = 1
  553.             }
  554.             const cell = document.createElement('td')
  555.             cell.style.display = "inline-flex"
  556.             const label = document.createElement('label')
  557.             label.htmlFor = office
  558.             label.className += "add-office-label"
  559.             label.innerHTML = office
  560.             const checkbox = document.createElement('input')
  561.             checkbox.type = "checkbox"
  562.             checkbox.id = office
  563.             checkbox.className += "add-office-checkbox"
  564.               //checkbox.style.display = "inline-block"
  565.             checkbox.style.marginRight = "5px"
  566.             const capacity = document.createElement('span')
  567.             capacity.className += "capacity_" + office
  568.               //capacity.style.display = "inline-block"
  569.             capacity.style.marginLeft = "10px"
  570.  
  571.             cell.appendChild(checkbox)
  572.             cell.appendChild(label)
  573.             cell.appendChild(capacity)
  574.             cell.style.width = "33%"
  575.             currentRow.appendChild(cell)
  576.           }
  577.         }
  578.         return table
  579.       }
  580.  
  581.       function handleAddLocation(elem){
  582.         console.log('called')
  583.         console.log(elem)
  584.         const dateId = elem.id[elem.id.length - 1]
  585.         console.log(dateId)
  586.         const locationName = elem.id.substring(0, elem.id.length - 2)
  587.         console.log(locationName)
  588.         const dateElem = document.getElementById("date_custom_" + dateId)
  589.         console.log(dateElem.value)
  590.         if (elem.checked) {
  591.           if (!additionalLocationInfo[dateElem.value]) additionalLocationInfo[dateElem.value] = []
  592.           additionalLocationInfo[dateElem.value].push(locationName)
  593.         } else {
  594.           const removed = additionalLocationInfo[dateElem.value].splice(additionalLocationInfo[dateElem.value].indexOf(locationName), 1)
  595.           console.log(removed)
  596.           console.log(additionalLocationInfo[dateElem.value])
  597.           if (!additionalLocationInfo[dateElem.value].length) delete additionalLocationInfo[dateElem.value]
  598.         }
  599.         console.log(additionalLocationInfo)
  600.         populateAddLocation()
  601.       }
  602.  
  603.       function populateAddLocation(){
  604.         fsNative.addloc.innerHTML = JSON.stringify(additionalLocationInfo)
  605.         var text = []
  606.         for (let date in additionalLocationInfo) {
  607.           text.push(`${date}: ${additionalLocationInfo[date].join(", ")}`)
  608.         }
  609.         fsNative.addloc_text.innerHTML = text.join("; \n")
  610.       }
  611.     }
  612.  
  613.     // ========== END OF WFO ==========
  614.  
  615.     if (window.location.pathname === "/support/catalog/items/139") {
  616.       const fsFields = {
  617.         from: "requested_item_values_139_requested_item_value_attributes_cf_from_270753",
  618.         to: "requested_item_values_139_requested_item_value_attributes_cf_to_270753",
  619.         country: "requested_item_values_139_requested_item_value_attributes_cf_country_270753"
  620.       }
  621.  
  622.       const countryBlacklist = [
  623.         "Afghanistan",
  624.         "Belarus",
  625.         "Burundi",
  626.         "Central African Republic",
  627.         "China",
  628.         "Côte d'Ivoire",
  629.         "Lebanon"
  630.       ]
  631.  
  632.       // =====================================================
  633.  
  634.       const fsNative = {
  635.         dates: [
  636.           {
  637.             date: document.getElementById(fsFields.from + "_date"),
  638.             time: document.getElementById(fsFields.from + "_time")
  639.           },
  640.           {
  641.             date: document.getElementById(fsFields.to + "_date"),
  642.             time: document.getElementById(fsFields.to + "_time")
  643.           }
  644.         ],
  645.         country: document.getElementById(fsFields.country)
  646.       }
  647.  
  648. const countryDropdown = createSimplifiedDropdown(fsFields.country, [], "country")
  649.       countryDropdown.addEventListener("change", function(){ renderController() })
  650.  
  651.       countriesGlobal.forEach(country => {
  652.         if (!countryBlacklist.includes(country)) {
  653.           const option = document.createElement("option")
  654.           option.innerHTML = country
  655.           option.value = country
  656.           countryDropdown.appendChild(option)
  657.         }
  658.       })
  659.       const dateList = createCustomDates(fsNative.dates.map(x => x.date))
  660.       const minDate = new Date()
  661.       minDate.setDate(minDate.getDate() + 14)
  662.  
  663.       dateList.forEach(dateElem => {
  664.         dateElem.parentNode.style.display = "block"
  665.         jQuery(dateElem).datepicker("option", {
  666.           onSelect: function() {
  667.             renderController()
  668.           },
  669.           minDate: minDate
  670.         })
  671.       })
  672.  
  673.       renderController()
  674.  
  675.       function renderController(){
  676.         dateList.forEach((dateElem, index) => {
  677.           if (dateElem.value) {
  678.             fsNative.dates[index].date.value = reverseForFS(dateElem.value)
  679.             fsNative.dates[index].time.value = "00:00"
  680.           } else {
  681.             fsNative.dates[index].date.value = null
  682.             fsNative.dates[index].time.value = null
  683.           }
  684.         })
  685.           fsNative.country.value = countryDropdown.value
  686.       }
  687.     }
  688.  
  689.     if (window.location.pathname === "/support/catalog/items/148") {
  690.       console.log("dates init")
  691.       const fsFields = {
  692.         dates: [
  693.           "requested_item_values_148_requested_item_value_attributes_cf_day1_270753",
  694.           "requested_item_values_148_requested_item_value_attributes_cf_day2_270753",
  695.           "requested_item_values_148_requested_item_value_attributes_cf_day3_270753",
  696.           "requested_item_values_148_requested_item_value_attributes_cf_day4_270753",
  697.           "requested_item_values_148_requested_item_value_attributes_cf_day5_270753"
  698.         ]
  699.       }
  700.       //==============================================================================
  701.       const fsNative = {
  702.         dates: getElemList(fsFields.dates)
  703.       }
  704.       var activeDateCount = 0
  705.       const dateList = createCustomDates(fsFields.dates.map(x => document.getElementById(x+"_date")))
  706.       const today = new Date()
  707.       const max = new Date()
  708.       max.setDate(max.getDate() + 7 + (today.getDay() === 0 ? 0 : 7 - today.getDay()))
  709.       dateList.forEach(dateElem => {
  710.         jQuery(dateElem).datepicker("option", {
  711.           onSelect: function() {
  712.             renderController()
  713.           },
  714.           minDate: today,
  715.           maxDate: max
  716.         })
  717.       })
  718.       const dateControlAdd = document.createElement("button")
  719.       dateControlAdd.innerHTML = "+"
  720.       const dateControlRemove = document.createElement("button")
  721.       dateControlRemove.innerHTML = "-"
  722.       dateControlAdd.addEventListener("click", function(e){
  723.         e.preventDefault()
  724.         activeDateCount += 1
  725.         renderController()
  726.       })
  727.       dateControlRemove.addEventListener("click", function(e){
  728.         e.preventDefault()
  729.         activeDateCount -= 1
  730.         renderController()
  731.       })
  732.  
  733.       renderController()
  734.  
  735.       function renderController(){
  736.         dateList.forEach((dateElem, index) => {
  737.           const date = document.getElementById(fsFields.dates[index] + "_date")
  738.           const time = document.getElementById(fsFields.dates[index] + "_time")
  739.           const errorElem = document.getElementById("date_custom_" + (index+1) + "-error")
  740.           if (errorElem) errorElem.style.display = "none"
  741.           if (dateElem.value) {
  742.             date.value = reverseForFS(dateElem.value)
  743.             time.value = "00:00"
  744.           } else {
  745.             date.value = null
  746.             time.value = null
  747.           }
  748.           const controlWrapper = document.getElementById("controls_" + index)
  749.           controlWrapper.innerHTML = ""
  750.           controlWrapper.style.display = "inline"
  751.           if (index < activeDateCount) {
  752.             dateElem.disabled = true
  753.             dateElem.parentNode.style.display = "block"
  754.           } else if (index === activeDateCount) {
  755.             dateElem.disabled = false
  756.             if (index > 0 && dateList[index-1].value) {
  757.               const nextDate = new Date(dateList[index-1].value)
  758.               nextDate.setDate(nextDate.getDate() + 1)
  759.               jQuery("#date_custom_"+(index+1)).datepicker("option", {
  760.                 minDate: nextDate
  761.               })
  762.             }
  763.             dateElem.parentNode.style.display = "block"
  764.             if (activeDateCount > 0) controlWrapper.appendChild(dateControlRemove)
  765.             if (activeDateCount < dateList.length-1) {
  766.               controlWrapper.appendChild(dateControlAdd)
  767.               dateControlAdd.disabled = !dateElem.value
  768.             }
  769.           } else {
  770.             dateElem.parentNode.style.display = "none"
  771.             dateElem.value = null
  772.             date.value = null
  773.             time.value = null
  774.           }
  775.         })
  776.       }
  777.     }
  778.  
  779.       // hoodie//
  780.       if (window.location.pathname === "/support/catalog/items/174") {
  781.       const fsFields = {
  782.         item: "requested_item_values_174_requested_item_value_attributes_cf_hoodie_options_270753"
  783.       }
  784.       const itemList = {
  785.         "Hoodie black: front logo": "https://squad-photo.s3.eu-north-1.amazonaws.com/hoodie/hoodie-black-with-front-logo.png",
  786.         "Hoodie black: front+arm logo": "https://squad-photo.s3.eu-north-1.amazonaws.com/hoodie/hoodie-black-with-front-arm-logo.png",
  787.         "Hoodie black: front+back logo": "https://squad-photo.s3.eu-north-1.amazonaws.com/hoodie/hoodie-black-with-front-and-back-logo.png",
  788.         "Hoodie khaki": "https://squad-photo.s3.eu-north-1.amazonaws.com/hoodie/hoodie-khaki.png"
  789.       }
  790.       // ===============================================
  791.       const fsNative = {
  792.         item: document.getElementById(fsFields.item)
  793.       }
  794.           fsNative.item.style.display = "none"
  795.  
  796.       const itemContainer = document.createElement("div")
  797.       itemContainer.style.width = "100%"
  798.       for (let itemName in itemList) {
  799.         const container = document.createElement("div")
  800.         const radio = document.createElement("input")
  801.         radio.type = "radio"
  802.         radio.name = "item"
  803.         radio.value = itemName
  804.         radio.id = itemName
  805.         const label = document.createElement("label")
  806.         label.htmlFor = itemName
  807.         label.style.display = "inline"
  808.         const img = document.createElement("img")
  809.         img.src = itemList[itemName]
  810.         img.style.width = "400px"
  811.         img.style.border = "1px solid lightgrey"
  812.         img.style.margin = "5px"
  813.  
  814.         label.appendChild(img)
  815.         container.appendChild(radio)
  816.         container.appendChild(label)
  817.  
  818.         itemContainer.appendChild(container)
  819.  
  820.         radio.onchange = function(){ renderController(this) }
  821.       }
  822.       fsNative.item.parentNode.appendChild(itemContainer)
  823.  
  824.       function renderController(context){
  825.         fsNative.item.value = context.value
  826.       }
  827.     }
  828.  
  829.       const poshtaRequestList = [32]
  830.     const currentRequestId = window.location.pathname.split("/").slice(-1)[0]
  831.         const langPattern = /[а-яА-ЯЬьЮюЯяЇїІіЄєҐґ.,-\/0-9 \b\+\)\(]/
  832.     if (poshtaRequestList.includes(parseInt(currentRequestId))) {
  833.       const fsFields = {
  834.         32: {
  835.           dropdown: "requested_item_values_120_requested_item_value_attributes_cf_delivery_type_270753",
  836.           address: {
  837.             region: "requested_item_values_120_requested_item_value_attributes_cf_region_270753",
  838.             city: "requested_item_values_120_requested_item_value_attributes_cf_city_270753",
  839.             district: "requested_item_values_120_requested_item_value_attributes_cf_district_270753",
  840.             street: "requested_item_values_120_requested_item_value_attributes_cf_street_name_270753",
  841.             building: "requested_item_values_120_requested_item_value_attributes_cf_building_270753",
  842.             apartment: "requested_item_values_120_requested_item_value_attributes_cf_apartment_270753",
  843.             receiver: 'requested_item_values_120_requested_item_value_attributes_cf_receiver_270753',
  844.             phone: 'requested_item_values_120_requested_item_value_attributes_cf_phone_number_270753'
  845.           },
  846.           pickup: {
  847.             receiver: "requested_item_values_120_requested_item_value_attributes_cf_receiver_1_270753",
  848.             phone: "requested_item_values_120_requested_item_value_attributes_cf_phone_number_1_380501234567_270753",
  849.             city: "requested_item_values_120_requested_item_value_attributes_cf_city_1_270753",
  850.             location: "requested_item_values_120_requested_item_value_attributes_cf_novaposhta_office_1_270753"
  851.           },
  852.           dropdown_options: [
  853.             "...",
  854.             "Address delivery",
  855.             "Delivery to NovaPoshta office",
  856.             "Pick up at the Toronto office",
  857.             "Pick up at the Community office",
  858.             "Pick up at the Lviv office",
  859.             "Courier delivery to the Lab 72/1",
  860.             "Courier delivery to the Lab 72",
  861.             "Courier delivery to the Lab 64"
  862.           ]
  863.         }
  864.       }
  865.       // =============================================================================================================
  866.       // =============================================================================================================
  867.       // =============================================================================================================
  868.       var fsNative = {
  869.         dropdown: document.getElementById(fsFields[currentRequestId].dropdown),
  870.         address: {},
  871.         pickup: {}
  872.       }
  873.       var fsCustom = {
  874.         dropdown: createSimplifiedDropdown(fsFields[currentRequestId].dropdown, fsFields[currentRequestId].dropdown_options),
  875.         address: {},
  876.         pickup: {}
  877.       }
  878.       fsCustom.dropdown.onchange = function(){ renderController() }
  879.       for (let key in fsFields[currentRequestId].address) {
  880.         fsNative.address[key] = document.getElementById(fsFields[currentRequestId].address[key])
  881.         fsCustom.address[key] = createInputWithRestrictions(fsNative.address[key], langPattern)
  882.         fsCustom.address[key].onkeydown = function(e){
  883.           if (langPattern.test(e.key) || e.key === "Backspace") {
  884.             renderController(fsNative.address[key], e.key)
  885.           } else {
  886.             return false
  887.           }
  888.         }
  889.       }
  890.       for (let key in fsFields[currentRequestId].pickup) {
  891.         fsNative.pickup[key] = document.getElementById(fsFields[currentRequestId].pickup[key])
  892.         fsCustom.pickup[key] = createInputWithRestrictions(fsNative.pickup[key], langPattern)
  893.         fsCustom.pickup[key].onkeydown = function(e){
  894.           if (langPattern.test(e.key)) {
  895.             renderController(fsNative.pickup[key], e.key)
  896.           } else {
  897.             return false
  898.           }
  899.         }
  900.       }
  901.  
  902.       renderController()
  903.  
  904.       function renderController(elem, key){
  905.         //console.log(elem, key)
  906.         //console.log('test')
  907.         fsNative.dropdown.value = fsCustom.dropdown.value === "..." ? "" : fsCustom.dropdown.value
  908.         if (fsCustom.dropdown.value === 'Address delivery') {
  909.           for (let key in fsCustom.address) {
  910.             fsCustom.address[key].parentNode.hidden = false
  911.             fsNative.address[key].value = fsCustom.address[key].value
  912.           }
  913.           for (let key in fsCustom.pickup) {
  914.             fsCustom.pickup[key].value = ""
  915.             fsNative.pickup[key].value = ""
  916.             fsCustom.pickup[key].parentNode.hidden = true
  917.           }
  918.         } else if (fsCustom.dropdown.value === 'Delivery to NovaPoshta office') {
  919.           for (let key in fsCustom.pickup) {
  920.             fsCustom.pickup[key].parentNode.hidden = false
  921.             fsNative.pickup[key].value = fsCustom.pickup[key].value
  922.           }
  923.           for (let key in fsCustom.address) {
  924.             fsCustom.address[key].value = ""
  925.             fsNative.address[key].value = ""
  926.             fsCustom.address[key].parentNode.hidden = true
  927.           }
  928.         } else {
  929.           for (let key in fsCustom.address) {
  930.             fsCustom.address[key].value = ""
  931.             fsNative.address[key].value = ""
  932.             fsCustom.address[key].parentNode.hidden = true
  933.           }
  934.           for (let key in fsCustom.pickup) {
  935.             fsCustom.pickup[key].value = ""
  936.             fsNative.pickup[key].value = ""
  937.             fsCustom.pickup[key].parentNode.hidden = true
  938.           }
  939.         }
  940.         if (elem && key) {
  941.           console.log(key)
  942.           if (key === "Backspace") {
  943.             console.log(elem.value.slice(0, -1))
  944.             elem.value = elem.value.slice(0, -1)
  945.           } else {
  946.             if (langPattern.test(key)) elem.value += key
  947.           }
  948.         }
  949.       }
  950.     }
  951.   if (/\/support\/tickets\/\d*/.test(window.location.pathname)) {                // INVENTORY//
  952.       console.log(jQuery('.item-name').text())
  953.  
  954.       const itemName = "Annual Asset check"      // if need to rename//
  955.       const rawDataFieldName = "Raw_data"
  956.  
  957.       console.log(jQuery('.item-name').text() === itemName, itemName, jQuery('.item-name').text())
  958.         if (jQuery('.item-name').text() === itemName) {
  959.         console.log('start')
  960.         jQuery('.redactor_box').hide()
  961.         jQuery('.control-group').hide()
  962.         const commentNative = jQuery('.redactor_editor p')
  963.  
  964.         console.log('ELEM PROBING')
  965.         const rawDataElem = jQuery(`[for=${rawDataFieldName}]`).parent()
  966.         const rawDataText = rawDataElem.find("pre").text()
  967.         const rawData = JSON.parse(rawDataText)
  968.         console.log(rawData)
  969.  
  970.         console.log('rendering items for requester')
  971.         renderItemList(rawData)
  972.  
  973.         const replyTable = createReplyTable(rawData)
  974.         jQuery('.redactor_box').parent().append(replyTable)
  975.  
  976.         const replies = jQuery('.p-desc')
  977.         replies.each((i,x) => {
  978.           if (i !== 0) {
  979.             try {
  980.               const child = jQuery(x).children('div')
  981.               JSON.parse(child.text())
  982.               child.css({
  983.                 "font-size": "14px",
  984.                 "font-family": '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif'
  985.               })
  986.               child.html('Thank you! Your reply has been submitted.')
  987.             } catch(e) { null }
  988.           }
  989.         })
  990.  
  991.         function createReplyTable(data){
  992.           const table = document.createElement("table")
  993.           rawData.forEach(item => {
  994.             const row = document.createElement("tr")
  995.             row.id = item.asset_tag
  996.             const itemName = document.createElement("td")
  997.             itemName.innerHTML = item.display_name
  998.             itemName.style.fontWeight = "bold"
  999.             itemName.style.margin = "5px"
  1000.             itemName.style.textAlign = "right"
  1001.             const isConfirmed = document.createElement("td")
  1002.             const checkbox = document.createElement("input")
  1003.             checkbox.type = "checkbox"
  1004.             checkbox.id = "check_" + item.asset_tag
  1005.             checkbox.onchange = function(){ renderController() }
  1006.             const label = document.createElement("label")
  1007.             label.htmlFor = "check_" + item.asset_tag
  1008.             label.innerHTML = "Confirm"
  1009.             label.style.margin = "5px"
  1010.             label.style.display = "inline"
  1011.             isConfirmed.appendChild(label)
  1012.             isConfirmed.appendChild(checkbox)
  1013.             const comment = document.createElement("td")
  1014.             const commentInput = document.createElement("textarea")
  1015.             commentInput.id = "comment_" + item.asset_tag
  1016.             commentInput.style.marginLeft = "10px"
  1017.             commentInput.onkeyup = function(){ renderController() }
  1018.             comment.appendChild(commentInput)
  1019.             row.appendChild(itemName)
  1020.             row.appendChild(isConfirmed)
  1021.             row.appendChild(comment)
  1022.             table.appendChild(row)
  1023.           })
  1024.           return table
  1025.         }
  1026.  
  1027.         function renderItemList(itemList){
  1028.           var parsedItems = []
  1029.           itemList.forEach(item => {
  1030.             var text = `<b>Display name:</b> ${item.display_name}<br>
  1031. <b>Asset type:</b> ${item.asset_type}<br>
  1032. <b>Asset tag:</b> ${item.asset_tag}<br>
  1033. <b>Serial number:</b> ${item.serial_number}<br>
  1034. <b>Finance name:</b> ${item.finance_name}<br>`
  1035.             parsedItems.push(text)
  1036.           })
  1037.           rawDataElem.html(parsedItems.join("<br>"))
  1038.         }
  1039.  
  1040.         function renderController(){
  1041.           var replyData = []
  1042.           rawData.forEach(item => {
  1043.             var replyItem = item
  1044.             replyItem.is_confirmed = document.getElementById("check_" + item.asset_tag).checked
  1045.             replyItem.comment = document.getElementById("comment_" + item.asset_tag).value
  1046.             replyData.push(replyItem)
  1047.           })
  1048.           commentNative.html(JSON.stringify(replyData))
  1049.         }
  1050.       }
  1051.     }
  1052.   })
  1053.  
  1054.   function replaceInputWithDropdown(targetId, dataset, facsId = null){
  1055.     const nativeContainer = document.getElementById(targetId).parentNode
  1056.     document.getElementById(targetId).style.display = "none"
  1057.     const selector = document.createElement("select")
  1058.     selector.id = facsId
  1059.     for (let optionName in dataset) {
  1060.       const option = document.createElement("option")
  1061.       option.innerHTML = optionName
  1062.       option.value = optionName
  1063.       selector.appendChild(option)
  1064.     }
  1065.     nativeContainer.appendChild(selector)
  1066.     return selector
  1067.   }
  1068.  
  1069.   function createSimplifiedDropdown(targetId, dataset, facsId = null){
  1070.     const nativeContainer = document.getElementById(targetId).parentNode
  1071.     document.getElementById(targetId).style.display = "none"
  1072.     const selector = document.createElement("select")
  1073.     selector.id = facsId
  1074.     dataset.forEach(optionName => {
  1075.       const option = document.createElement("option")
  1076.       option.innerHTML = optionName
  1077.       option.value = optionName
  1078.       selector.appendChild(option)
  1079.     })
  1080.     nativeContainer.appendChild(selector)
  1081.     return selector
  1082.   }
  1083.  
  1084.   function createCustomCheckbox(container, id, labelText){
  1085.     container.childNodes.forEach(elem => {
  1086.       elem.style.display = "none"
  1087.     })
  1088.     const checkboxWrapper = document.createElement("div")
  1089.     const checkbox = document.createElement("input")
  1090.     checkbox.type = "checkbox"
  1091.     checkbox.id = id
  1092.     const checkboxLabel = document.createElement("label")
  1093.     checkboxLabel.htmlFor = id
  1094.     checkboxLabel.style.display = "inline"
  1095.     checkboxLabel.style.marginLeft = "5px"
  1096.     checkboxLabel.appendChild(labelText)
  1097.     checkboxWrapper.appendChild(checkbox)
  1098.     checkboxWrapper.appendChild(checkboxLabel)
  1099.     container.appendChild(checkboxWrapper)
  1100.     return checkbox
  1101.   }
  1102.  
  1103.   function createCustomDates(nativeList){
  1104.     var customDateCollection = []
  1105.     nativeList.forEach((dateNativeField, index) => {
  1106.       dateNativeField.parentNode.style.display = "none"
  1107.       const dateField = document.createElement("input")
  1108.       const elemId = "date_custom_" + (index + 1)
  1109.       dateField.id = elemId
  1110.       const controlWrapper = document.createElement("span")
  1111.       controlWrapper.id = "controls_" + index
  1112.       controlWrapper.style.marginLeft = "5px"
  1113.       controlWrapper.style.minWidth = "50px"
  1114.       controlWrapper.style.display = "inline-block"
  1115.  
  1116.       const addLocationWrapper = document.createElement("div")
  1117.       addLocationWrapper.id = "addtable_wrapper_" + (index+1)
  1118.       const addLocationHeader = document.createElement("div")
  1119.       addLocationHeader.style.textColor = "lightgrey"
  1120.       addLocationHeader.style.fontSize = "16px"
  1121.       const addLocationArrow = document.createElement("span")
  1122.       addLocationHeader.appendChild(addLocationArrow)
  1123.       addLocationArrow.innerHTML = "►"
  1124.       addLocationHeader.innerHTML += "Select additional locations"
  1125.       const addLocationTableContainer = document.createElement("div")
  1126.       addLocationTableContainer.id = "addtable_" + (index+1)
  1127.       addLocationTableContainer.className += "addtable-container"
  1128.       jQuery(addLocationTableContainer).hide()
  1129.       addLocationHeader.onclick = function(){
  1130.         console.log(addLocationArrow.innerHTML, addLocationArrow.innerHTML === "►")
  1131.         addLocationArrow.innerHTML = (addLocationArrow.innerHTML === "►") ? "▼" : "►"
  1132.         jQuery(addLocationTableContainer).toggle(200)
  1133.       }
  1134.       addLocationWrapper.appendChild(addLocationHeader)
  1135.       addLocationWrapper.appendChild(addLocationTableContainer)
  1136.  
  1137.       dateNativeField.parentNode.parentNode.append(dateField)
  1138.       dateNativeField.parentNode.parentNode.append(controlWrapper)
  1139.       dateNativeField.parentNode.parentNode.append(addLocationWrapper)
  1140.       if (index > 0) dateNativeField.parentNode.parentNode.style.display = "none"
  1141.       customDateCollection.push(dateField)
  1142.       jQuery("#"+elemId).datepicker({
  1143.         dateFormat: "yy-mm-dd",
  1144.         firstDay: 1
  1145.       })
  1146.     })
  1147.     return customDateCollection
  1148.   }
  1149.  
  1150.     function createInputWithRestrictions(elem, pattern){
  1151.   const parent = elem.parentNode
  1152.   const input = document.createElement("input")
  1153.   if (pattern) input.pattern = pattern
  1154.   elem.style.display = "none"
  1155.   parent.appendChild(input)
  1156.   return input
  1157. }
  1158.  
  1159.   function createDocumentSection(target, todayGlobal){
  1160.     target.parentNode.childNodes.forEach(node => {
  1161.       node.style.display = "none"
  1162.     })
  1163.     const documentTextWrapper = document.createElement("div")
  1164.     const documentTextHeader = document.createElement("div")
  1165.     documentTextHeader.style.fontSize = "16px"
  1166.     const headerArrow = document.createElement("span")
  1167.     headerArrow.innerHTML = "▼"
  1168.     const headerTitle = document.createElement("span")
  1169.     headerTitle.innerHTML = "Текст документа (click to view)"
  1170.     documentTextHeader.appendChild(headerArrow)
  1171.     documentTextHeader.appendChild(headerTitle)
  1172.     const documentTextContent = document.createElement("div")
  1173.     documentTextHeader.onclick = function(){
  1174.       documentTextContent.hidden = !documentTextContent.hidden
  1175.       headerArrow.innerHTML = (headerArrow.innerHTML === "►" ? "▼" : "►")
  1176.     }
  1177.     documentTextContent.style.width = "600px"
  1178.     documentTextContent.style.margin = "15px"
  1179.     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>')
  1180.     documentTextContent.hidden = true
  1181.     documentTextWrapper.appendChild(documentTextHeader)
  1182.     documentTextWrapper.appendChild(documentTextContent)
  1183.     target.parentNode.appendChild(documentTextWrapper)
  1184.     return documentTextContent
  1185.   }
  1186.  
  1187.   function createAdditionalOfficeSelectors(ids, datalist){
  1188.     var list = []
  1189.     ids.forEach((id, index) => {
  1190.       const newID = "additional_office_" + (index+1)
  1191.       const selector = replaceInputWithDropdown(id, datalist, newID)
  1192.       selector.parentNode.style.display = "none"
  1193.       if (index > 0) selector.parentNode.childNodes.item("LABEL").style.display = "none"
  1194.       list.push(selector)
  1195.     })
  1196.     return list
  1197.   }
  1198.  
  1199.   function calcDateLimits(thisWeek){
  1200.     const nowDate = new Date()
  1201.     var limits = []
  1202.     if (thisWeek) {
  1203.       const dateMin = nowDate.toISOString().split("T")[0]
  1204.       const nowWeekDay = nowDate.getDay()
  1205.       const daysToAdd = !nowWeekDay ? 0 : 7 - nowWeekDay
  1206.       nowDate.setDate(nowDate.getDate() + daysToAdd)
  1207.       const dateMax = nowDate.toISOString().split("T")[0]
  1208.       limits.push(dateMin)
  1209.       limits.push(dateMax)
  1210.     } else {
  1211.       const nowWeekDay = nowDate.getDay()
  1212.       const daysToAdd = !nowWeekDay ? 1 : 7 - nowWeekDay + 1
  1213.       nowDate.setDate(nowDate.getDate() + daysToAdd)
  1214.       const dateMin = nowDate.toISOString().split("T")[0]
  1215.       nowDate.setDate(nowDate.getDate() + 6)
  1216.       const dateMax = nowDate.toISOString().split("T")[0]
  1217.       limits.push(dateMin)
  1218.       limits.push(dateMax)
  1219.     }
  1220.     return limits
  1221.   }
  1222.  
  1223.   function reverseForFS(date){
  1224.     if (!date) return null
  1225.     const vals = date.split("-")
  1226.     //return `${vals[2]}-${vals[1]}-${vals[0]}`
  1227.     return vals[2]+"-"+vals[1]+"-"+vals[0]
  1228.   }
  1229.  
  1230.   function getElemList(idList){
  1231.     var collection = []
  1232.     idList.forEach(id => {
  1233.       collection.push(document.getElementById(id))
  1234.     })
  1235.     return collection
  1236.   }
  1237.  
  1238.     function createCapacityDisplay(nextElement){
  1239.     const wrapper = document.createElement("div")
  1240.     wrapper.style.border = "3px solid #70c9e9"
  1241.     wrapper.style.minHeight = "100px"
  1242.     wrapper.style.width = "250px"
  1243.     wrapper.style.margin = "5px 0px 5px 0px"
  1244.     wrapper.style.padding = "5px"
  1245.     const mainWrapper = nextElement.parentNode
  1246.     mainWrapper.insertBefore(wrapper, nextElement)
  1247.     wrapper.hidden = true
  1248.     return wrapper
  1249.   }
  1250.   // ==================== MEIDO ====================
  1251.  
  1252.  class MeidoCart{
  1253.   constructor(itemList, limit, cartElem, dateElemsCollection, fsMeidoField, reverseDate){
  1254.     console.log('constructing')
  1255.     this.itemList = itemList
  1256.     this.dailyLimit = limit
  1257.     //this.renderElementId = elemId
  1258.     this.renderTarget = cartElem
  1259.     this.reverseDate = reverseDate
  1260.     this.targetField = fsMeidoField
  1261.     this.dateElemsCollection = dateElemsCollection
  1262.     console.log(this.dateElemsCollection)
  1263.     this.dateCollection = null
  1264.     this.selectedRadio = null
  1265.  
  1266.     this.dateElemsCollection.forEach(dateElem => {
  1267.       dateElem.onchange = function(){
  1268.         this.calcDateCollection()
  1269.         this.render()
  1270.       }
  1271.     })
  1272.   }
  1273.  
  1274.   init(){
  1275.     this.calcDateCollection()
  1276.   }
  1277.  
  1278.   reverse(date){
  1279.     const vals = date.split("-")
  1280.     //return `${vals[2]}-${vals[1]}-${vals[0]}`
  1281.     return vals[2]+"-"+vals[1]+"-"+vals[0]
  1282.   }
  1283.  
  1284.   calcDateCollection(){
  1285.     if (!this.dateCollection) this.dateCollection = {}
  1286.     var flag = false
  1287.     var collection = []
  1288.     var dateObj = {}
  1289.     this.dateElemsCollection.forEach(dateElem => {
  1290.       if (dateElem.value) {
  1291.         flag = true
  1292.         collection.push(dateElem.value)
  1293.       }
  1294.       const weekday = new Date(dateElem.value).getDay()
  1295.       if (dateElem.value && weekday !== 6 && weekday !== 0){
  1296.         if (!this.dateCollection[dateElem.value]){
  1297.           dateObj[dateElem.value] = {
  1298.             limit: this.dailyLimit,
  1299.             items: {}
  1300.           }
  1301.         } else {
  1302.           dateObj[dateElem.value] = this.dateCollection[dateElem.value]
  1303.         }
  1304.       }
  1305.     })
  1306.     if (!this.selectedRadio || !collection.includes(this.selectedRadio)) this.selectedRadio = this.dateElemsCollection[0].value
  1307.     if (!flag) dateObj = null
  1308.     this.dateCollection = dateObj
  1309.     this.render()
  1310.   }
  1311.  
  1312.   get cartState(){
  1313.     return JSON.stringify(this.dateCollection)
  1314.   }
  1315.  
  1316.   render(){
  1317.     const wrapper = document.createElement("div")
  1318.     if (!this.dateCollection) {
  1319.       wrapper.innerHTML = "Диапазон дат указан неверно!"
  1320.     } else {
  1321.       for(let date in this.dateCollection){
  1322.         const dateWrapper = document.createElement("div")
  1323.         dateWrapper.className += "meido-cart-date-wrapper"
  1324.         const header = document.createElement("div")
  1325.         header.className += "meido-cart-date-header"
  1326.         const radio = document.createElement("input")
  1327.         radio.type = "radio"
  1328.         radio.id = date
  1329.         radio.value = date
  1330.         radio.name = "date-radio"
  1331.         radio.addEventListener('change', function(e){
  1332.           this.selectedRadio = e.target.value
  1333.         }.bind(this))
  1334.         if (date === this.selectedRadio) radio.checked = true
  1335.         header.appendChild(radio)
  1336.         const label = document.createElement("label")
  1337.         label.htmlFor = date
  1338.         //label.innerHTML += `${date} (остаток: ${this.dateCollection[date].limit} грн.)`
  1339.         label.innerHTML += date+" (остаток: "+this.dateCollection[date].limit+" грн.)"
  1340.         header.appendChild(label)
  1341.         dateWrapper.appendChild(header)
  1342.         var flag = false
  1343.         for(let item in this.dateCollection[date].items){
  1344.           flag = true
  1345.           const itemElem = document.createElement("div")
  1346.           itemElem.className += "meido-cart-item"
  1347.           const itemText = document.createElement("span")
  1348.           //itemText.innerHTML = `${this.dateCollection[date].items[item]} x ${this.itemList[item].name}`
  1349.           itemText.innerHTML = this.dateCollection[date].items[item]+" x "+this.itemList[item].name
  1350.           itemText.style.width = "90%"
  1351.           itemElem.appendChild(itemText)
  1352.           const itemRemove = document.createElement("button")
  1353.           itemRemove.innerHTML = "X"
  1354.           itemRemove.className += "meido-cart-item-remove"
  1355.           itemRemove.onclick = function(){ this.removeMeidoItem(item, date) }.bind(this)
  1356.           itemElem.appendChild(itemRemove)
  1357.           dateWrapper.appendChild(itemElem)
  1358.         }
  1359.         if (!flag) {
  1360.           const itemEmpty = document.createElement("div")
  1361.           itemEmpty.className += "meido-cart-item"
  1362.           itemEmpty.style.color = "grey"
  1363.           itemEmpty.innerHTML = "<i>Ничего не добавлено</i>"
  1364.           dateWrapper.appendChild(itemEmpty)
  1365.         }
  1366.         wrapper.appendChild(dateWrapper)
  1367.       }
  1368.     }
  1369.     this.renderTarget.innerHTML = ""
  1370.     this.renderTarget.appendChild(wrapper)
  1371.     document.getElementById(this.targetField).innerHTML = this.cartState
  1372.   }
  1373.  
  1374.   addMeidoItem(itemId){
  1375.     if (this.dateCollection[this.selectedRadio].limit - this.itemList[itemId].price >= 0) {
  1376.       if (!this.dateCollection[this.selectedRadio].items[itemId]) {
  1377.         this.dateCollection[this.selectedRadio].items[itemId] = 1
  1378.       } else {
  1379.         this.dateCollection[this.selectedRadio].items[itemId] += 1
  1380.       }
  1381.       this.dateCollection[this.selectedRadio].limit -= this.itemList[itemId].price
  1382.     } else {
  1383.       console.error('Insufficient funds!')
  1384.     }
  1385.     this.render()
  1386.   }
  1387.  
  1388.   removeMeidoItem(itemId, date){
  1389.     this.dateCollection[date].items[itemId] -= 1
  1390.     if (this.dateCollection[date].items[itemId] === 0) delete this.dateCollection[date].items[itemId]
  1391.     this.dateCollection[date].limit += this.itemList[itemId].price
  1392.     this.render()
  1393.   }
  1394. }
  1395.  
  1396. function meidoInit(container, dateElemsCollection, fsMeidoField, limit, reverseDate = false){
  1397.   const innerContainer = document.createElement("div")
  1398.  
  1399.   return fetch("https://analytics.getmeido.com/api/fs/product-list?token="+meidoToken)
  1400.   .then(res => {return res.json()})
  1401.   .then(data => {
  1402.     const title = document.createElement("h4")
  1403.     title.innerHTML = "Заказ еды Meido"
  1404.     innerContainer.appendChild(title)
  1405.     const mainWindow = buildMeidoWindow(data, dateElemsCollection, fsMeidoField, limit, reverseDate)
  1406.     innerContainer.appendChild(mainWindow)
  1407.     meidoCart.init()
  1408.     container.appendChild(innerContainer)
  1409.     return innerContainer
  1410.   }).catch(err => {
  1411.     console.error("[MEIDO] Cannot get Meido menu!")
  1412.     console.error(err)
  1413.   })
  1414.  
  1415. }
  1416.  
  1417. function buildMeidoWindow(apiData, dateElemsCollection, fsMeidoField, limit, reverseDate){
  1418.   const wrapper = document.createElement("div")
  1419.   wrapper.className += "meido-main-window"
  1420.   const menuElem = document.createElement("div")
  1421.   menuElem.id = "meido-menu"
  1422.   const cartElem = document.createElement("div")
  1423.   cartElem.id = "meido-cart"
  1424.   var categorized = {}
  1425.   var flat = {}
  1426.   apiData.forEach(item => {
  1427.     if (!categorized[item.product_contractor_title]) categorized[item.product_contractor_title] = {}
  1428.     if (!categorized[item.product_contractor_title][item.category_title]) categorized[item.product_contractor_title][item.category_title] = {}
  1429.     categorized[item.product_contractor_title][item.category_title][item.id] = item
  1430.     flat[item.id] = {
  1431.       name: item.product_title,
  1432.       price: parseFloat(item.product_price),
  1433.       bzhu: item.bzhu,
  1434.       weight: item.weight,
  1435.       cal: item.cal
  1436.     }
  1437.   })
  1438.   menuElem.appendChild(buildMenu(categorized))
  1439.   console.log(limit, dateElemsCollection, reverseDate)
  1440.   window.meidoCart = new MeidoCart(flat, limit, cartElem, dateElemsCollection, fsMeidoField, reverseDate)
  1441.   cartElem.className += "meido-cart-wrapper"
  1442.   wrapper.appendChild(menuElem)
  1443.   wrapper.appendChild(cartElem)
  1444.   return wrapper
  1445. }
  1446.  
  1447. function buildMenu(data){
  1448.   const wrapper = document.createElement("div")
  1449.   wrapper.className += "meido-menu-wrapper"
  1450.   for(let category in data){
  1451.     const categoryWrapper = document.createElement("div")
  1452.     const categoryHeader = document.createElement("div")
  1453.     categoryHeader.className += "meido-category-title"
  1454.     const categoryArrow = document.createElement("span")
  1455.     categoryArrow.className += "arrow"
  1456.     categoryArrow.innerHTML = "►"
  1457.     const categoryTitle = document.createElement("span")
  1458.     categoryTitle.innerHTML = category
  1459.     categoryHeader.appendChild(categoryArrow)
  1460.     categoryHeader.appendChild(categoryTitle)
  1461.     const categoryContent = document.createElement("div")
  1462.     categoryContent.className += "meido-category-content"
  1463.     categoryHeader.onclick = function(){
  1464.       categoryContent.hidden = !categoryContent.hidden
  1465.       categoryArrow.innerHTML = (categoryArrow.innerHTML === "►" ? "▼" : "►")
  1466.     }
  1467.     categoryContent.hidden = true
  1468.     categoryWrapper.appendChild(categoryHeader)
  1469.     for(let contractor in data[category]){
  1470.       const contractorWrapper = document.createElement("div")
  1471.       const contractorHeader = document.createElement("div")
  1472.       contractorHeader.className += "meido-contractor-title"
  1473.       const contractorArrow = document.createElement("span")
  1474.       contractorArrow.className += "arrow"
  1475.       contractorArrow.innerHTML = "►"
  1476.       const contractorTitle = document.createElement("span")
  1477.       contractorTitle.innerHTML = contractor
  1478.       contractorHeader.appendChild(contractorArrow)
  1479.       contractorHeader.appendChild(contractorTitle)
  1480.       const contractorContent = document.createElement("div")
  1481.       contractorContent.className += "meido-contractor-content"
  1482.       contractorHeader.onclick = function(){
  1483.         contractorContent.hidden = !contractorContent.hidden
  1484.         contractorArrow.innerHTML = (contractorArrow.innerHTML === "►" ? "▼" : "►")
  1485.       }
  1486.       contractorContent.hidden = true
  1487.       contractorWrapper.appendChild(contractorHeader)
  1488.       for(let item in data[category][contractor]){
  1489.         contractorContent.appendChild(buildMenuItem(data[category][contractor][item]))
  1490.       }
  1491.       contractorWrapper.appendChild(contractorContent)
  1492.       categoryContent.appendChild(contractorWrapper)
  1493.     }
  1494.     categoryWrapper.appendChild(categoryContent)
  1495.     wrapper.appendChild(categoryWrapper)
  1496.   }
  1497.  
  1498.   return wrapper
  1499. }
  1500.  
  1501. function buildMenuItem(item){
  1502.   const wrapper = document.createElement("div")
  1503.   wrapper.className += "meido-item"
  1504.   const itemTitle = document.createElement("div")
  1505.   itemTitle.innerHTML = item.product_title
  1506.   itemTitle.className += "meido-item-title"
  1507.   const descWrapper = document.createElement("div")
  1508.   descWrapper.className += "meido-desc-wrapper"
  1509.   const itemPic = document.createElement("img")
  1510.   itemPic.src = item.photo_url
  1511.   itemPic.className += "meido-pic"
  1512.   const innerWrapper = document.createElement("div")
  1513.   const itemDesc = document.createElement("div")
  1514.   itemDesc.innerHTML = item.product_description
  1515.   itemDesc.className += "meido-desc-text"
  1516.   const itemInfo = document.createElement("div")
  1517.   itemInfo.innerHTML = item.weight + " gr.    " + item.cal
  1518.   itemInfo.className += "meido-item-bzhu"
  1519.   const itemBzhu = document.createElement("div")
  1520.   itemBzhu.innerHTML = item.bzhu
  1521.   itemBzhu.className += "meido-item-bzhu"
  1522.   descWrapper.appendChild(itemPic)
  1523.   innerWrapper.appendChild(itemDesc)
  1524.   innerWrapper.appendChild(itemInfo)
  1525.   innerWrapper.appendChild(itemBzhu)
  1526.   descWrapper.appendChild(innerWrapper)
  1527.   const price = document.createElement("span")
  1528.   //price.innerHTML = `<i>Цена: ${item.product_price} грн.</i>`
  1529.   price.innerHTML = "Цена: "+item.product_price+" грн."
  1530.   price.className += "meido-price"
  1531.   const add = document.createElement("button")
  1532.   add.innerHTML = "Buy"
  1533.   add.className += "meido-add-button"
  1534.   add.onclick = null
  1535.   add.onclick = function(e){
  1536.     e.preventDefault()
  1537.     meidoCart.addMeidoItem(item.id)
  1538.   }
  1539.   wrapper.appendChild(itemTitle)
  1540.   wrapper.appendChild(descWrapper)
  1541.   wrapper.appendChild(add)
  1542.   wrapper.appendChild(price)
  1543.   return wrapper
  1544. }
  1545.  
  1546.   const countriesGlobal = ["Afghanistan","Åland Islands","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia (Plurinational State of)","Bonaire, Sint Eustatius and Saba","Bosnia and Herzegovina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","United States Minor Outlying Islands","Virgin Islands (British)","Virgin Islands (U.S.)","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cabo Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos (Keeling) Islands","Colombia","Comoros","Congo","Congo (Democratic Republic of the)","Cook Islands","Costa Rica","Croatia","Cuba","Curaçao","Cyprus","Czech Republic","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Ethiopia","Falkland Islands (Malvinas)","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guernsey","Guinea","Guinea-Bissau","Guyana","Haiti","Heard Island and McDonald Islands","Holy See","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Côte d'Ivoire","Iran (Islamic Republic of)","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People's Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macao","Macedonia (the former Yugoslav Republic of)","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Micronesia (Federated States of)","Moldova (Republic of)","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","Korea (Democratic People's Republic of)","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Palestine, State of","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Republic of Kosovo","Réunion","Romania","Russian Federation","Rwanda","Saint Barthélemy","Saint Helena, Ascension and Tristan da Cunha","Saint Kitts and Nevis","Saint Lucia","Saint Martin (French part)","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Sint Maarten (Dutch part)","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia and the South Sandwich Islands","Korea (Republic of)","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen","Swaziland","Sweden","Switzerland","Syrian Arab Republic","Taiwan","Tajikistan","Tanzania, United Republic of","Thailand","Timor-Leste","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom of Great Britain and Northern Ireland","United States of America","Uruguay","Uzbekistan","Vanuatu","Venezuela (Bolivarian Republic of)","Viet Nam","Wallis and Futuna","Western Sahara","Yemen","Zambia","Zimbabwe"]
  1547.  
  1548. </script>
  1549.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement