summaryrefslogtreecommitdiff
path: root/addons/web/static/lib/qweb/qweb2.js
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2014-10-15 17:45:37 +0200
committerFabien Meghazi <fme@openerp.com>2014-10-16 10:25:57 +0200
commit75dfa9a3564a487a60635f87fb54e7a6f8be628d (patch)
tree6ca34d7754bb15cd59ad3b66866a02d2e6c925ca /addons/web/static/lib/qweb/qweb2.js
parente9587bf1309dcaa45f816a1dd603ed01b8f6faaf (diff)
[ADD] QWeb2: add support for operation='attributes' in a t-extend
Same syntax as server's position='attributes' on view inheritance
Diffstat (limited to 'addons/web/static/lib/qweb/qweb2.js')
-rw-r--r--addons/web/static/lib/qweb/qweb2.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 0994ae250cb..2fbef19000a 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -414,7 +414,8 @@ QWeb2.Engine = (function() {
}
},
extend : function(template, extend_node) {
- if (!this.jQuery) {
+ var jQuery = this.jQuery;
+ if (!jQuery) {
return this.tools.exception("Can't extend template " + template + " without jQuery");
}
var template_dest = this.templates[template];
@@ -426,18 +427,25 @@ QWeb2.Engine = (function() {
target,
error_msg = "Error while extending template '" + template;
if (jquery) {
- target = this.jQuery(jquery, template_dest);
+ target = jQuery(jquery, template_dest);
} else {
this.tools.exception(error_msg + "No expression given");
}
error_msg += "' (expression='" + jquery + "') : ";
if (operation) {
- var allowed_operations = "append,prepend,before,after,replace,inner".split(',');
+ var allowed_operations = "append,prepend,before,after,replace,inner,attributes".split(',');
if (this.tools.arrayIndexOf(allowed_operations, operation) == -1) {
this.tools.exception(error_msg + "Invalid operation : '" + operation + "'");
}
operation = {'replace' : 'replaceWith', 'inner' : 'html'}[operation] || operation;
- target[operation](child.cloneNode(true).childNodes);
+ if (operation === 'attributes') {
+ jQuery('attribute', child).each(function () {
+ var attrib = jQuery(this);
+ target.attr(attrib.attr('name'), attrib.text());
+ });
+ } else {
+ target[operation](child.cloneNode(true).childNodes);
+ }
} else {
try {
var f = new Function(['$', 'document'], this.tools.xml_node_to_string(child, true));
@@ -445,7 +453,7 @@ QWeb2.Engine = (function() {
return this.tools.exception("Parse " + error_msg + error);
}
try {
- f.apply(target, [this.jQuery, template_dest.ownerDocument]);
+ f.apply(target, [jQuery, template_dest.ownerDocument]);
} catch(error) {
return this.tools.exception("Runtime " + error_msg + error);
}