From be34f957230a8df4e557800b69f011c231c95b58 Mon Sep 17 00:00:00 2001 From: nathangray Date: Thu, 23 Aug 2018 15:44:32 -0600 Subject: [PATCH] Add template fetch fallback using egw.link() if template_base_url fails --- api/js/etemplate/et2_core_xml.js | 7 ++++++- api/js/etemplate/et2_widget_template.js | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/api/js/etemplate/et2_core_xml.js b/api/js/etemplate/et2_core_xml.js index 9cf3b06dab..a1a1a6dec0 100644 --- a/api/js/etemplate/et2_core_xml.js +++ b/api/js/etemplate/et2_core_xml.js @@ -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) + } } }); } diff --git a/api/js/etemplate/et2_widget_template.js b/api/js/etemplate/et2_widget_template.js index 7f0519d475..93c5d58416 100644 --- a/api/js/etemplate/et2_widget_template.js +++ b/api/js/etemplate/et2_widget_template.js @@ -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; }