appointments.js
1 week ago
attendees.js
1 week ago
colorManipulation.js
1 week ago
customer.js
1 week ago
date.js
1 week ago
defaultCustomize.js
1 week ago
employee.js
1 week ago
events.js
1 week ago
formFieldsTemplates.js
1 week ago
formatting.js
1 week ago
helper.js
1 week ago
image.js
1 week ago
integrationApple.js
1 week ago
integrationGoogle.js
1 week ago
integrationOutlook.js
1 week ago
integrationStripe.js
1 week ago
integrationZoom.js
1 week ago
licence.js
1 week ago
phone.js
1 week ago
pricing.js
1 week ago
recurring.js
1 week ago
responsive.js
1 week ago
scrollElements.js
1 week ago
settings.js
1 week ago
translationsElementPlus.js
1 week ago
utilHeaderHeight.js
1 week ago
helper.js
190 lines
| 1 | import { settings } from '../../../plugins/settings.js' |
| 2 | |
| 3 | function useCurrentTimeZone() { |
| 4 | return Intl.DateTimeFormat().resolvedOptions().timeZone |
| 5 | } |
| 6 | |
| 7 | function useRemoveUrlParameter(url, parameter) { |
| 8 | let urlParts = url.split('?') |
| 9 | |
| 10 | if (urlParts.length >= 2) { |
| 11 | let prefix = encodeURIComponent(parameter) + '=' |
| 12 | let pars = urlParts[1].split(/[&;]/g) |
| 13 | |
| 14 | for (let i = pars.length; i-- > 0; ) { |
| 15 | if (pars[i].lastIndexOf(prefix, 0) !== -1) { |
| 16 | pars.splice(i, 1) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | url = urlParts[0] + (pars.length > 0 ? '?' + pars.join('&') : '') |
| 21 | } |
| 22 | |
| 23 | return url |
| 24 | } |
| 25 | |
| 26 | function useUrlParams(params) { |
| 27 | if (!settings.activation.disableUrlParams) { |
| 28 | return params |
| 29 | } |
| 30 | |
| 31 | let names = [ |
| 32 | 'categories', |
| 33 | 'services', |
| 34 | 'packages', |
| 35 | 'employees', |
| 36 | 'providers', |
| 37 | 'providerIds', |
| 38 | 'extras', |
| 39 | 'locations', |
| 40 | 'events', |
| 41 | 'types', |
| 42 | 'dates', |
| 43 | 'customers', |
| 44 | 'providers', |
| 45 | 'services', |
| 46 | 'locations', |
| 47 | 'status', |
| 48 | ] |
| 49 | |
| 50 | let convertedParams = JSON.parse(JSON.stringify(params)) |
| 51 | |
| 52 | names.forEach((name) => { |
| 53 | if (name === 'extras' && name in convertedParams && convertedParams['extras']) { |
| 54 | convertedParams['extras'] = JSON.parse(convertedParams['extras']) |
| 55 | |
| 56 | let extras = [] |
| 57 | |
| 58 | convertedParams['extras'].forEach((item) => { |
| 59 | extras.push(item.id + '-' + item.quantity) |
| 60 | }) |
| 61 | |
| 62 | convertedParams['extras'] = extras.length ? extras : null |
| 63 | } |
| 64 | |
| 65 | if ( |
| 66 | name in convertedParams && |
| 67 | Array.isArray(convertedParams[name]) && |
| 68 | convertedParams[name].length |
| 69 | ) { |
| 70 | convertedParams[name] = convertedParams[name].join(',') |
| 71 | } |
| 72 | }) |
| 73 | |
| 74 | return convertedParams |
| 75 | } |
| 76 | |
| 77 | function useSortedDateStrings(dates) { |
| 78 | return dates.sort((a, b) => new Date(a) - new Date(b)) |
| 79 | } |
| 80 | |
| 81 | function useSortedTimeStrings(times) { |
| 82 | return times.sort((a, b) => new Date(`2000-01-01T${a}`) - new Date(`2000-01-01T${b}`)) |
| 83 | } |
| 84 | |
| 85 | function useUrlQueryParams(url) { |
| 86 | let queryString = |
| 87 | url.indexOf('#') > 0 ? url.substring(0, url.indexOf('#')).split('?')[1] : url.split('?')[1] |
| 88 | |
| 89 | if (queryString) { |
| 90 | let keyValuePairs = queryString.split('&') |
| 91 | let keyValue = [] |
| 92 | let queryParams = {} |
| 93 | |
| 94 | keyValuePairs.forEach(function (pair) { |
| 95 | keyValue = pair.split('=') |
| 96 | queryParams[keyValue[0]] = decodeURIComponent(keyValue[1]).replace(/\+/g, ' ') |
| 97 | }) |
| 98 | |
| 99 | return queryParams |
| 100 | } |
| 101 | |
| 102 | // ! return null |
| 103 | return {} |
| 104 | } |
| 105 | |
| 106 | function useUrlQueryParam(param) { |
| 107 | let queryParams = useUrlQueryParams(window.location.href) |
| 108 | |
| 109 | return param in queryParams ? queryParams[param] : null |
| 110 | } |
| 111 | |
| 112 | function useDescriptionVisibility(text) { |
| 113 | if (text && text.length) { |
| 114 | return ( |
| 115 | !text.includes('<!-- Content -->') || (text.includes('<!-- Content -->') && text.length > 16) |
| 116 | ) |
| 117 | } |
| 118 | |
| 119 | return false |
| 120 | } |
| 121 | function mapAddressComponentsForXML(components) { |
| 122 | const result = {} |
| 123 | |
| 124 | components.forEach((component) => { |
| 125 | const types = component.types |
| 126 | |
| 127 | if (types.includes('street_number')) { |
| 128 | result.BuildingNumber = component.long_name |
| 129 | } |
| 130 | |
| 131 | if (types.includes('route')) { |
| 132 | result.StreetName = component.long_name |
| 133 | } |
| 134 | |
| 135 | if (types.includes('postal_code')) { |
| 136 | result.PostalZone = component.long_name |
| 137 | } |
| 138 | |
| 139 | if (types.includes('locality')) { |
| 140 | result.CityName = component.long_name |
| 141 | } |
| 142 | |
| 143 | if (types.includes('administrative_area_level_1')) { |
| 144 | result.CountrySubentity = component.long_name |
| 145 | } |
| 146 | |
| 147 | if (types.includes('administrative_area_level_2') && !result.CountrySubentity) { |
| 148 | result.CountrySubentity = component.long_name |
| 149 | } |
| 150 | |
| 151 | if (types.includes('country')) { |
| 152 | result.CountryCode = component.short_name |
| 153 | } |
| 154 | |
| 155 | if (types.includes('premise')) { |
| 156 | result.Premise = component.long_name |
| 157 | } |
| 158 | |
| 159 | if (types.includes('sublocality') || types.includes('neighborhood')) { |
| 160 | result.AdditionalStreetName = component.long_name |
| 161 | } |
| 162 | }) |
| 163 | |
| 164 | return result |
| 165 | } |
| 166 | |
| 167 | function createFileUrlFromResponse(response, format = 'pdf') { |
| 168 | const byteCharacters = atob(response.data) |
| 169 | const byteNumbers = new Array(byteCharacters.length) |
| 170 | for (let i = 0; i < byteCharacters.length; i++) { |
| 171 | byteNumbers[i] = byteCharacters.charCodeAt(i) |
| 172 | } |
| 173 | const byteArray = new Uint8Array(byteNumbers) |
| 174 | const file = new Blob([byteArray], { type: `application/${format};base64` }) |
| 175 | return URL.createObjectURL(file) |
| 176 | } |
| 177 | |
| 178 | export { |
| 179 | useRemoveUrlParameter, |
| 180 | useSortedDateStrings, |
| 181 | useUrlParams, |
| 182 | useUrlQueryParams, |
| 183 | useUrlQueryParam, |
| 184 | useCurrentTimeZone, |
| 185 | useSortedTimeStrings, |
| 186 | useDescriptionVisibility, |
| 187 | createFileUrlFromResponse, |
| 188 | mapAddressComponentsForXML, |
| 189 | } |
| 190 |