summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2012-02-07 14:29:01 +0100
committerFabien Meghazi <fme@openerp.com>2012-02-07 14:29:01 +0100
commitce65bc3ac37934a27045e8af3d43fc0accf35f3c (patch)
tree5504c739a2a1f66487aefdcfdff5a5b05d68d2ee
parentb5579eee208bf12a4d591e45f3b5ea21cbec69c0 (diff)
[IMP] Add QWeb preprocess_node callback. Translate @label, @title and @alt attributes in web client
bzr revid: fme@openerp.com-20120207132901-ifwnfj6c4mp451tl
-rw-r--r--addons/web/static/lib/qweb/qweb2.js16
-rw-r--r--addons/web/static/src/js/core.js38
2 files changed, 36 insertions, 18 deletions
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 1ec2a37c02d..9845889a0b7 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -55,7 +55,7 @@ var QWeb2 = {
if (o !== null && o !== undefined) {
if (o.constructor === Array) {
if (o[1] !== null && o[1] !== undefined) {
- return ' ' + o[0] + '="' + this.html_escape(o[1], true) + '"';
+ return this.format_attribute(o[0], o[1]);
}
} else if (typeof o === 'object') {
var r = '';
@@ -69,6 +69,9 @@ var QWeb2 = {
}
return '';
},
+ format_attribute: function(name, value) {
+ return ' ' + name + '="' + this.html_escape(value, true) + '"';
+ },
extend: function(dst, src, exclude) {
for (var p in src) {
if (src.hasOwnProperty(p) && !(exclude && this.arrayIndexOf(exclude, p) !== -1)) {
@@ -193,7 +196,7 @@ QWeb2.Engine = (function() {
this.reserved_words = QWeb2.RESERVED_WORDS.slice(0);
this.actions_precedence = QWeb2.ACTIONS_PRECEDENCE.slice(0);
this.word_replacement = QWeb2.tools.extend({}, QWeb2.WORD_REPLACEMENT);
- this.format_text_node = null;
+ this.preprocess_node = null;
for (var i = 0; i < arguments.length; i++) {
this.add_template(arguments[i]);
}
@@ -437,6 +440,9 @@ QWeb2.Element = (function() {
}
}
}
+ if (this.engine.preprocess_node) {
+ this.engine.preprocess_node.call(this);
+ }
}
QWeb2.tools.extend(Element.prototype, {
@@ -472,11 +478,7 @@ QWeb2.Element = (function() {
switch (this.node.nodeType) {
case 3:
case 4:
- var text = this.node.data;
- if (this.engine.format_text_node) {
- text = this.engine.format_text_node.call(this, text);
- }
- this.top_string(text);
+ this.top_string(this.node.data);
break;
case 1:
this.compile_element();
diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js
index e5e1bc4a066..9d88a8af7f2 100644
--- a/addons/web/static/src/js/core.js
+++ b/addons/web/static/src/js/core.js
@@ -1233,18 +1233,34 @@ openerp.web.qweb.default_dict = {
'_' : _,
'_t' : openerp.web._t
};
-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 = _.str.trim(s);
- if (ts.length === 0) {
- return s;
+openerp.web.qweb.preprocess_node = function() {
+ // Note that 'this' is the Qweb Node
+ switch (this.node.nodeType) {
+ case 3:
+ case 4:
+ // Text and CDATAs
+ var translation = this.node.parentNode.attributes['t-translation'];
+ if (translation && translation.value === 'off') {
+ return;
+ }
+ var ts = _.str.trim(this.node.data);
+ if (ts.length === 0) {
+ return;
+ }
+ var tr = openerp.web._t(ts);
+ if (tr !== ts) {
+ this.node.data = tr;
+ }
+ break;
+ case 1:
+ // Element
+ var attr, attrs = ['label', 'title', 'alt'];
+ while (attr = attrs.pop()) {
+ if (this.attributes[attr]) {
+ this.attributes[attr] = openerp.web._t(this.attributes[attr]);
+ }
+ }
}
- var tr = openerp.web._t(ts);
- return tr === ts ? s : tr;
};
/** Jquery extentions */