2021-08-31 18:09:59 +02:00
|
|
|
import {
|
2021-09-04 15:05:34 +02:00
|
|
|
defineComponent, onMounted, ref,
|
2021-08-31 18:09:59 +02:00
|
|
|
} from 'vue'
|
|
|
|
|
import { useI18n } from '@src/boot/i18n'
|
2022-07-10 01:24:54 +02:00
|
|
|
import { useQuasar } from 'quasar'
|
2021-08-31 18:09:59 +02:00
|
|
|
|
|
|
|
|
// PropType,
|
|
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'BannerCookies',
|
|
|
|
|
components: {},
|
|
|
|
|
props: {
|
|
|
|
|
urlInfo: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setup(props, context) {
|
|
|
|
|
const { t } = useI18n();
|
|
|
|
|
|
2022-07-10 01:24:54 +02:00
|
|
|
const $q = useQuasar()
|
|
|
|
|
|
2021-08-31 18:09:59 +02:00
|
|
|
const elementId = ref<string>('id');
|
|
|
|
|
const disableDecline = ref<boolean>(true);
|
|
|
|
|
const debug = ref<boolean>(false);
|
|
|
|
|
const status = ref<string | null>(null);
|
|
|
|
|
const supportsLocalStorage = ref<boolean>(true);
|
|
|
|
|
const isOpen = ref<boolean>(false);
|
|
|
|
|
|
|
|
|
|
const getCookieStatus = (): string | null => {
|
|
|
|
|
if (supportsLocalStorage.value) {
|
|
|
|
|
return localStorage.getItem(`cookie-${elementId.value}`)
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
// return tinyCookie.get(`cookie-${this.elementId}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const init = (): void => {
|
|
|
|
|
const visitedType = getCookieStatus()
|
|
|
|
|
if (visitedType && (visitedType === 'accept' || visitedType === 'decline' || visitedType === 'postpone')) {
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!visitedType) {
|
|
|
|
|
isOpen.value = true
|
|
|
|
|
}
|
|
|
|
|
if (!supportsLocalStorage.value) isOpen.value = false
|
|
|
|
|
|
|
|
|
|
status.value = visitedType
|
|
|
|
|
context.emit('status', visitedType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const checkLocalStorageFunctionality = (): void => {
|
|
|
|
|
// Check for availability of localStorage
|
|
|
|
|
try {
|
|
|
|
|
const test = '__cookie-check-localStorage'
|
|
|
|
|
window.localStorage.setItem(test, test)
|
|
|
|
|
window.localStorage.removeItem(test)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('Local storage is not supported, falling back to cookie use')
|
|
|
|
|
supportsLocalStorage.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const setCookieStatus = (type: string): void => {
|
|
|
|
|
if (supportsLocalStorage.value) {
|
|
|
|
|
if (type === 'accept') {
|
|
|
|
|
localStorage.setItem(`cookie-${elementId.value}`, 'accept')
|
|
|
|
|
}
|
|
|
|
|
if (type === 'decline') {
|
|
|
|
|
localStorage.setItem(`cookie-${elementId.value}`, 'decline')
|
|
|
|
|
}
|
|
|
|
|
if (type === 'postpone') {
|
|
|
|
|
localStorage.setItem(`cookie-${elementId.value}`, 'postpone')
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* if (type === 'accept') {
|
|
|
|
|
tinyCookie.set(`cookie-${elementId}`, 'accept')
|
|
|
|
|
}
|
|
|
|
|
if (type === 'decline') {
|
|
|
|
|
tinyCookie.set(`cookie-${elementId}`, 'decline')
|
|
|
|
|
}
|
|
|
|
|
if (type === 'postpone') {
|
|
|
|
|
tinyCookie.set(`cookie-${elementId}`, 'postpone')
|
|
|
|
|
} */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const accept = (): void => {
|
|
|
|
|
if (!debug.value) {
|
|
|
|
|
setCookieStatus('accept')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status.value = 'accept'
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
context.emit('clicked-accept')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const decline = (): void => {
|
|
|
|
|
|
2022-07-10 01:24:54 +02:00
|
|
|
const mytitle = 'Cookies'
|
|
|
|
|
const mytext = t('reg.refuse_cookie')
|
|
|
|
|
|
|
|
|
|
return $q.dialog({
|
|
|
|
|
message: mytext,
|
|
|
|
|
html: true,
|
|
|
|
|
ok: {
|
|
|
|
|
label: 'Rifiuta Cookies',
|
|
|
|
|
push: true,
|
|
|
|
|
},
|
|
|
|
|
title: mytitle,
|
|
|
|
|
cancel: true,
|
|
|
|
|
persistent: false,
|
|
|
|
|
}).onOk(() => {
|
|
|
|
|
if (!debug.value) {
|
|
|
|
|
setCookieStatus('decline')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status.value = 'decline'
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
context.emit('clicked-decline')
|
|
|
|
|
|
|
|
|
|
}).onCancel(() => {
|
|
|
|
|
//
|
|
|
|
|
})
|
|
|
|
|
|
2021-08-31 18:09:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const clickInfo = (): void => {
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
}
|
|
|
|
|
const postpone = (): void => {
|
|
|
|
|
if (!debug.value) {
|
|
|
|
|
setCookieStatus('postpone')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status.value = 'postpone'
|
|
|
|
|
isOpen.value = false
|
|
|
|
|
context.emit('clicked-postpone')
|
|
|
|
|
}
|
|
|
|
|
const removeCookie = (): void => {
|
|
|
|
|
localStorage.removeItem(`cookie-${elementId.value}`)
|
|
|
|
|
status.value = null
|
|
|
|
|
context.emit('removed-cookie')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(init)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
disableDecline,
|
|
|
|
|
decline,
|
|
|
|
|
accept,
|
|
|
|
|
postpone,
|
|
|
|
|
checkLocalStorageFunctionality,
|
|
|
|
|
clickInfo,
|
|
|
|
|
removeCookie,
|
|
|
|
|
isOpen,
|
|
|
|
|
t,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|