[REVERT] reverted 3812 because it's an incorrect way to upgrade an external dependency of OpenERP
bzr revid: nicolas.vanhoren@openerp.com-20130819092940-9vqh5036p7rf2azv
This commit is contained in:
parent
a0bac10130
commit
3210d02d8f
|
@ -226,27 +226,10 @@ QWeb2.Engine = (function() {
|
|||
}
|
||||
|
||||
QWeb2.tools.extend(Engine.prototype, {
|
||||
/**
|
||||
* Add a template to the engine
|
||||
*
|
||||
* @param {String|Document} template Template as string or url or DOM Document
|
||||
* @param {Function} [callback] Called when the template is loaded, force async request
|
||||
*/
|
||||
add_template : function(template, callback) {
|
||||
var self = this;
|
||||
add_template : function(template) {
|
||||
this.templates_resources.push(template);
|
||||
if (template.constructor === String) {
|
||||
return this.load_xml(template, function (err, xDoc) {
|
||||
if (err) {
|
||||
if (callback) {
|
||||
return callback(err);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
self.add_template(xDoc, callback);
|
||||
});
|
||||
template = this.load_xml(template, callback);
|
||||
template = this.load_xml(template);
|
||||
}
|
||||
var ec = (template.documentElement && template.documentElement.childNodes) || template.childNodes || [];
|
||||
for (var i = 0; i < ec.length; i++) {
|
||||
|
@ -279,56 +262,35 @@ QWeb2.Engine = (function() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(null, template);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
load_xml : function(s, callback) {
|
||||
var self = this;
|
||||
var async = !!callback;
|
||||
load_xml : function(s) {
|
||||
s = this.tools.trim(s);
|
||||
if (s.charAt(0) === '<') {
|
||||
var tpl = this.load_xml_string(s);
|
||||
if (callback) {
|
||||
callback(null, tpl);
|
||||
}
|
||||
return tpl;
|
||||
return this.load_xml_string(s);
|
||||
} else {
|
||||
var req = this.get_xhr();
|
||||
if (this.debug) {
|
||||
s += '?debug=' + (new Date()).getTime(); // TODO fme: do it properly in case there's already url parameters
|
||||
}
|
||||
req.open('GET', s, async);
|
||||
if (async) {
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {
|
||||
callback(null, self._parse_from_request(req));
|
||||
} else {
|
||||
callback(new Error("Can't load template, http status " + req.status));
|
||||
}
|
||||
if (req) {
|
||||
// TODO: third parameter is async : https://developer.mozilla.org/en/XMLHttpRequest#open()
|
||||
// do an on_ready in QWeb2{} that could be passed to add_template
|
||||
if (this.debug) {
|
||||
s += '?debug=' + (new Date()).getTime(); // TODO fme: do it properly in case there's already url parameters
|
||||
}
|
||||
req.open('GET', s, false);
|
||||
req.send(null);
|
||||
var xDoc = req.responseXML;
|
||||
if (xDoc) {
|
||||
if (!xDoc.documentElement) {
|
||||
throw new Error("QWeb2: This xml document has no root document : " + xDoc.responseText);
|
||||
}
|
||||
};
|
||||
if (xDoc.documentElement.nodeName == "parsererror") {
|
||||
return this.tools.exception(xDoc.documentElement.childNodes[0].nodeValue);
|
||||
}
|
||||
return xDoc;
|
||||
} else {
|
||||
return this.load_xml_string(req.responseText);
|
||||
}
|
||||
}
|
||||
req.send(null);
|
||||
if (!async) {
|
||||
return this._parse_from_request(req);
|
||||
}
|
||||
}
|
||||
},
|
||||
_parse_from_request: function(req) {
|
||||
var xDoc = req.responseXML;
|
||||
if (xDoc) {
|
||||
if (!xDoc.documentElement) {
|
||||
throw new Error("QWeb2: This xml document has no root document : " + xDoc.responseText);
|
||||
}
|
||||
if (xDoc.documentElement.nodeName == "parsererror") {
|
||||
throw new Error("QWeb2: Could not parse document :" + xDoc.documentElement.childNodes[0].nodeValue);
|
||||
}
|
||||
return xDoc;
|
||||
} else {
|
||||
return this.load_xml_string(req.responseText);
|
||||
}
|
||||
},
|
||||
load_xml_string : function(s) {
|
||||
|
@ -336,15 +298,17 @@ QWeb2.Engine = (function() {
|
|||
var dp = new DOMParser();
|
||||
var r = dp.parseFromString(s, "text/xml");
|
||||
if (r.body && r.body.firstChild && r.body.firstChild.nodeName == 'parsererror') {
|
||||
throw new Error("QWeb2: Could not parse document :" + r.body.innerText);
|
||||
return this.tools.exception(r.body.innerText);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
var xDoc;
|
||||
try {
|
||||
// new ActiveXObject("Msxml2.DOMDocument.4.0");
|
||||
xDoc = new ActiveXObject("MSXML2.DOMDocument");
|
||||
} catch (e) {
|
||||
throw new Error("Could not find a DOM Parser: " + e.message);
|
||||
return this.tools.exception(
|
||||
"Could not find a DOM Parser: " + e.message);
|
||||
}
|
||||
xDoc.async = false;
|
||||
xDoc.preserveWhiteSpace = true;
|
||||
|
@ -361,7 +325,7 @@ QWeb2.Engine = (function() {
|
|||
try {
|
||||
return new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||
} catch (e) {
|
||||
throw new Error("Could not get XHR");
|
||||
return null;
|
||||
}
|
||||
},
|
||||
compile : function(node) {
|
||||
|
|
Loading…
Reference in New Issue