[IMP] web : add set_cookie in utils.js (framework) since the get_cookie method already exists. The set_cookie of session.js is now using the one from utils.js

This commit is contained in:
Jérome Maes
2015-03-24 11:48:25 +01:00
parent 88f119314f
commit ebc75e1395
2 changed files with 19 additions and 7 deletions
@@ -156,12 +156,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
set_cookie: function (name, value, ttl) {
if (!this.name) { return; }
ttl = ttl || 24*60*60*365;
document.cookie = [
this.name + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)),
'path=/',
'max-age=' + ttl,
'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
].join(';');
utils.set_cookie(this.name + '|' + name, value, ttl);
},
/**
* Load additional web addons of that instance and init them
@@ -388,7 +383,7 @@ var Session = core.Class.extend(mixins.EventDispatcherMixin, {
qs = "?" + qs;
var prefix = _.any(['http://', 'https://', '//'], function(el) {
return path.length >= el.length && path.slice(0, el.length) === el;
}) ? '' : this.prefix;
}) ? '' : this.prefix;
return prefix + path + qs;
},
});
@@ -222,6 +222,22 @@ function get_cookie (c_name) {
return "";
}
/**
* 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.
*/
function 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(';');
};
/**
* Insert "thousands" separators in the provided number (which is actually
* a string)
@@ -368,6 +384,7 @@ return {
xml_to_str: xml_to_str,
Mutex: Mutex,
get_cookie: get_cookie,
set_cookie: set_cookie,
insert_thousand_seps: insert_thousand_seps,
is_bin_size: is_bin_size,
binary_to_binsize: binary_to_binsize,