mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-10-06 18:12:22 +02:00
114 lines
2.7 KiB
JavaScript
114 lines
2.7 KiB
JavaScript
/**
|
|
* eGroupWare eTemplate2 - JS file which contains the complete et2 module
|
|
*
|
|
* @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$
|
|
*/
|
|
|
|
/*egw:uses
|
|
// Include all widget classes here
|
|
et2_template;
|
|
et2_grid;
|
|
et2_box;
|
|
et2_button;
|
|
et2_description;
|
|
et2_textbox;
|
|
|
|
// Requirements for the etemplate2 object
|
|
et2_xml;
|
|
et2_arrayMgr;
|
|
*/
|
|
|
|
/**
|
|
* The etemplate2 class manages a certain etemplate2 instance.
|
|
*
|
|
* @param _container is the DOM-Node into which the DOM-Nodes of this instance
|
|
* should be inserted
|
|
* @param _submitURL is the URL to which the form data should be submitted.
|
|
*/
|
|
function etemplate2(_container, _submitURL)
|
|
{
|
|
// Copy the given parameters
|
|
this.DOMContainer = _container;
|
|
this.submitURL = _submitURL;
|
|
|
|
// Preset the object variable
|
|
this.widgetContainer = null;
|
|
}
|
|
|
|
/**
|
|
* Clears the current instance.
|
|
*/
|
|
etemplate2.prototype.clear = function()
|
|
{
|
|
if (this.widgetContainer != null)
|
|
{
|
|
this.widgetContainer.destroy();
|
|
this.widgetContainer = null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Creates an associative array containing the data array managers for each part
|
|
* of the associative data array. A part is something like "content", "readonlys"
|
|
* or "sel_options".
|
|
*/
|
|
etemplate2.prototype._createArrayManagers = function(_data)
|
|
{
|
|
if (typeof _data == "undefined")
|
|
{
|
|
_data = {};
|
|
}
|
|
|
|
// Create all neccessary _data entries
|
|
var neededEntries = ["content", "readonlys", "validation_errors"];
|
|
for (var i = 0; i < neededEntries.length; i++)
|
|
{
|
|
if (typeof _data[neededEntries[i]] == "undefined")
|
|
{
|
|
et2_debug("info", "Created not passed entry '" + neededEntries[i] + "' in data array.");
|
|
_data[neededEntries[i]] = {};
|
|
}
|
|
}
|
|
|
|
var result = {};
|
|
|
|
// Create an array manager object for each part of the _data array.
|
|
for (var key in _data)
|
|
{
|
|
result[key] = new et2_arrayMgr(_data[key]);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Loads the template from the given URL and sets the data object
|
|
*/
|
|
etemplate2.prototype.load = function(_url, _data)
|
|
{
|
|
// Asynchronously load the XET file (code below is executed ahead of the
|
|
// code in the callback function)
|
|
et2_loadXMLFromURL(_url, function(_xmldoc) {
|
|
this.widgetContainer.loadFromXML(_xmldoc);
|
|
}, this);
|
|
|
|
// Clear any existing instance
|
|
this.clear();
|
|
|
|
// Create the basic widget container and attach it to the DOM
|
|
this.widgetContainer = new et2_container(null);
|
|
this.widgetContainer.setParentDOMNode(this.DOMContainer);
|
|
|
|
// Split the given data into array manager objects and pass those to the
|
|
// widget container
|
|
this.widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
|
}
|
|
|
|
|