Add template fetch fallback using egw.link() if template_base_url fails

This commit is contained in:
nathangray 2018-08-23 15:44:32 -06:00
parent 13941bb0e6
commit be34f95723
2 changed files with 17 additions and 4 deletions

View File

@ -19,8 +19,9 @@
* @param {string} _url
* @param {function} _callback function(_xml)
* @param {object} _context for _callback
* @param {function} _fail_callback function(_xml)
*/
function et2_loadXMLFromURL(_url, _callback, _context)
function et2_loadXMLFromURL(_url, _callback, _context, _fail_callback)
{
if (typeof _context == "undefined")
{
@ -52,6 +53,10 @@ function et2_loadXMLFromURL(_url, _callback, _context)
},
error: function(_xmlhttp, _err) {
egw().debug('error', 'Loading eTemplate from '+_url+' failed! '+_xmlhttp.status+' '+_xmlhttp.statusText);
if(typeof _fail_callback !== 'undefined')
{
_fail_callback.call(_context, _err)
}
}
});
}

View File

@ -117,8 +117,9 @@ var et2_template = (function(){ "use strict"; return et2_DOMWidget.extend(
if (!this.options.url)
{
var splitted = template_name.split('.');
var app = splitted.shift();
// use template base url from initial template, to continue using webdav, if that was loaded via webdav
url = this.getRoot()._inst.template_base_url + splitted.shift() + "/templates/default/" +
url = this.getRoot()._inst.template_base_url + app + "/templates/default/" +
splitted.join('.')+ ".xet" + (cache_buster ? '?download='+cache_buster : '');
}
// if server did not give a cache-buster, fall back to current time
@ -126,7 +127,7 @@ var et2_template = (function(){ "use strict"; return et2_DOMWidget.extend(
if(this.options.url || splitted.length)
{
et2_loadXMLFromURL(url, function(_xmldoc) {
var fetch_url_callback = function(_xmldoc) {
// Scan for templates and store them
for(var i = 0; i < _xmldoc.childNodes.length; i++) {
var template = _xmldoc.childNodes[i];
@ -140,7 +141,14 @@ var et2_template = (function(){ "use strict"; return et2_DOMWidget.extend(
// Update flag
this.loading.resolve();
}, this);
}
et2_loadXMLFromURL(url, fetch_url_callback, this, function( error) {
url = egw.link('/'+ app + "/templates/default/" +
splitted.join('.')+ ".xet", {download:cache_buster? cache_buster :(new Date).valueOf()});
et2_loadXMLFromURL(url, fetch_url_callback, this);
});
}
return;
}