share loaded eTemplates with iframes and popups, this way they dont need to load templates in same EGroupware session again (unless main window get reloaded), also adding now a cache-buster by default, if server dont supply one

This commit is contained in:
Ralf Becker 2015-01-23 14:32:47 +00:00
parent d56b92af8b
commit cf61d38137
2 changed files with 25 additions and 22 deletions

View File

@ -88,7 +88,7 @@ var et2_template = et2_DOMWidget.extend(
// Check to see if XML is known // Check to see if XML is known
var xml = null; var xml = null;
var templates = etemplate2.prototype.templates || this.getRoot().getInstanceManager().templates; var templates = etemplate2.prototype.templates; // use global eTemplate cache
if(!(xml = templates[template_name])) if(!(xml = templates[template_name]))
{ {
// Check to see if ID is short form --> prepend parent/top-level name // Check to see if ID is short form --> prepend parent/top-level name
@ -105,12 +105,13 @@ var et2_template = et2_DOMWidget.extend(
var splitted = template_name.split('.'); var splitted = template_name.split('.');
// use template base url from initial template, to continue using webdav, if that was loaded via webdav // use template base url from initial template, to continue using webdav, if that was loaded via webdav
var path = this.getRoot()._inst.template_base_url + splitted.shift() + "/templates/default/" + var path = this.getRoot()._inst.template_base_url + splitted.shift() + "/templates/default/" +
splitted.join('.')+ ".xet" + (cache_buster ? '?'+cache_buster : ''); splitted.join('.')+ ".xet" + (cache_buster ? '?'+cache_buster :
// if server did not give a cache-buster, fall back to current time
'?download='+(new Date).valueOf());
if(splitted.length) if(splitted.length)
{ {
et2_loadXMLFromURL(path, function(_xmldoc) { et2_loadXMLFromURL(path, function(_xmldoc) {
var templates = this.getInstanceManager().templates || {};
// Scan for templates and store them // Scan for templates and store them
for(var i = 0; i < _xmldoc.childNodes.length; i++) { for(var i = 0; i < _xmldoc.childNodes.length; i++) {
var template = _xmldoc.childNodes[i]; var template = _xmldoc.childNodes[i];

View File

@ -100,25 +100,40 @@ function etemplate2(_container, _menuaction)
} }
// List of templates (XML) that are known, not always used. Indexed by id. // List of templates (XML) that are known, not always used. Indexed by id.
etemplate2.prototype.templates = {}; // We share list of templates with iframes and popups
try {
if (opener && opener.etemplate2)
{
etemplate2.prototype.templates = opener.etemplate2.prototype.templates;
}
}
catch (e) {
// catch security exception if opener is from a different domain
}
if (typeof etemplate2.prototype.templates == "undefined")
{
etemplate2.prototype.templates = top.etemplate2.prototype.templates || {};
}
/** /**
* Calls the resize event of all widgets * Calls the resize event of all widgets
*
* @param {jQuery.event} e
*/ */
etemplate2.prototype.resize = function(e) etemplate2.prototype.resize = function(e)
{ {
var event = e; var event = e;
var self = this; var self = this;
var excess_height = false; var excess_height = false;
// Check if the framework has an specific excess height calculation // Check if the framework has an specific excess height calculation
if (typeof window.framework != 'undefined' && typeof window.framework.get_wExcessHeight != 'undefined') if (typeof window.framework != 'undefined' && typeof window.framework.get_wExcessHeight != 'undefined')
{ {
excess_height = window.framework.get_wExcessHeight(window); excess_height = window.framework.get_wExcessHeight(window);
} }
//@TODO implement getaccess height for other framework and remove //@TODO implement getaccess height for other framework and remove
if (typeof event != 'undefined' && event.type == 'resize') if (typeof event != 'undefined' && event.type == 'resize')
{ {
setTimeout(function(){ setTimeout(function(){
@ -180,19 +195,6 @@ etemplate2.prototype.clear = function()
this.widgetContainer = null; this.widgetContainer = null;
} }
$j(this.DOMContainer).empty(); $j(this.DOMContainer).empty();
// Remove self from the index
for(name in this.templates)
{
if(typeof etemplate2._byTemplate[name] == "undefined") continue;
for(var i = 0; i < etemplate2._byTemplate[name].length; i++)
{
if(etemplate2._byTemplate[name][i] == this)
{
etemplate2._byTemplate[name].splice(i,1);
}
}
}
}; };
/** /**
@ -448,7 +450,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
// Wait for everything to be loaded, then finish it up // Wait for everything to be loaded, then finish it up
jQuery.when.apply(jQuery, deferred).done(jQuery.proxy(function() { jQuery.when.apply(jQuery, deferred).done(jQuery.proxy(function() {
egw.debug("log", "Finished loading %s, triggering load event", _name); egw.debug("log", "Finished loading %s, triggering load event", _name);
if (typeof window.framework != 'undefined' && typeof window.framework.et2_loadingFinished != 'undefined') if (typeof window.framework != 'undefined' && typeof window.framework.et2_loadingFinished != 'undefined')
{ {
//Call loading finished method of the framework with local window //Call loading finished method of the framework with local window
@ -469,7 +471,7 @@ etemplate2.prototype.load = function(_name, _url, _data, _callback)
return !$this.attr('tabindex') || $this.attr('tabIndex')>=0; return !$this.attr('tabindex') || $this.attr('tabIndex')>=0;
}).first().focus(); }).first().focus();
}; };
// Tell others about it // Tell others about it
if(typeof _callback == "function") if(typeof _callback == "function")
{ {