summaryrefslogtreecommitdiff
path: root/addons/web/static/lib
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-07-10 10:09:35 +0000
committerAaron Bohy <aab@odoo.com>2020-07-10 11:53:23 +0000
commitb558cb7996b1de385f6bf7cb3918f0e37cee69fe (patch)
treecc76f041e70b3cd9bc21a58ec0223113b7a67ebb /addons/web/static/lib
parente00361997ba79639a2c5701bd6c2191400732028 (diff)
[FIX] web: qweb old inheritance mechanism
Before this commit, defining a extension of a template by using the combination of directives 't-name' and 't-extend' ignored potential extensions that could have been defined beforehand. For instance, let's assume the following templates. ```xml <t t-name="a"> <div><span>1</span></div> </t> <t t-extend="a"> <t t-jquery="span" t-operation="replace"> <span>2</span> </t> </t> <t t-name="b" t-extend="a"> <t t-jquery="div" t-operation="append"> <span>b</span> </t> </t> ``` Rendering template "b" displayed "1b" whereas we would expect "2b". Moreover, when the extended template is itself an extension of another template: ```xml <t t-name="a"> <div><span>a</span></div> </t> <t t-name="b" t-extend="a"> <t t-jquery="div" t-operation="append"> <span>b</span> </t> </t> <t t-name="c" t-extend="b"> <t t-jquery="div" t-operation="append"> <span>c</span> </t> </t> ``` Rendering template "a" displayed "a", template "b" displayed "ab", but template "c" displayed "ac", whereas we would expect "abc". With this commit, other extensions done to a template are kept when a new extension is defined. It relies on the templates order, and takes into account all extensions that have *already* been defined. This is exactly how the new qweb inheritance mechanism (using 't-inherit' and 't-inherit-mode') behaves. closes odoo/odoo#54315 Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
Diffstat (limited to 'addons/web/static/lib')
-rw-r--r--addons/web/static/lib/qweb/qweb-test-extend.xml21
-rw-r--r--addons/web/static/lib/qweb/qweb2.js1
2 files changed, 21 insertions, 1 deletions
diff --git a/addons/web/static/lib/qweb/qweb-test-extend.xml b/addons/web/static/lib/qweb/qweb-test-extend.xml
index dfd0ec46940..f8a24c4ef8e 100644
--- a/addons/web/static/lib/qweb/qweb-test-extend.xml
+++ b/addons/web/static/lib/qweb/qweb-test-extend.xml
@@ -37,7 +37,26 @@
<t t-jquery="ul" t-operation="append"><li>[[cloned template]]</li></t>
</t>
<result id="jquery-extend-clone"><![CDATA[
- <ul><li>one</li><li>[[cloned template]]</li></ul>
+ <hr/><ul class="main" title="Main Title" name="main-ul"><li>1</li><li>2</li><li>3</li><li>[[cloned template]]</li></ul><footer><b>[[end]]</b></footer>
]]></result>
+
+ <t t-name="a">
+ <div><span>Hi</span></div>
+ </t>
+ <t t-name="b" t-extend="a">
+ <t t-jquery="span" t-operation="after"><i>World</i></t>
+ </t>
+ <t t-name="c" t-extend="b">
+ <t t-jquery="span" t-operation="replace"><span>Hello</span></t>
+ </t>
+ <result id="a"><![CDATA[
+ <div><span>Hi</span></div>
+]]></result>
+ <result id="b"><![CDATA[
+ <div><span>Hi</span><i>World</i></div>
+]]></result>
+ <result id="c"><![CDATA[
+ <div><span>Hello</span><i>World</i></div>
+]]></result>
</templates>
diff --git a/addons/web/static/lib/qweb/qweb2.js b/addons/web/static/lib/qweb/qweb2.js
index 2cfd2286cbc..d2a367f1c33 100644
--- a/addons/web/static/lib/qweb/qweb2.js
+++ b/addons/web/static/lib/qweb/qweb2.js
@@ -268,6 +268,7 @@ QWeb2.Engine = (function() {
return this.tools.exception("Can't clone undefined template " + extend);
}
this.templates[name] = this.templates[extend].cloneNode(true);
+ this.extend_templates[name] = (this.extend_templates[extend] || []).slice();
extend = name;
name = undefined;
}