diff options
| author | Jiten (OpenERP) <jra@tinyerp.com> | 2011-10-25 11:43:27 +0530 |
|---|---|---|
| committer | Jiten (OpenERP) <jra@tinyerp.com> | 2011-10-25 11:43:27 +0530 |
| commit | 417cae1645d11ee173bbb2dcebe112009b520cd7 (patch) | |
| tree | 501bb01b6d8688258155661577669d85fe887879 /addons/web/static/src/js/core.js | |
| parent | 27598512e3e267d92a863c7df41974208ea8b554 (diff) | |
| parent | f097e140b8b51437258ae03000b37f1677f6098b (diff) | |
[Merge] Merge from openerp-web
bzr revid: bth@tinyerp.com-20111020062457-h4v2ud105ver5u5y
bzr revid: jra@tinyerp.com-20111025061327-v676oxmsx3xz66s3
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; +} }; |
