[REF] web, *: move cookie utils out of legacy core utils
*: im_livechat Cookie utils will be required on the frontend side but before the lazy loading. This commit splits them out of default utils to achieve that. Note: kept as "legacy" utils anyway, we'll handle that when the time is right... Part of https://github.com/odoo/odoo/pull/67140 task-2381049
This commit is contained in:
@@ -143,6 +143,7 @@ Help your customers with this chat, and analyse their feedback.
|
||||
'web/static/src/session.js',
|
||||
'web/static/src/legacy/js/core/session.js',
|
||||
'web/static/src/legacy/js/core/concurrency.js',
|
||||
'web/static/src/legacy/js/core/cookie_utils.js',
|
||||
'web/static/src/legacy/js/core/utils.js',
|
||||
'web/static/src/legacy/js/core/dom.js',
|
||||
'web/static/src/legacy/js/core/qweb.js',
|
||||
|
||||
@@ -58,6 +58,7 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/src/legacy/js/promise_extension.js',
|
||||
'web/static/src/boot.js',
|
||||
'web/static/src/session.js',
|
||||
'web/static/src/legacy/js/core/cookie_utils.js',
|
||||
],
|
||||
'web.assets_common': [
|
||||
('include', 'web._assets_helpers'),
|
||||
@@ -75,6 +76,7 @@ This module provides the core of the Odoo Web Client.
|
||||
('remove', 'web/static/src/legacy/js/promise_extension.js'),
|
||||
('remove', 'web/static/src/boot.js'),
|
||||
('remove', 'web/static/src/session.js'),
|
||||
('remove', 'web/static/src/legacy/js/core/cookie_utils.js'),
|
||||
],
|
||||
'web.assets_backend': [
|
||||
('include', 'web._assets_helpers'),
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
odoo.define('web.utils.cookies', function (require) {
|
||||
"use strict";
|
||||
|
||||
return {
|
||||
/**
|
||||
* Reads the cookie described by the given name.
|
||||
*
|
||||
* @param {string} cookieName
|
||||
* @returns {string}
|
||||
*/
|
||||
get_cookie(cookieName) {
|
||||
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||
for (var i = 0, l = cookies.length; i < l; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var name = parts.shift();
|
||||
var cookie = parts.join('=');
|
||||
|
||||
if (cookieName && cookieName === name) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
},
|
||||
/**
|
||||
* Creates a cookie.
|
||||
*
|
||||
* @param {string} name the name of the cookie
|
||||
* @param {string} value the value stored in the cookie
|
||||
* @param {integer} ttl time to live of the cookie in millis. -1 to erase the cookie.
|
||||
*/
|
||||
set_cookie(name, value, ttl) {
|
||||
ttl = ttl || 24 * 60 * 60 * 365;
|
||||
document.cookie = [
|
||||
`${name}=${value}`,
|
||||
'path=/',
|
||||
`max-age=${ttl}`,
|
||||
`expires=${new Date(new Date().getTime() + ttl * 1000).toGMTString()}`
|
||||
].join(';');
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -8,6 +8,7 @@ odoo.define('web.utils', function (require) {
|
||||
*/
|
||||
|
||||
var translation = require('web.translation');
|
||||
var cookieUtils = require('web.utils.cookies');
|
||||
|
||||
var _t = translation._t;
|
||||
var id = -1;
|
||||
@@ -311,7 +312,7 @@ function Markup(v, ...exprs) {
|
||||
return new _Markup(s);
|
||||
}
|
||||
|
||||
var utils = {
|
||||
var utils = Object.assign({
|
||||
AlreadyDefinedPatchError,
|
||||
UnknownPatchError,
|
||||
Markup,
|
||||
@@ -390,25 +391,6 @@ var utils = {
|
||||
generateID: function () {
|
||||
return ++id;
|
||||
},
|
||||
/**
|
||||
* Read the cookie described by c_name
|
||||
*
|
||||
* @param {string} c_name
|
||||
* @returns {string}
|
||||
*/
|
||||
get_cookie: function (c_name) {
|
||||
var cookies = document.cookie ? document.cookie.split('; ') : [];
|
||||
for (var i = 0, l = cookies.length; i < l; i++) {
|
||||
var parts = cookies[i].split('=');
|
||||
var name = parts.shift();
|
||||
var cookie = parts.join('=');
|
||||
|
||||
if (c_name && c_name === name) {
|
||||
return cookie;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
},
|
||||
/**
|
||||
* Gets dataURL (base64 data) from the given file or blob.
|
||||
* Technically wraps FileReader.readAsDataURL in Promise.
|
||||
@@ -849,21 +831,6 @@ var utils = {
|
||||
str = "" + str;
|
||||
return str + new Array(size - str.length + 1).join('0');
|
||||
},
|
||||
/**
|
||||
* Create a cookie
|
||||
* @param {String} name the name of the cookie
|
||||
* @param {String} value the value stored in the cookie
|
||||
* @param {Integer} ttl time to live of the cookie in millis. -1 to erase the cookie.
|
||||
*/
|
||||
set_cookie: function (name, value, ttl) {
|
||||
ttl = ttl || 24*60*60*365;
|
||||
document.cookie = [
|
||||
name + '=' + value,
|
||||
'path=/',
|
||||
'max-age=' + ttl,
|
||||
'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
|
||||
].join(';');
|
||||
},
|
||||
/**
|
||||
* Return a shallow copy of a given array sorted by a given criterion or a default one.
|
||||
* The given criterion can either be:
|
||||
@@ -1174,7 +1141,7 @@ var utils = {
|
||||
['name', '=like', '%.report_assets\_%.css'],
|
||||
];
|
||||
},
|
||||
};
|
||||
}, cookieUtils);
|
||||
|
||||
return utils;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user