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
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_xml;
|
|
|
|
et2_core_DOMWidget;
|
2011-08-05 16:53:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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": {
|
2011-09-28 01:44:07 +02:00
|
|
|
"name": "Template",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Name / ID of template"
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
"group": {
|
2011-09-28 01:44:07 +02:00
|
|
|
// TODO: Not implemented
|
|
|
|
"name": "Group",
|
|
|
|
"description":"Not implemented",
|
|
|
|
"default": 0
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
"version": {
|
|
|
|
"name": "Version",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Version of the template"
|
|
|
|
},
|
|
|
|
"lang": {
|
|
|
|
"name": "Language",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Language the template is written in"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
createNamespace: true,
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
/**
|
|
|
|
* Initializes this template widget as a simple container.
|
|
|
|
*/
|
2011-08-24 12:05:52 +02:00
|
|
|
init: function() {
|
2011-08-19 18:00:44 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
this.div = document.createElement("div");
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
if (this.id != "")
|
|
|
|
{
|
2012-03-02 11:44:56 +01:00
|
|
|
// Set the api instance to the first part of the name of the
|
2012-03-20 22:42:25 +01:00
|
|
|
// template, if it's in app.function.template format
|
2012-03-02 11:44:56 +01:00
|
|
|
var splitted = this.id.split('.');
|
2012-03-20 22:42:25 +01:00
|
|
|
if(splitted.length == 3)
|
|
|
|
{
|
|
|
|
this.setApiInstance(egw(splitted[0], this._parent.egw().window));
|
|
|
|
}
|
2012-03-02 11:44:56 +01:00
|
|
|
|
2012-03-14 22:27:23 +01:00
|
|
|
// Check to see if XML is known
|
|
|
|
var xml = null;
|
|
|
|
var templates = this.getRoot().getInstanceManager().templates;
|
|
|
|
if(!(xml = templates[this.id]))
|
2011-08-05 16:53:54 +02:00
|
|
|
{
|
2012-03-14 22:27:23 +01:00
|
|
|
// Check to see if ID is short form
|
|
|
|
// eg: row instead of app.something.row
|
|
|
|
for(var key in templates)
|
2011-08-05 16:53:54 +02:00
|
|
|
{
|
2012-03-14 22:27:23 +01:00
|
|
|
splitted = key.split('.');
|
|
|
|
if(splitted[splitted.length-1] == this.id)
|
|
|
|
{
|
|
|
|
xml = templates[key];
|
|
|
|
break;
|
|
|
|
}
|
2011-08-05 16:53:54 +02:00
|
|
|
}
|
|
|
|
}
|
2012-03-14 22:27:23 +01:00
|
|
|
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);
|
|
|
|
}
|
2011-08-05 16:53:54 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
getDOMNode: function() {
|
2011-08-05 16:53:54 +02:00
|
|
|
return this.div;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
et2_register_widget(et2_template, ["template"]);
|
|
|
|
|
|
|
|
|