[FIX] template rendering issues in IE8

bzr revid: xmo@openerp.com-20120124101155-b52f8b3jd6otn7j9
This commit is contained in:
Xavier Morel
2012-01-24 11:11:55 +01:00
5 changed files with 52 additions and 30 deletions
@@ -22,11 +22,11 @@
<t t-jquery="hr:eq(1)" t-operation="replace"><footer></footer></t>
</t>
<t t-extend="jquery-extend">
<t t-jquery="footer" t-operation="inner"><b>END</b></t>
<t t-jquery="footer" t-operation="inner"><b>[[end]]</b></t>
</t>
<t t-name="jquery-extend-clone" t-extend="jquery-extend">
<t t-jquery="ul" t-operation="append"><li>CLONED TEMPLATE</li></t>
<t t-jquery="ul" t-operation="append"><li>[[cloned template]]</li></t>
</t>
</templates>
@@ -1,4 +1,4 @@
<templates>
<templates xml:space="preserve">
<t t-name="repetition-text-content" t-foreach="seq">*</t>
<t t-name="repetition-dom-content" t-foreach="seq"><b/></t>
<b t-name="repetition-self" t-foreach="seq"/>
+5 -6
View File
@@ -5,7 +5,6 @@
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen"/>
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script type="text/javascript" src="/base/static/lib/jquery/jquery-1.5.2.js"></script>
<script type="text/javascript" src="qweb2.js"></script>
<script>
@@ -14,7 +13,7 @@
return s.replace(/(^\s+|\s+$)/g, '');
}
function render(template, context) {
return trim(QWeb.render(template, context));
return trim(QWeb.render(template, context)).toLowerCase();
}
$(document).ready(function() {
module("Basic output tests", {
@@ -209,9 +208,9 @@
test('Basic foreach repetition', function () {
equals(QWeb.render('repetition-text-content', {seq:seq}), '*****',
"Repetition of text content via foreach");
equals(QWeb.render('repetition-dom-content', {seq:seq}), '<b/><b/><b/><b/><b/>',
equals(QWeb.render('repetition-dom-content', {seq:seq}).toLowerCase(), '<b/><b/><b/><b/><b/>',
"Repetition of node content via foreach");
equals(QWeb.render('repetition-self', {seq:seq}), '<b/><b/><b/><b/><b/>',
equals(QWeb.render('repetition-self', {seq:seq}).toLowerCase(), '<b/><b/><b/><b/><b/>',
"A node with a foreach repeats itself");
});
test("Foreach scope content", function () {
@@ -249,9 +248,9 @@
});
test("jQuery extend", function () {
equals(render('jquery-extend', {}), '<hr/><ul class="main"><li>1</li><li>2</li><li>3</li></ul><footer><b>END</b></footer>',
equals(render('jquery-extend', {}), '<hr/><ul class="main"><li>1</li><li>2</li><li>3</li></ul><footer><b>[[end]]</b></footer>',
"Extend template with jQuery");
equals(render('jquery-extend-clone', {}), '<ul><li>one</li><li>CLONED TEMPLATE</li></ul>',
equals(render('jquery-extend-clone', {}), '<ul><li>one</li><li>[[cloned template]]</li></ul>',
"Clone template");
});
});
+38 -17
View File
@@ -93,10 +93,16 @@ var QWeb2 = {
}
return r.join('');
} else {
if (node.xml !== undefined) {
return node.xml;
} else {
if (typeof XMLSerializer !== 'undefined') {
return (new XMLSerializer()).serializeToString(node);
} else {
switch(node.nodeType) {
case 1: return node.outerHTML;
case 3: return node.data;
case 4: return '<![CDATA[' + node.data + ']]>';
case 8: return '<!-- ' + node.data + '-->';
}
throw new Error('Unknown node type ' + node.nodeType);
}
}
},
@@ -265,11 +271,16 @@ QWeb2.Engine = (function() {
}
req.open('GET', s, false);
req.send(null);
if (req.responseXML) {
if (req.responseXML.documentElement.nodeName == "parsererror") {
return this.tools.exception(req.responseXML.documentElement.childNodes[0].nodeValue);
var xDoc = req.responseXML;
if (xDoc) {
if (xDoc.documentElement.nodeName == "parsererror") {
return this.tools.exception(xDoc.documentElement.childNodes[0].nodeValue);
}
return req.responseXML;
if (xDoc.xml !== undefined) {
// MSIE
return this.convert_xml_to_html(xDoc.documentElement);
}
return xDoc;
} else {
return this.load_xml_string(req.responseText);
}
@@ -295,7 +306,25 @@ QWeb2.Engine = (function() {
xDoc.async = false;
xDoc.preserveWhiteSpace = true;
xDoc.loadXML(s);
return xDoc;
return this.convert_xml_to_html(xDoc.documentElement);
},
convert_xml_to_html: function (node) {
switch (node.nodeType) {
case 3:
case 4:
return document.createTextNode(node.data);
case 8: return document.createComment(node.data);
}
var hnode = document.createElement(node.nodeName);
for(var i=0, alen=node.attributes.length; i < alen; ++i) {
var attr = node.attributes[i];
hnode.setAttribute(attr.name, attr.value);
}
for(var j=0, clen=node.childNodes.length; j < clen; ++j) {
hnode.appendChild(this.convert_xml_to_html(node.childNodes[j]));
}
return hnode;
},
has_template : function(template) {
return !!this.templates[template];
@@ -373,12 +402,7 @@ QWeb2.Engine = (function() {
if (!this.jQuery) {
return this.tools.exception("Can't extend template " + template + " without jQuery");
}
var template_dest = this.templates[template],
msie_trololo = false;
if (template_dest.xml !== undefined) {
template_dest = this.jQuery(template_dest.xml);
msie_trololo = true;
}
var template_dest = this.templates[template];
for (var i = 0, ilen = extend_node.childNodes.length; i < ilen; i++) {
var child = extend_node.childNodes[i];
if (child.nodeType === 1) {
@@ -421,9 +445,6 @@ QWeb2.Engine = (function() {
}
}
}
if (msie_trololo) {
this.templates[template] = template_dest[0];
}
}
});
return Engine;
+6 -4
View File
@@ -682,7 +682,9 @@
</td>
</t>
<th t-if="options.selectable" class="oe-record-selector" width="1">
<input t-att-type="options.radio? 'radio': 'checkbox'" name ="radiogroup" t-att-checked="options.select_view_id == record.get('id')? true: null"/>
<t t-set="checked" t-value="options.select_view_id == record.get('id') ? 'checked' : null"/>
<input t-if="options.radio" type="radio" name="radiogroup" t-att-checked="checked"/>
<input t-if="!options.radio" type="checkbox" name="radiogroup" t-att-checked="checked"/>
</th>
<th t-if="options.isClarkGable" class="oe-record-edit-link" width="1">
<img src="/web/static/src/img/pencil.gif" width="12" height="12" class="oe-record-edit-link-img"/>
@@ -747,7 +749,7 @@
<input type="file" class="oe-binary-file" name="ufile" title="Add attachment"
t-att-onclick="view.datarecord.id ? null : 'alert(\'No record selected ! You can only attach to existing record.\'); return false;'"/>
</form>
<iframe t-attf-id="#{element_id}_iframe" t-attf-name="#{element_id}_iframe" style="display: none"> </iframe>
<iframe t-attf-id="#{element_id}_iframe" t-attf-name="#{element_id}_iframe" style="display: none"/>
</div>
</div>
<br style="clear: both"/>
@@ -1084,7 +1086,7 @@
<img t-att-src='_s + "/web/static/src/img/throbber.gif"' width="16" height="16"/>
<b>Uploading ...</b>
</div>
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"> </iframe>
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"/>
</td>
</tr>
</table>
@@ -1134,7 +1136,7 @@
<td class="oe-binary-progress" style="display: none" nowrap="true">
<img t-att-src='_s + "/web/static/src/img/throbber.gif"' width="16" height="16"/>
<b>Uploading ...</b>
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"> </iframe>
<iframe t-att-id="widget.iframe" t-att-name="widget.iframe" style="display: none"/>
</td>
</tr>
</table>