summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/framework/qweb.js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2016-06-16 13:19:15 +0200
committerGéry Debongnie <ged@odoo.com>2016-06-17 13:27:18 +0200
commitd56b35e26e4b578c5f6f434d336edd006d321860 (patch)
tree213d2cad70191c3d6576eb76efa754ade974dcfb /addons/web/static/src/js/framework/qweb.js
parent611322c36b5dcf73c9f4286a083cd150672d2319 (diff)
[REF] web, *: move QWeb odoo init to web.QWeb
this js module centralizes all odoo initialization
Diffstat (limited to 'addons/web/static/src/js/framework/qweb.js')
-rw-r--r--addons/web/static/src/js/framework/qweb.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/addons/web/static/src/js/framework/qweb.js b/addons/web/static/src/js/framework/qweb.js
new file mode 100644
index 00000000000..b29f0f06d65
--- /dev/null
+++ b/addons/web/static/src/js/framework/qweb.js
@@ -0,0 +1,48 @@
+odoo.define('web.QWeb', function (require) {
+"use strict";
+
+var translation = require('web.translation');
+
+function QWeb(debug) {
+ var qweb = new QWeb2.Engine();
+ qweb.default_dict = {
+ '_' : _,
+ 'JSON': JSON,
+ '_t' : translation._t,
+ '__debug__': debug,
+ 'moment': function(date) { return new moment(date); },
+ 'csrf_token': odoo.csrf_token,
+ };
+ qweb.debug = debug;
+ return qweb;
+}
+
+QWeb.prototype.preprocess_node = function() {
+ // Note that 'this' is the Qweb Node
+ switch (this.node.nodeType) {
+ case Node.TEXT_NODE:
+ case Node.CDATA_SECTION_NODE:
+ // Text and CDATAs
+ var translation = this.node.parentNode.attributes['t-translation'];
+ if (translation && translation.value === 'off') {
+ return;
+ }
+ var match = /^(\s*)([\s\S]+?)(\s*)$/.exec(this.node.data);
+ if (match) {
+ this.node.data = match[1] + _t(match[2]) + match[3];
+ }
+ break;
+ case Node.ELEMENT_NODE:
+ // Element
+ var attr, attrs = ['label', 'title', 'alt', 'placeholder'];
+ while ((attr = attrs.pop())) {
+ if (this.attributes[attr]) {
+ this.attributes[attr] = _t(this.attributes[attr]);
+ }
+ }
+ }
+};
+
+return QWeb;
+
+});