mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-08 09:05:16 +01:00
Don't proxy template, just don't load it until asked for
This commit is contained in:
parent
e5b4bcfe7f
commit
0aa4c66803
@ -167,7 +167,7 @@ class etemplate_new extends etemplate_widget_template
|
||||
egw.langRequire(window, '.json_encode($langRequire).');
|
||||
egw(window).ready(function() {
|
||||
var et2 = new etemplate2(document.getElementById("container"), "etemplate_new::ajax_process_content");
|
||||
et2.load("'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
||||
et2.load("'.$this->name.'","'.$GLOBALS['egw_info']['server']['webserver_url'].$this->rel_path.'",'.json_encode($data).');
|
||||
}, null, true);
|
||||
</script>
|
||||
';
|
||||
|
@ -664,15 +664,15 @@ var et2_nextmatch = et2_DOMWidget.extend(et2_IResizeable, {
|
||||
// Load the template
|
||||
var template = et2_createWidget("template", {"id": _value}, this);
|
||||
|
||||
if (!template.proxiedTemplate)
|
||||
if (!template)
|
||||
{
|
||||
this.egw().debug("error", "Error while loading definition template for" +
|
||||
"nextmatch widget.");
|
||||
this.egw().debug("error", "Error while loading definition template for " +
|
||||
"nextmatch widget.",_value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the grid element and parse it
|
||||
var definitionGrid = template.proxiedTemplate.getChildren()[0];
|
||||
var definitionGrid = template.getChildren()[0];
|
||||
if (definitionGrid && definitionGrid instanceof et2_grid)
|
||||
{
|
||||
this._parseGrid(definitionGrid);
|
||||
|
@ -59,10 +59,6 @@ var et2_template = et2_DOMWidget.extend({
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
this.proxiedTemplate = null;
|
||||
this.isProxied = false;
|
||||
this.isProxy = false;
|
||||
|
||||
this.div = document.createElement("div");
|
||||
|
||||
if (this.id != "")
|
||||
@ -72,85 +68,40 @@ var et2_template = et2_DOMWidget.extend({
|
||||
var splitted = this.id.split('.');
|
||||
this.setApiInstance(egw(splitted[0], this._parent.egw().window));
|
||||
|
||||
this.createProxy();
|
||||
}
|
||||
},
|
||||
|
||||
createProxy: function() {
|
||||
// Check whether a template with the given name already exists and
|
||||
// is not a proxy.
|
||||
var tmpl = this.getRoot().getWidgetById(this.id);
|
||||
if (tmpl instanceof et2_template && tmpl.proxiedTemplate == null &&
|
||||
tmpl != this)
|
||||
{
|
||||
// Detatch the proxied template from the DOM to and set its
|
||||
// isProxied property to true
|
||||
tmpl.makeProxied();
|
||||
|
||||
// Do not copy the id when cloning as this leads to infinit
|
||||
// recursion
|
||||
tmpl.options.id = "";
|
||||
|
||||
// Create a clone of the template and add it as child of this
|
||||
// template (done by passing "this" to the clone function)
|
||||
this.proxiedTemplate = tmpl.clone(this);
|
||||
|
||||
// Reset the id and manually copy the id to the proxied template
|
||||
tmpl.options.id = this.id;
|
||||
this.proxiedTemplate.id = tmpl.id;
|
||||
this.proxiedTemplate.isProxy = true;
|
||||
|
||||
// Disallow adding any new node to this template
|
||||
this.supportedWidgetClasses = [];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* If the parent node is changed, either the DOM-Node of the proxied template
|
||||
* or the DOM-Node of this template is connected to the parent DOM-Node.
|
||||
*/
|
||||
doLoadingFinished: function() {
|
||||
// Check whether the parent implements the et2_IDOMNode interface.
|
||||
if (this._parent && this._parent.implements(et2_IDOMNode)) {
|
||||
var parentNode = this._parent.getDOMNode(this);
|
||||
|
||||
if (parentNode)
|
||||
// Check to see if XML is known
|
||||
var xml = null;
|
||||
var templates = this.getRoot().getInstanceManager().templates;
|
||||
if(!(xml = templates[this.id]))
|
||||
{
|
||||
if (this.proxiedTemplate)
|
||||
// Check to see if ID is short form
|
||||
// eg: row instead of app.something.row
|
||||
for(var key in templates)
|
||||
{
|
||||
this.proxiedTemplate.setParentDOMNode(parentNode);
|
||||
this.proxiedTemplate.loadingFinished();
|
||||
return false;
|
||||
}
|
||||
else if (!this.isProxied && !this.isProxy)
|
||||
{
|
||||
this.setParentDOMNode(parentNode);
|
||||
splitted = key.split('.');
|
||||
if(splitted[splitted.length-1] == this.id)
|
||||
{
|
||||
xml = templates[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(xml !== null && typeof xml !== "undefined")
|
||||
{
|
||||
this.egw().debug("info", "Loading template from XML: ", this.id);
|
||||
this.loadFromXML(xml);
|
||||
// Don't call this here - premature
|
||||
//this.loadingFinished();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.egw().debug("warn", "Unable to find XML for ", this.id);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
makeProxied: function() {
|
||||
if (!this.isProxied)
|
||||
{
|
||||
this.detatchFromDOM();
|
||||
this.div = null;
|
||||
this.parentNode = null;
|
||||
}
|
||||
|
||||
this.isProxied = true;
|
||||
},
|
||||
|
||||
getDOMNode: function() {
|
||||
return this.div;
|
||||
},
|
||||
|
||||
isInTree: function(_sender) {
|
||||
return this._super(this, !this.isProxied);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
et2_register_widget(et2_template, ["template"]);
|
||||
|
@ -72,6 +72,9 @@ function etemplate2(_container, _menuaction)
|
||||
// Preset the object variable
|
||||
this.widgetContainer = null;
|
||||
|
||||
// List of templates (XML) that are known, but not used. Indexed by id.
|
||||
this.templates = {};
|
||||
|
||||
// Connect to the window resize event
|
||||
$j(window).resize(this, function(e) {e.data.resize()});
|
||||
}
|
||||
@ -102,6 +105,7 @@ etemplate2.prototype.clear = function()
|
||||
this.widgetContainer.free();
|
||||
this.widgetContainer = null;
|
||||
}
|
||||
this.templates = {};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,7 +156,7 @@ etemplate2.prototype._createArrayManagers = function(_data)
|
||||
/**
|
||||
* Loads the template from the given URL and sets the data object
|
||||
*/
|
||||
etemplate2.prototype.load = function(_url, _data)
|
||||
etemplate2.prototype.load = function(_name, _url, _data)
|
||||
{
|
||||
// Create the document fragment into which the HTML will be injected
|
||||
var frag = document.createDocumentFragment();
|
||||
@ -161,8 +165,15 @@ etemplate2.prototype.load = function(_url, _data)
|
||||
// code in the callback function)
|
||||
et2_loadXMLFromURL(_url, function(_xmldoc) {
|
||||
|
||||
// Read the XML structure
|
||||
this.widgetContainer.loadFromXML(_xmldoc);
|
||||
// Scan for templates and store them
|
||||
for(var i = 0; i < _xmldoc.childNodes.length; i++) {
|
||||
var template = _xmldoc.childNodes[i];
|
||||
if(template.nodeName.toLowerCase() != "template") continue;
|
||||
this.templates[template.getAttribute("id")] = template;
|
||||
}
|
||||
|
||||
// Read the XML structure of the requested template
|
||||
this.widgetContainer.loadFromXML(this.templates[_name]);
|
||||
|
||||
// Inform the widget tree that it has been successfully loaded.
|
||||
this.widgetContainer.loadingFinished();
|
||||
|
Loading…
Reference in New Issue
Block a user