1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-11 05:54:15 +01:00

57 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-06-13 11:28:55 +02:00
'use strict';
/**
* Controller used for the cookies consent modal
*/
Application.Controllers.controller('CookiesController', ['$scope', '$cookies', 'Setting',
function ($scope, $cookies, Setting) {
/* PUBLIC SCOPE */
// the acceptation state (undefined if no decision was made until now)
$scope.cookiesState = undefined;
// link pointed by "learn more"
$scope.learnMoreUrl = 'https://www.cookiesandyou.com/';
2022-03-21 17:59:38 +01:00
// add a cookie to the browser, saving the user choice to refuse cookies
2019-06-13 11:28:55 +02:00
$scope.declineCookies = function () {
const expires = moment().add(13, 'months').toDate();
$cookies.put('fab-manager-cookies-consent', 'decline', { expires });
readCookie();
};
2022-03-21 17:59:38 +01:00
// add a cookie to the browser, saving the user choice to accept cookies.
// Then enable the analytics
2019-06-13 11:28:55 +02:00
$scope.acceptCookies = function () {
const expires = moment().add(13, 'months').toDate();
$cookies.put('fab-manager-cookies-consent', 'accept', { expires });
readCookie();
2022-03-21 17:59:38 +01:00
GTM.enableAnalytics(Fablab.trackingId);
2019-06-13 11:28:55 +02:00
};
/* PRIVATE SCOPE */
/**
* Kind of constructor: these actions will be realized first when the controller is loaded
*/
const initialize = function () {
readCookie();
2022-03-21 17:59:38 +01:00
// if the privacy policy was defined, redirect the user to it when clicking on "read more"
2019-06-13 11:28:55 +02:00
Setting.get({ name: 'privacy_body' }, data => {
if (data.setting.value) {
$scope.learnMoreUrl = '#!/privacy-policy';
}
});
// if the tracking ID was not set in the settings, only functional cookies will be set, so user consent is not required
if (!Fablab.trackingId) $scope.cookiesState = 'ignore';
2019-06-13 11:28:55 +02:00
};
const readCookie = function () {
$scope.cookiesState = $cookies.get('fab-manager-cookies-consent');
};
// !!! MUST BE CALLED AT THE END of the controller
return initialize();
}
]);