2011-08-05 16:53:54 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Template base class
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel
|
|
|
|
* @copyright Stylite 2011
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2011-08-07 15:43:46 +02:00
|
|
|
"use strict";
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
/*egw:uses
|
|
|
|
et2_widget;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class which implements the "template" XET-Tag. When the id parameter is set,
|
|
|
|
* the template class checks whether another template with this id already
|
|
|
|
* exists. If yes, this template is removed from the DOM tree, copied and
|
|
|
|
* inserted in place of this template.
|
|
|
|
*
|
|
|
|
* TODO: Check whether this widget behaves as it should.
|
|
|
|
*/
|
2011-08-07 15:43:46 +02:00
|
|
|
var et2_template = et2_DOMWidget.extend({
|
2011-08-05 16:53:54 +02:00
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
attributes: {
|
|
|
|
"template": {
|
|
|
|
},
|
|
|
|
"group": {
|
|
|
|
},
|
|
|
|
"version": {
|
|
|
|
"name": "Version",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Version of the template"
|
|
|
|
},
|
|
|
|
"lang": {
|
|
|
|
"name": "Language",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Language the template is written in"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
/**
|
|
|
|
* Initializes this template widget as a simple container.
|
|
|
|
*/
|
|
|
|
init: function(_parent) {
|
|
|
|
this.proxiedTemplate = null;
|
|
|
|
this.isProxied = false;
|
|
|
|
|
|
|
|
this.div = document.createElement("div");
|
2011-08-10 16:36:31 +02:00
|
|
|
this.id = "";
|
2011-08-05 16:53:54 +02:00
|
|
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
onSetParent: function() {
|
|
|
|
// Check whether the parent implements the et2_IDOMNode interface. If
|
|
|
|
// yes, grab the DOM node and create our own.
|
|
|
|
if (this._parent && this._parent.implements(et2_IDOMNode)) {
|
2011-08-06 16:36:44 +02:00
|
|
|
var parentNode = this._parent.getDOMNode(this);
|
2011-08-05 16:53:54 +02:00
|
|
|
|
|
|
|
if (parentNode)
|
|
|
|
{
|
|
|
|
if (this.proxiedTemplate)
|
|
|
|
{
|
|
|
|
this.proxiedTemplate.setParentDOMNode(parentNode);
|
|
|
|
}
|
|
|
|
else if (!this.isProxied)
|
|
|
|
{
|
|
|
|
this.setParentDOMNode(parentNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
makeProxied: function() {
|
|
|
|
if (!this.isProxied)
|
|
|
|
{
|
|
|
|
this.detatchFromDOM();
|
|
|
|
this.div = null;
|
|
|
|
this.parentNode = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.isProxied = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
set_id: function(_value) {
|
|
|
|
if (_value != this.id)
|
|
|
|
{
|
|
|
|
// Check whether a template with the given name already exists and
|
|
|
|
// is not a proxy.
|
|
|
|
var tmpl = this.getRoot().getWidgetById(_value);
|
|
|
|
if (tmpl instanceof et2_template && tmpl.proxiedTemplate == null &&
|
|
|
|
tmpl != this)
|
|
|
|
{
|
|
|
|
// Check whether we still have a proxied template, if yes,
|
|
|
|
// destroy it
|
|
|
|
if (this.proxiedTemplate != null)
|
|
|
|
{
|
|
|
|
this.proxiedTemplate.destroy();
|
|
|
|
this.proxiedTemplate = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This element does not have a node in the tree
|
|
|
|
this.detatchFromDOM();
|
|
|
|
|
|
|
|
// Detatch the proxied template from the DOM to and set its
|
|
|
|
// isProxied property to true
|
|
|
|
tmpl.makeProxied();
|
|
|
|
|
2011-08-10 18:23:02 +02:00
|
|
|
// Do not copy the id when cloning as this leads to infinit
|
|
|
|
// recursion
|
|
|
|
tmpl.attributes["id"].ignore = true;
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
// 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);
|
|
|
|
|
2011-08-10 18:23:02 +02:00
|
|
|
// Reset the "ignore" flag and manually copy the id
|
|
|
|
tmpl.attributes["id"].ignore = false;
|
|
|
|
this.proxiedTemplate.id = tmpl.id;
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
// Disallow adding any new node to this template
|
|
|
|
this.supportedWidgetClasses = [];
|
|
|
|
|
|
|
|
// Call the parent change event function
|
|
|
|
this.onSetParent();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._super(_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getDOMNode: function(_fromProxy) {
|
|
|
|
return this.div;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_template, ["template"]);
|
|
|
|
|
|
|
|
|