diff options
Diffstat (limited to 'addons/web/static/src/js/core.js')
| -rw-r--r-- | addons/web/static/src/js/core.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 8dfbd68e6de..39a1ba7ef64 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -10,8 +10,6 @@ if (!console.debug) { } openerp.web.core = function(openerp) { -openerp.web.qweb = new QWeb2.Engine(); -openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); /** * John Resig Class with factory improvement */ @@ -363,6 +361,9 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web this.context = {}; this.shortcuts = []; this.active_id = null; + // TODO: session should have an optional name indicating that they'll + // be saved to (and revived from) cookies + this.name = 'session'; }, start: function() { this.session_restore(); @@ -527,7 +528,8 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web * @param name the cookie's name */ get_cookie: function (name) { - var nameEQ = this.element_id + '|' + name + '='; + if (!this.name) { return null; } + var nameEQ = this.name + '|' + name + '='; var cookies = document.cookie.split(';'); for(var i=0; i<cookies.length; ++i) { var cookie = cookies[i].replace(/^\s*/, ''); @@ -546,9 +548,11 @@ openerp.web.Session = openerp.web.CallbackEnabled.extend( /** @lends openerp.web * @param ttl the cookie's time to live, 1 year by default, set to -1 to delete */ set_cookie: function (name, value, ttl) { + if (!this.name) { return; } ttl = ttl || 24*60*60*365; document.cookie = [ - this.element_id + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)), + this.name + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)), + 'path=/', 'max-age=' + ttl, 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString() ].join(';'); @@ -1040,6 +1044,21 @@ openerp.web.TranslationDataBase = openerp.web.Class.extend(/** @lends openerp.we }); openerp.web._t = new openerp.web.TranslationDataBase().build_translation_function(); +openerp.web.qweb = new QWeb2.Engine(); +openerp.web.qweb.debug = (window.location.search.indexOf('?debug') !== -1); +openerp.web.qweb.format_text_node = function(s) { + // Note that 'this' is the Qweb Node of the text + var translation = this.node.parentNode.attributes['t-translation']; + if (translation && translation.value === 'off') { + return s; + } + var ts = _.trim(s); + if (ts.length === 0) { + return s; + } + var tr = openerp.web._t(ts); + return tr === ts ? s : tr; +} }; |
