2011-08-04 21:08:50 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Widget base class
|
2011-08-04 21:08:50 +02:00
|
|
|
*
|
|
|
|
* @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-04 21:08:50 +02:00
|
|
|
/*egw:uses
|
2011-08-23 19:10:56 +02:00
|
|
|
jsapi.egw;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_xml;
|
|
|
|
et2_core_common;
|
|
|
|
et2_core_inheritance;
|
|
|
|
et2_core_arrayMgr;
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The registry contains all XML tag names and the corresponding widget
|
|
|
|
* constructor.
|
|
|
|
*/
|
|
|
|
var et2_registry = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers the widget class defined by the given constructor and associates it
|
|
|
|
* with the types in the _types array.
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {function} _constructor constructor
|
|
|
|
* @param {array} _types widget types _constructor wants to register for
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
|
|
|
function et2_register_widget(_constructor, _types)
|
|
|
|
{
|
|
|
|
// Iterate over all given types and register those
|
2011-08-05 16:53:54 +02:00
|
|
|
for (var i = 0; i < _types.length; i++)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
|
|
|
var type = _types[i].toLowerCase();
|
|
|
|
|
|
|
|
// Check whether a widget has already been registered for one of the
|
|
|
|
// types.
|
|
|
|
if (et2_registry[type])
|
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
egw.debug("warn", "Widget class registered for " + type +
|
2011-08-04 21:08:50 +02:00
|
|
|
" will be overwritten.");
|
|
|
|
}
|
|
|
|
|
|
|
|
et2_registry[type] = _constructor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 11:45:45 +02:00
|
|
|
/**
|
|
|
|
* Creates a widget registered for the given tag-name. If "readonly" is listed
|
|
|
|
* inside the attributes, et2_createWidget will try to use the "_ro" type of the
|
|
|
|
* widget.
|
|
|
|
*
|
|
|
|
* @param _name is the name of the widget with which it is registered. If the
|
|
|
|
* widget is not found, an et2_placeholder will be created.
|
|
|
|
* @param _attrs is an associative array with attributes. If not passed, it will
|
2013-02-07 15:36:19 +01:00
|
|
|
* default to an empty object.
|
2011-08-23 11:45:45 +02:00
|
|
|
* @param _parent is the parent to which the element will be attached. If _parent
|
|
|
|
* is not passed, it will default to null. Then you have to attach the element
|
|
|
|
* to a parent using the addChild or insertChild method.
|
|
|
|
*/
|
|
|
|
function et2_createWidget(_name, _attrs, _parent)
|
|
|
|
{
|
|
|
|
if (typeof _attrs == "undefined")
|
|
|
|
{
|
|
|
|
_attrs = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof _parent == "undefined")
|
|
|
|
{
|
|
|
|
_parent = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the "readonly" and "type" flag for this element here, as they
|
|
|
|
// determine which constructor is used
|
|
|
|
var nodeName = _attrs["type"] = _name;
|
2014-01-21 15:39:51 +01:00
|
|
|
var readonly = _attrs["readonly"] =
|
2011-08-23 11:45:45 +02:00
|
|
|
typeof _attrs["readonly"] == "undefined" ? false : _attrs["readonly"];
|
|
|
|
|
|
|
|
// Get the constructor - if the widget is readonly, use the special "_ro"
|
|
|
|
// constructor if it is available
|
|
|
|
var constructor = typeof et2_registry[nodeName] == "undefined" ?
|
|
|
|
et2_placeholder : et2_registry[nodeName];
|
|
|
|
if (readonly && typeof et2_registry[nodeName + "_ro"] != "undefined")
|
|
|
|
{
|
|
|
|
constructor = et2_registry[nodeName + "_ro"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do an sanity check for the attributes
|
|
|
|
constructor.prototype.generateAttributeSet(_attrs);
|
|
|
|
|
|
|
|
// Create the new widget and return it
|
|
|
|
return new constructor(_parent, _attrs);
|
|
|
|
}
|
|
|
|
|
2011-08-04 21:08:50 +02:00
|
|
|
/**
|
|
|
|
* The et2 widget base class.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2014-03-20 10:40:37 +01:00
|
|
|
* @augments ClassWithAttributes
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
2014-03-20 10:40:37 +01:00
|
|
|
var et2_widget = ClassWithAttributes.extend(
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2011-08-10 16:36:31 +02:00
|
|
|
attributes: {
|
|
|
|
"id": {
|
|
|
|
"name": "ID",
|
|
|
|
"type": "string",
|
2011-08-10 19:44:22 +02:00
|
|
|
"description": "Unique identifier of the widget"
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
|
2011-08-23 19:05:05 +02:00
|
|
|
"no_lang": {
|
|
|
|
"name": "No translation",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false,
|
|
|
|
"description": "If true, no translations are made for this widget"
|
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
/**
|
|
|
|
* Ignore the "span" property by default - it is read by the grid and
|
|
|
|
* other widgets.
|
|
|
|
*/
|
|
|
|
"span": {
|
|
|
|
"ignore": true
|
2011-08-15 10:34:21 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore the "type" tag - it is read by the "createElementFromNode"
|
|
|
|
* function and passed as second parameter of the widget constructor
|
|
|
|
*/
|
|
|
|
"type": {
|
2011-09-28 01:44:07 +02:00
|
|
|
"name": "Widget type",
|
|
|
|
"type": "string",
|
|
|
|
"ignore": true,
|
|
|
|
"description": "What kind of widget this is"
|
2011-08-16 14:31:18 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore the readonly tag by default - its also read by the
|
|
|
|
* "createElementFromNode" function.
|
|
|
|
*/
|
|
|
|
"readonly": {
|
|
|
|
"ignore": true
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set the legacyOptions array to the names of the properties the "options"
|
|
|
|
// attribute defines.
|
|
|
|
legacyOptions: [],
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
/**
|
|
|
|
* Set this variable to true if this widget can have namespaces
|
|
|
|
*/
|
|
|
|
createNamespace: false,
|
|
|
|
|
2011-08-04 21:08:50 +02:00
|
|
|
/**
|
|
|
|
* The init function is the constructor of the widget. When deriving new
|
|
|
|
* classes from the widget base class, always call this constructor unless
|
|
|
|
* you know what you're doing.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2011-08-04 21:08:50 +02:00
|
|
|
* @param _parent is the parent object from the XML tree which contains this
|
|
|
|
* object. The default constructor always adds the new instance to the
|
|
|
|
* children list of the given parent object. _parent may be NULL.
|
2011-08-19 18:00:44 +02:00
|
|
|
* @param _attrs is an associative array of attributes.
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_widget
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
2011-08-19 18:00:44 +02:00
|
|
|
init: function(_parent, _attrs) {
|
2011-08-04 21:08:50 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Check whether all attributes are available
|
|
|
|
if (typeof _parent == "undefined")
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
_parent = null;
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
if (typeof _attrs == "undefined")
|
|
|
|
{
|
|
|
|
_attrs = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize all important parameters
|
2011-08-15 14:34:00 +02:00
|
|
|
this._mgrs = {};
|
2011-08-15 16:29:58 +02:00
|
|
|
this._inst = null;
|
2011-08-19 18:00:44 +02:00
|
|
|
this._children = [];
|
|
|
|
this._type = _attrs["type"];
|
|
|
|
this.id = _attrs["id"];
|
2011-08-10 18:23:02 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Add this widget to the given parent widget
|
2011-08-04 21:08:50 +02:00
|
|
|
if (_parent != null)
|
|
|
|
{
|
2013-02-07 15:36:19 +01:00
|
|
|
_parent.addChild(this);
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
// The supported widget classes array defines a whitelist for all widget
|
|
|
|
// classes or interfaces child widgets have to support.
|
|
|
|
this.supportedWidgetClasses = [et2_widget];
|
2011-08-19 18:00:44 +02:00
|
|
|
|
|
|
|
if (_attrs["id"])
|
|
|
|
{
|
|
|
|
// Create a namespace for this object
|
|
|
|
if (this.createNamespace)
|
|
|
|
{
|
|
|
|
this.checkCreateNamespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-14 23:57:06 +01:00
|
|
|
if(this.id)
|
|
|
|
{
|
2014-05-13 00:03:38 +02:00
|
|
|
//this.id = this.id.replace(/\[/g,'[').replace(/]/g,']');
|
2011-11-14 23:57:06 +01:00
|
|
|
}
|
|
|
|
|
2011-08-23 19:05:05 +02:00
|
|
|
// Add all attributes hidden in the content arrays to the attributes
|
|
|
|
// parameter
|
|
|
|
this.transformAttributes(_attrs);
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Create a local copy of the options object
|
|
|
|
this.options = et2_cloneObject(_attrs);
|
2011-08-04 21:08:50 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The destroy function destroys all children of the widget, removes itself
|
|
|
|
* from the parents children list.
|
|
|
|
* In all classes derrived from et2_widget ALWAYS override the destroy
|
|
|
|
* function and remove ALL references to other objects. Also remember to
|
|
|
|
* unbind ANY event this widget created and to remove all DOM-Nodes it
|
|
|
|
* created.
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
|
|
|
|
|
|
|
// Call the destructor of all children
|
2011-08-05 16:53:54 +02:00
|
|
|
for (var i = this._children.length - 1; i >= 0; i--)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2011-08-25 15:35:53 +02:00
|
|
|
this._children[i].free();
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
|
2013-05-29 20:57:48 +02:00
|
|
|
// Remove this element from the parent, if it exists
|
|
|
|
if (typeof this._parent != "undefined" && this._parent !== null)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
|
|
|
this._parent.removeChild(this);
|
|
|
|
}
|
|
|
|
|
2011-09-05 16:35:28 +02:00
|
|
|
// Free the array managers if they belong to this widget
|
|
|
|
for (var key in this._mgrs)
|
|
|
|
{
|
|
|
|
if (this._mgrs[key] && this._mgrs[key].owner == this)
|
|
|
|
{
|
|
|
|
this._mgrs[key].free();
|
|
|
|
}
|
|
|
|
}
|
2011-08-05 16:53:54 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a copy of this widget. The parameters given are passed to the
|
|
|
|
* constructor of the copied object. If the parameters are omitted, _parent
|
|
|
|
* is defaulted to null
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {et2_widget} _parent parent to set for clone, default null
|
2011-08-05 16:53:54 +02:00
|
|
|
*/
|
2011-08-19 18:00:44 +02:00
|
|
|
clone: function(_parent) {
|
2011-08-05 16:53:54 +02:00
|
|
|
|
|
|
|
// Default _parent to null
|
|
|
|
if (typeof _parent == "undefined")
|
|
|
|
{
|
|
|
|
_parent = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the copy
|
2011-08-19 18:00:44 +02:00
|
|
|
var copy = new (this.constructor)(_parent, this.options);
|
2011-08-05 16:53:54 +02:00
|
|
|
|
2011-08-06 16:36:44 +02:00
|
|
|
// Assign this element to the copy
|
|
|
|
copy.assign(this);
|
|
|
|
|
|
|
|
return copy;
|
|
|
|
},
|
|
|
|
|
|
|
|
assign: function(_obj) {
|
2011-08-22 18:37:04 +02:00
|
|
|
if (typeof _obj._children == "undefined")
|
|
|
|
{
|
2012-03-05 14:07:38 +01:00
|
|
|
this.egw().debug("log", "Foo!");
|
2011-08-22 18:37:04 +02:00
|
|
|
}
|
|
|
|
|
2011-08-06 16:36:44 +02:00
|
|
|
// Create a clone of all child elements of the given object
|
|
|
|
for (var i = 0; i < _obj._children.length; i++)
|
2011-08-05 16:53:54 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
_obj._children[i].clone(this);
|
2011-08-05 16:53:54 +02:00
|
|
|
}
|
2011-08-12 18:29:24 +02:00
|
|
|
|
|
|
|
// Copy a reference to the content array manager
|
2011-08-15 14:34:00 +02:00
|
|
|
this.setArrayMgrs(_obj.mgrs);
|
2011-08-04 21:08:50 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the parent widget of this widget
|
|
|
|
*/
|
|
|
|
getParent: function() {
|
|
|
|
return this._parent;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list of children of this widget.
|
|
|
|
*/
|
|
|
|
getChildren: function() {
|
|
|
|
return this._children;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the base widget
|
|
|
|
*/
|
|
|
|
getRoot: function() {
|
|
|
|
if (this._parent != null)
|
|
|
|
{
|
|
|
|
return this._parent.getRoot();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts an child at the end of the list.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2011-08-04 21:08:50 +02:00
|
|
|
* @param _node is the node which should be added. It has to be an instance
|
|
|
|
* of et2_widget
|
|
|
|
*/
|
|
|
|
addChild: function(_node) {
|
|
|
|
this.insertChild(_node, this._children.length);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts a child at the given index.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2011-08-04 21:08:50 +02:00
|
|
|
* @param _node is the node which should be added. It has to be an instance
|
|
|
|
* of et2_widget
|
|
|
|
* @param _idx is the position at which the element should be added.
|
|
|
|
*/
|
|
|
|
insertChild: function(_node, _idx) {
|
2011-08-05 16:53:54 +02:00
|
|
|
// Check whether the node is one of the supported widget classes.
|
|
|
|
if (this.isOfSupportedWidgetClass(_node))
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2011-08-25 15:35:53 +02:00
|
|
|
// Remove the node from its original parent
|
|
|
|
if (_node._parent)
|
|
|
|
{
|
|
|
|
_node._parent.removeChild(_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
_node._parent = this;
|
2011-08-04 21:08:50 +02:00
|
|
|
this._children.splice(_idx, 0, _node);
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2013-10-09 16:11:44 +02:00
|
|
|
if(_node.implements(et2_IDOMNode) && this.implements(et2_IDOMNode) && _node.parentNode)
|
|
|
|
{
|
|
|
|
_node.detachFromDOM();
|
|
|
|
_node.parentNode = this.getDOMNode(_node);
|
|
|
|
_node.attachToDOM();
|
|
|
|
}
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-05 22:00:34 +02:00
|
|
|
this.egw().debug("error", "Widget " + _node._type +" is not supported by this widget class", this);
|
2011-08-22 18:37:04 +02:00
|
|
|
// throw("Widget is not supported by this widget class!");
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the child but does not destroy it.
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {et2_widget} _node child to remove
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
|
|
|
removeChild: function(_node) {
|
|
|
|
// Retrieve the child from the child list
|
|
|
|
var idx = this._children.indexOf(_node);
|
|
|
|
|
|
|
|
if (idx >= 0)
|
|
|
|
{
|
|
|
|
// This element is no longer parent of the child
|
|
|
|
_node._parent = null;
|
|
|
|
|
|
|
|
this._children.splice(idx, 1);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches an element by id in the tree, descending into the child levels.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2011-08-04 21:08:50 +02:00
|
|
|
* @param _id is the id you're searching for
|
|
|
|
*/
|
|
|
|
getWidgetById: function(_id) {
|
|
|
|
if (this.id == _id)
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2014-12-03 01:16:39 +01:00
|
|
|
if(!this._children) return null;
|
2011-08-04 21:08:50 +02:00
|
|
|
|
|
|
|
for (var i = 0; i < this._children.length; i++)
|
|
|
|
{
|
|
|
|
var elem = this._children[i].getWidgetById(_id);
|
|
|
|
|
|
|
|
if (elem != null)
|
|
|
|
{
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
/**
|
|
|
|
* Function which allows iterating over the complete widget tree.
|
|
|
|
*
|
|
|
|
* @param _callback is the function which should be called for each widget
|
|
|
|
* @param _context is the context in which the function should be executed
|
|
|
|
* @param _type is an optional parameter which specifies a class/interface
|
|
|
|
* the elements have to be instanceOf.
|
|
|
|
*/
|
|
|
|
iterateOver: function(_callback, _context, _type) {
|
|
|
|
if (typeof _type == "undefined")
|
|
|
|
{
|
|
|
|
_type = et2_widget;
|
|
|
|
}
|
|
|
|
|
2011-08-15 12:04:37 +02:00
|
|
|
if (this.isInTree() && this.instanceOf(_type))
|
2011-08-10 16:36:31 +02:00
|
|
|
{
|
|
|
|
_callback.call(_context, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < this._children.length; i++)
|
|
|
|
{
|
|
|
|
this._children[i].iterateOver(_callback, _context, _type);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-15 12:04:37 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the widget currently resides in the visible part of the
|
|
|
|
* widget tree. E.g. Templates which have been cloned are not in the visible
|
|
|
|
* part of the widget tree.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2014-01-29 18:11:11 +01:00
|
|
|
* @param _sender
|
|
|
|
* @param {boolean} _vis can be used by widgets overwriting this function - simply
|
2011-08-15 12:04:37 +02:00
|
|
|
* write
|
|
|
|
* return this._super(inTree);
|
|
|
|
* when calling this function the _vis parameter does not have to be supplied.
|
|
|
|
*/
|
2011-08-22 17:58:47 +02:00
|
|
|
isInTree: function(_sender, _vis) {
|
2011-08-15 12:04:37 +02:00
|
|
|
if (typeof _vis == "undefined")
|
|
|
|
{
|
|
|
|
_vis = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._parent)
|
|
|
|
{
|
2011-08-22 17:58:47 +02:00
|
|
|
return _vis && this._parent.isInTree(this);
|
2011-08-15 12:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return _vis;
|
|
|
|
},
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
isOfSupportedWidgetClass: function(_obj)
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this.supportedWidgetClasses.length; i++)
|
|
|
|
{
|
|
|
|
if (_obj.instanceOf(this.supportedWidgetClasses[i]))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
/**
|
|
|
|
* The parseXMLAttrs function takes an XML DOM attributes object
|
|
|
|
* and adds the given attributes to the _target associative array. This
|
|
|
|
* function also parses the legacyOptions.
|
|
|
|
*
|
|
|
|
* @param _attrsObj is the XML DOM attributes object
|
2014-01-29 18:11:11 +01:00
|
|
|
* @param {object} _target is the object to which the attributes should be written.
|
|
|
|
* @param {et2_widget} _proto prototype with attributes and legacyOptions attribute
|
2011-08-19 18:00:44 +02:00
|
|
|
*/
|
|
|
|
parseXMLAttrs: function(_attrsObj, _target, _proto) {
|
2011-08-15 10:34:21 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Check whether the attributes object is really existing, if not abort
|
|
|
|
if (typeof _attrsObj == "undefined")
|
2011-08-15 10:34:21 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
return;
|
2011-08-15 10:34:21 +02:00
|
|
|
}
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Iterate over the given attributes and parse them
|
2012-03-21 23:54:25 +01:00
|
|
|
var mgr = this.getArrayMgr("content");
|
2011-08-19 18:00:44 +02:00
|
|
|
for (var i = 0; i < _attrsObj.length; i++)
|
2011-08-06 16:36:44 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
var attrName = _attrsObj[i].name;
|
|
|
|
var attrValue = _attrsObj[i].value;
|
|
|
|
|
|
|
|
// Special handling for the legacy options
|
2013-02-06 09:03:13 +01:00
|
|
|
if (attrName == "options" && _proto.legacyOptions.length > 0)
|
2011-08-19 18:00:44 +02:00
|
|
|
{
|
2013-02-07 15:36:19 +01:00
|
|
|
// Check for modifications on legacy options here. Normal modifications
|
|
|
|
// are handled in widget constructor, but it's too late for legacy options then
|
|
|
|
if(_target.id && this.getArrayMgr("modifications").getEntry(_target.id))
|
|
|
|
{
|
|
|
|
var mod = this.getArrayMgr("modifications").getEntry(_target.id);
|
2013-03-25 22:46:18 +01:00
|
|
|
if(typeof mod.options != "undefined") attrValue = _attrsObj[i].value = mod.options;
|
2013-02-07 15:36:19 +01:00
|
|
|
}
|
2015-05-02 21:35:16 +02:00
|
|
|
// expand legacyOptions with content
|
|
|
|
if(attrValue.charAt(0) == '@' || attrValue.indexOf('$') != -1)
|
2013-02-06 09:03:13 +01:00
|
|
|
{
|
|
|
|
attrValue = mgr.expandName(attrValue);
|
|
|
|
}
|
|
|
|
|
2014-04-02 16:43:23 +02:00
|
|
|
// Parse the legacy options (as a string, other types not allowed)
|
|
|
|
var splitted = et2_csvSplit(attrValue+"");
|
2011-08-19 18:00:44 +02:00
|
|
|
|
|
|
|
for (var j = 0; j < splitted.length && j < _proto.legacyOptions.length; j++)
|
|
|
|
{
|
2013-04-10 11:39:36 +02:00
|
|
|
// Blank = not set
|
|
|
|
if(splitted[j].trim().length == 0) continue;
|
|
|
|
|
2012-03-15 22:56:19 +01:00
|
|
|
// Check to make sure we don't overwrite a current option with a legacy option
|
|
|
|
if(typeof _target[_proto.legacyOptions[j]] === "undefined")
|
|
|
|
{
|
2012-03-21 23:54:25 +01:00
|
|
|
attrValue = splitted[j];
|
2012-03-27 01:28:35 +02:00
|
|
|
|
2013-02-06 09:03:13 +01:00
|
|
|
/**
|
|
|
|
If more legacy options than expected, stuff them all in the last legacy option
|
|
|
|
Some legacy options take a comma separated list.
|
|
|
|
*/
|
|
|
|
if(j == _proto.legacyOptions.length - 1 && splitted.length > _proto.legacyOptions.length)
|
|
|
|
{
|
|
|
|
attrValue = splitted.slice(j);
|
|
|
|
}
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2012-03-21 23:54:25 +01:00
|
|
|
var attr = _proto.attributes[_proto.legacyOptions[j]];
|
|
|
|
|
|
|
|
// If the attribute is marked as boolean, parse the
|
|
|
|
// expression as bool expression.
|
|
|
|
if (attr.type == "boolean")
|
|
|
|
{
|
|
|
|
attrValue = mgr.parseBoolExpression(attrValue);
|
|
|
|
}
|
2013-02-06 09:03:13 +01:00
|
|
|
else if (typeof attrValue != "object")
|
2012-03-21 23:54:25 +01:00
|
|
|
{
|
|
|
|
attrValue = mgr.expandName(attrValue);
|
|
|
|
}
|
|
|
|
_target[_proto.legacyOptions[j]] = attrValue;
|
2012-03-15 22:56:19 +01:00
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mgr != null && typeof _proto.attributes[attrName] != "undefined")
|
|
|
|
{
|
|
|
|
var attr = _proto.attributes[attrName];
|
|
|
|
|
|
|
|
// If the attribute is marked as boolean, parse the
|
|
|
|
// expression as bool expression.
|
|
|
|
if (attr.type == "boolean")
|
|
|
|
{
|
|
|
|
attrValue = mgr.parseBoolExpression(attrValue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attrValue = mgr.expandName(attrValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the attribute
|
|
|
|
_target[attrName] = attrValue;
|
|
|
|
}
|
2011-08-06 16:36:44 +02:00
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
},
|
|
|
|
|
2011-08-23 17:27:34 +02:00
|
|
|
/**
|
2011-08-23 19:05:05 +02:00
|
|
|
* Apply the "modifications" to the element and translate attributes marked
|
|
|
|
* with "translate: true"
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {object} _attrs
|
2011-08-23 17:27:34 +02:00
|
|
|
*/
|
|
|
|
transformAttributes: function(_attrs) {
|
|
|
|
|
2011-08-23 19:05:05 +02:00
|
|
|
// Apply the content of the modifications array
|
|
|
|
if (this.id)
|
|
|
|
{
|
2011-09-08 20:36:09 +02:00
|
|
|
if (typeof this.id != "string")
|
|
|
|
{
|
|
|
|
console.log(this.id);
|
|
|
|
}
|
|
|
|
|
2011-09-26 18:01:42 +02:00
|
|
|
if(this.getArrayMgr("modifications"))
|
2011-08-23 19:05:05 +02:00
|
|
|
{
|
2011-09-26 18:01:42 +02:00
|
|
|
var data = this.getArrayMgr("modifications").getEntry(this.id);
|
2013-05-22 20:13:37 +02:00
|
|
|
|
|
|
|
// Check for already inside namespace
|
|
|
|
if(this.createNamespace && this.getArrayMgr("modifications").perspectiveData.owner == this)
|
|
|
|
{
|
|
|
|
data = this.getArrayMgr("modifications").data;
|
|
|
|
}
|
2012-03-06 14:22:01 +01:00
|
|
|
if (typeof data === 'object')
|
2011-08-23 19:05:05 +02:00
|
|
|
{
|
2011-09-26 18:01:42 +02:00
|
|
|
for (var key in data)
|
2011-08-23 19:05:05 +02:00
|
|
|
{
|
2013-07-05 17:03:49 +02:00
|
|
|
_attrs[key] = data[key];
|
2011-08-23 19:05:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Translate the attributes
|
2011-08-24 12:05:52 +02:00
|
|
|
for (var key in _attrs)
|
2011-08-23 17:27:34 +02:00
|
|
|
{
|
2011-08-24 12:05:52 +02:00
|
|
|
if (_attrs[key] && typeof this.attributes[key] != "undefined")
|
2011-08-23 17:27:34 +02:00
|
|
|
{
|
2014-01-21 15:39:51 +01:00
|
|
|
if (this.attributes[key].translate === true ||
|
2011-08-24 12:05:52 +02:00
|
|
|
(this.attributes[key].translate === "!no_lang" && !_attrs["no_lang"]))
|
2012-03-02 11:44:56 +01:00
|
|
|
{
|
2014-03-19 13:39:10 +01:00
|
|
|
_attrs[key] = this.egw().lang(_attrs[key], '%s');
|
2012-03-02 11:44:56 +01:00
|
|
|
}
|
2011-08-23 17:27:34 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
},
|
|
|
|
|
2013-02-05 15:40:37 +01:00
|
|
|
/**
|
|
|
|
* Create a et2_widget from an XML node.
|
|
|
|
*
|
|
|
|
* First the type and attributes are read from the node. Then the readonly & modifications
|
|
|
|
* arrays are checked for changes specific to the loaded data. Then the appropriate
|
|
|
|
* constructor is called. After the constructor returns, the widget has a chance to
|
2014-01-21 15:39:51 +01:00
|
|
|
* further initialize itself from the XML node when the widget's loadFromXML() method
|
2013-02-05 15:40:37 +01:00
|
|
|
* is called with the node.
|
|
|
|
*
|
|
|
|
* @param _node XML node to read
|
|
|
|
*
|
|
|
|
* @return et2_widget
|
|
|
|
*/
|
2011-08-19 18:00:44 +02:00
|
|
|
createElementFromNode: function(_node) {
|
|
|
|
var attributes = {};
|
2011-08-06 16:36:44 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Parse the "readonly" and "type" flag for this element here, as they
|
|
|
|
// determine which constructor is used
|
|
|
|
var _nodeName = attributes["type"] = _node.getAttribute("type") ?
|
|
|
|
_node.getAttribute("type") : _node.nodeName.toLowerCase();
|
|
|
|
var readonly = attributes["readonly"] =
|
|
|
|
this.getArrayMgr("readonlys").isReadOnly(
|
|
|
|
_node.getAttribute("id"), _node.getAttribute("readonly"),
|
2014-02-27 22:26:10 +01:00
|
|
|
typeof this.readonly !== 'undefined' ? this.readonly : this.options.readonly );
|
2011-08-19 18:00:44 +02:00
|
|
|
|
2011-09-15 20:00:17 +02:00
|
|
|
// Check to see if modifications change type
|
|
|
|
var modifications = this.getArrayMgr("modifications");
|
|
|
|
if(modifications && _node.getAttribute("id")) {
|
|
|
|
var entry = modifications.getEntry(_node.getAttribute("id"));
|
2011-10-06 18:33:55 +02:00
|
|
|
if(entry == null)
|
|
|
|
{
|
|
|
|
// Try again, but skip the fancy stuff
|
|
|
|
// TODO: Figure out why the getEntry() call doesn't always work
|
|
|
|
var entry = modifications.data[_node.getAttribute("id")];
|
2013-10-17 01:16:29 +02:00
|
|
|
if(entry)
|
|
|
|
{
|
|
|
|
this.egw().debug("warn", "getEntry("+_node.getAttribute("id")+") failed, but the data is there.", modifications, entry);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Try the root, in case a namespace got missed
|
|
|
|
var entry = modifications.getRoot().getEntry(_node.getAttribute("id"));
|
|
|
|
}
|
2011-10-06 18:33:55 +02:00
|
|
|
}
|
2011-09-15 20:00:17 +02:00
|
|
|
if(entry && entry.type)
|
|
|
|
{
|
2014-10-07 23:16:18 +02:00
|
|
|
_nodeName = attributes["type"] = entry.type;
|
2011-09-15 20:00:17 +02:00
|
|
|
}
|
|
|
|
entry = null;
|
|
|
|
}
|
|
|
|
|
2014-01-27 22:59:29 +01:00
|
|
|
// if _nodeName / type-attribute contains something to expand (eg. type="@${row}[type]"),
|
|
|
|
// we need to expand it now as it defines the constructor and by that attributes parsed via parseXMLAttrs!
|
|
|
|
if (_nodeName.charAt(0) == '@' || _nodeName.indexOf('$') >= 0)
|
|
|
|
{
|
2014-10-07 23:16:18 +02:00
|
|
|
_nodeName = attributes["type"] = this.getArrayMgr('content').expandName(_nodeName);
|
2014-01-27 22:59:29 +01:00
|
|
|
}
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Get the constructor - if the widget is readonly, use the special "_ro"
|
|
|
|
// constructor if it is available
|
2011-08-06 16:36:44 +02:00
|
|
|
var constructor = typeof et2_registry[_nodeName] == "undefined" ?
|
|
|
|
et2_placeholder : et2_registry[_nodeName];
|
2011-08-16 14:31:18 +02:00
|
|
|
if (readonly && typeof et2_registry[_nodeName + "_ro"] != "undefined")
|
|
|
|
{
|
|
|
|
constructor = et2_registry[_nodeName + "_ro"];
|
|
|
|
}
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Parse the attributes from the given XML attributes object
|
|
|
|
this.parseXMLAttrs(_node.attributes, attributes, constructor.prototype);
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Do an sanity check for the attributes
|
|
|
|
constructor.prototype.generateAttributeSet(attributes);
|
|
|
|
|
2011-08-06 16:36:44 +02:00
|
|
|
// Creates the new widget, passes this widget as an instance and
|
|
|
|
// passes the widgetType. Then it goes on loading the XML for it.
|
2011-08-19 18:00:44 +02:00
|
|
|
var widget = new constructor(this, attributes);
|
2011-08-16 14:31:18 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
// Load the widget itself from XML
|
2011-08-06 16:36:44 +02:00
|
|
|
widget.loadFromXML(_node);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
},
|
|
|
|
|
2011-08-04 21:08:50 +02:00
|
|
|
/**
|
|
|
|
* Loads the widget tree from an XML node
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param _node xml node
|
2011-08-04 21:08:50 +02:00
|
|
|
*/
|
|
|
|
loadFromXML: function(_node) {
|
|
|
|
// Load the child nodes.
|
|
|
|
for (var i = 0; i < _node.childNodes.length; i++)
|
|
|
|
{
|
|
|
|
var node = _node.childNodes[i];
|
|
|
|
var widgetType = node.nodeName.toLowerCase();
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
if (widgetType == "#comment")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetType == "#text")
|
|
|
|
{
|
|
|
|
if (node.data.replace(/^\s+|\s+$/g, ''))
|
|
|
|
{
|
|
|
|
this.loadContent(node.data);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-08-06 16:36:44 +02:00
|
|
|
// Create the new element
|
2011-08-20 20:34:14 +02:00
|
|
|
this.createElementFromNode(node);
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-08-05 16:53:54 +02:00
|
|
|
/**
|
|
|
|
* Called whenever textNodes are loaded from the XML tree
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param _content
|
2011-08-05 16:53:54 +02:00
|
|
|
*/
|
|
|
|
loadContent: function(_content) {
|
|
|
|
},
|
|
|
|
|
2011-08-15 16:52:45 +02:00
|
|
|
/**
|
2011-08-19 18:00:44 +02:00
|
|
|
* Called when loading the widget (sub-tree) is finished. First when this
|
|
|
|
* function is called, the DOM-Tree is created. loadingFinished is
|
|
|
|
* recursively called for all child elements. Do not directly override this
|
|
|
|
* function but the doLoadingFinished function which is executed before
|
2013-10-16 22:48:05 +02:00
|
|
|
* descending deeper into the DOM-Tree.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2013-10-16 22:48:05 +02:00
|
|
|
* Some widgets (template) do not load immediately because they request
|
|
|
|
* additional resources via AJAX. They will return a Deferred Promise object.
|
|
|
|
* If you call loadingFinished(promises) after creating such a widget
|
|
|
|
* programmatically, you might need to wait for it to fully complete its
|
|
|
|
* loading before proceeding. In that case use:
|
|
|
|
* <code>
|
|
|
|
* var promises = [];
|
|
|
|
* widget.loadingFinished(promises);
|
|
|
|
* jQuery.when.apply(null, promises).done( doneCallback );
|
|
|
|
* </code>
|
|
|
|
* @see {@link http://api.jquery.com/category/deferred-object/|jQuery Deferred}
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2013-10-16 22:48:05 +02:00
|
|
|
* @param {Promise[]} promises List of promises from widgets that are not done. Pass an empty array, it will be filled if needed.
|
2011-08-15 16:52:45 +02:00
|
|
|
*/
|
2013-10-16 22:48:05 +02:00
|
|
|
loadingFinished: function(promises) {
|
2011-08-19 18:00:44 +02:00
|
|
|
// Call all availble setters
|
|
|
|
this.initAttributes(this.options);
|
2014-01-21 15:39:51 +01:00
|
|
|
|
|
|
|
// Make sure promises is defined to avoid errors.
|
2013-10-16 22:48:05 +02:00
|
|
|
// We'll warn (below) if programmer should have passed it.
|
|
|
|
if(typeof promises == "undefined")
|
|
|
|
{
|
|
|
|
promises = [];
|
|
|
|
var warn_if_deferred = true;
|
|
|
|
}
|
2011-08-15 16:52:45 +02:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
var loadChildren = function()
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
// Descend recursively into the tree
|
|
|
|
for (var i = 0; i < this._children.length; i++)
|
2011-08-04 21:08:50 +02:00
|
|
|
{
|
2013-07-20 15:54:31 +02:00
|
|
|
try
|
|
|
|
{
|
2013-10-16 22:48:05 +02:00
|
|
|
this._children[i].loadingFinished(promises);
|
2013-07-20 15:54:31 +02:00
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
2013-10-10 14:32:34 +02:00
|
|
|
egw.debug("error", "There was an error with a widget:\nError:%o\nProblem widget:%o",e.valueOf(),this._children[i],e.stack);
|
2013-07-20 15:54:31 +02:00
|
|
|
}
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
2013-10-16 22:48:05 +02:00
|
|
|
};
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
var result = this.doLoadingFinished();
|
|
|
|
if(typeof result == "boolean" && result)
|
|
|
|
{
|
|
|
|
// Simple widget finishes nicely
|
|
|
|
loadChildren.apply(this, arguments);
|
|
|
|
}
|
|
|
|
else if (typeof result == "object" && result.done)
|
|
|
|
{
|
|
|
|
// Warn if list was not provided
|
|
|
|
if(warn_if_deferred)
|
|
|
|
{
|
|
|
|
// Might not be a problem, but if you need the widget to be really loaded, it could be
|
2014-01-21 15:39:51 +01:00
|
|
|
egw.debug("warn", "Loading was deferred for widget %o, but creator is not checking. Pass a list to loadingFinished().", this);
|
2013-10-16 22:48:05 +02:00
|
|
|
}
|
|
|
|
// Widget is waiting. Add to the list
|
|
|
|
promises.push(result);
|
|
|
|
// Fihish loading when it's finished
|
|
|
|
result.done(jQuery.proxy(loadChildren, this));
|
2011-08-04 21:08:50 +02:00
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
},
|
2014-01-21 15:39:51 +01:00
|
|
|
|
2013-10-09 16:35:03 +02:00
|
|
|
/**
|
|
|
|
* The initAttributes function sets the attributes to their default
|
|
|
|
* values. The attributes are not overwritten, which means, that the
|
|
|
|
* default is only set, if either a setter exists or this[propName] does
|
|
|
|
* not exist yet.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2013-10-09 16:35:03 +02:00
|
|
|
* Overwritten here to compile legacy JS code in attributes of type "js"
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {object} _attrs
|
2013-10-09 16:35:03 +02:00
|
|
|
*/
|
|
|
|
initAttributes: function(_attrs) {
|
|
|
|
for (var key in _attrs)
|
|
|
|
{
|
|
|
|
if (typeof this.attributes[key] != "undefined" && !this.attributes[key].ignore && !(_attrs[key] == undefined))
|
|
|
|
{
|
|
|
|
var val = _attrs[key];
|
|
|
|
// compile string values of attribute type "js" to functions
|
|
|
|
if (this.attributes[key].type == 'js' && typeof _attrs[key] == 'string')
|
|
|
|
{
|
2014-01-21 15:39:51 +01:00
|
|
|
val = et2_compileLegacyJS(val, this,
|
|
|
|
this.instanceOf(et2_inputWidget) ? this.getInputNode() :
|
2013-10-09 16:35:03 +02:00
|
|
|
(this.implements(et2_IDOMNode) ? this.getDOMNode() : null));
|
|
|
|
}
|
|
|
|
this.setAttribute(key, val, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2011-08-04 21:08:50 +02:00
|
|
|
|
2013-10-16 22:48:05 +02:00
|
|
|
/**
|
|
|
|
* Does specific post-processing after the widget is loaded. Most widgets should not
|
|
|
|
* need to do anything here, it should all be done before.
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2013-10-16 22:48:05 +02:00
|
|
|
* @return {boolean|Promise} True if the widget is fully loaded, false to avoid procesing children,
|
|
|
|
* or a Promise if loading is not actually finished (eg. waiting for AJAX)
|
2014-01-21 15:39:51 +01:00
|
|
|
*
|
2013-10-16 22:48:05 +02:00
|
|
|
* @see {@link http://api.jquery.com/deferred.promise/|jQuery Promise}
|
|
|
|
*/
|
2011-08-19 18:00:44 +02:00
|
|
|
doLoadingFinished: function() {
|
|
|
|
return true;
|
2011-08-10 19:44:22 +02:00
|
|
|
},
|
|
|
|
|
2012-03-02 11:44:56 +01:00
|
|
|
/**
|
|
|
|
* The egw function returns the instance of the client side api belonging
|
|
|
|
* to this widget tree. The api instance can be set in the "container"
|
|
|
|
* widget using the setApiInstance function.
|
|
|
|
*/
|
|
|
|
egw: function() {
|
2014-01-21 15:39:51 +01:00
|
|
|
// The _egw property is not set
|
2012-03-02 11:44:56 +01:00
|
|
|
if (typeof this._egw === 'undefined')
|
|
|
|
{
|
|
|
|
if (this._parent != null)
|
|
|
|
{
|
|
|
|
return this._parent.egw();
|
|
|
|
}
|
|
|
|
|
2012-03-05 14:07:38 +01:00
|
|
|
// Get the window this object belongs to
|
|
|
|
var wnd = null;
|
|
|
|
if (this.implements(et2_IDOMNode))
|
|
|
|
{
|
|
|
|
var node = this.getDOMNode();
|
2012-05-01 01:22:14 +02:00
|
|
|
if(node && node.ownerDocument)
|
|
|
|
{
|
|
|
|
wnd = node.ownerDocument.parentNode || node.ownerDocument.defaultView;
|
|
|
|
}
|
2012-03-05 14:07:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we're the root object, return the phpgwapi API instance
|
|
|
|
return egw('phpgwapi', wnd);
|
2012-03-02 11:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this._egw;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the client side api instance. It can be retrieved by the widget tree
|
|
|
|
* by using the "egw()" function.
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {egw} _egw egw object to set
|
2012-03-02 11:44:56 +01:00
|
|
|
*/
|
|
|
|
setApiInstance: function(_egw) {
|
|
|
|
this._egw = _egw;
|
|
|
|
},
|
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
/**
|
|
|
|
* Sets all array manager objects - this function can be used to set the
|
|
|
|
* root array managers of the container object.
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {object} _mgrs
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
|
|
|
setArrayMgrs: function(_mgrs) {
|
|
|
|
this._mgrs = et2_cloneObject(_mgrs);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an associative array containing the top-most array managers.
|
|
|
|
*
|
|
|
|
* @param _mgrs is used internally and should not be supplied.
|
|
|
|
*/
|
|
|
|
getArrayMgrs: function(_mgrs) {
|
|
|
|
if (typeof _mgrs == "undefined")
|
|
|
|
{
|
|
|
|
_mgrs = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add all managers of this object to the result, if they have not already
|
|
|
|
// been set in the result
|
|
|
|
for (var key in this._mgrs)
|
|
|
|
{
|
|
|
|
if (typeof _mgrs[key] == "undefined")
|
|
|
|
{
|
|
|
|
_mgrs[key] = this._mgrs[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recursively applies this function to the parent widget
|
|
|
|
if (this._parent)
|
|
|
|
{
|
|
|
|
this._parent.getArrayMgrs(_mgrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _mgrs;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the array manager for the given part
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {string} _part which array mgr to set
|
|
|
|
* @param {object} _mgr
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
|
|
|
setArrayMgr: function(_part, _mgr) {
|
|
|
|
this._mgrs[_part] = _mgr;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the array manager object for the given part
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {string} _part name of array mgr to return
|
2011-08-15 14:34:00 +02:00
|
|
|
*/
|
|
|
|
getArrayMgr: function(_part) {
|
|
|
|
if (typeof this._mgrs[_part] != "undefined")
|
|
|
|
{
|
|
|
|
return this._mgrs[_part];
|
|
|
|
}
|
|
|
|
else if (this._parent)
|
|
|
|
{
|
|
|
|
return this._parent.getArrayMgr(_part);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-08-12 18:29:24 +02:00
|
|
|
/**
|
|
|
|
* Checks whether a namespace exists for this element in the content array.
|
|
|
|
* If yes, an own perspective of the content array is created. If not, the
|
|
|
|
* parent content manager is used.
|
|
|
|
*/
|
|
|
|
checkCreateNamespace: function() {
|
|
|
|
// Get the content manager
|
2011-08-15 14:34:00 +02:00
|
|
|
var mgrs = this.getArrayMgrs();
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
for (var key in mgrs)
|
2011-08-12 18:29:24 +02:00
|
|
|
{
|
2011-08-15 14:34:00 +02:00
|
|
|
var mgr = mgrs[key];
|
2011-08-12 18:29:24 +02:00
|
|
|
|
2011-08-15 14:34:00 +02:00
|
|
|
// Get the original content manager if we have already created a
|
|
|
|
// perspective for this node
|
|
|
|
if (typeof this._mgrs[key] != "undefined" && mgr.perspectiveData.owner == this)
|
|
|
|
{
|
|
|
|
mgr = mgr.parentMgr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the manager has a namespace for the id of this object
|
2012-07-24 00:05:54 +02:00
|
|
|
var entry = mgr.getEntry(this.id);
|
2013-02-05 13:55:01 +01:00
|
|
|
if (typeof entry === 'object' && entry !== null||this.id )
|
2011-08-15 14:34:00 +02:00
|
|
|
{
|
|
|
|
// The content manager has an own node for this object, so
|
|
|
|
// create an own perspective.
|
|
|
|
this._mgrs[key] = mgr.openPerspective(this, this.id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The current content manager does not have an own namespace for
|
|
|
|
// this element, so use the content manager of the parent.
|
|
|
|
delete(this._mgrs[key]);
|
|
|
|
}
|
2011-08-12 18:29:24 +02:00
|
|
|
}
|
2011-08-15 16:29:58 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the instance manager object (of type etemplate2, see etemplate2.js)
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @param {etemplate2} _inst
|
2011-08-15 16:29:58 +02:00
|
|
|
*/
|
|
|
|
setInstanceManager: function(_inst) {
|
|
|
|
this._inst = _inst;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the instance manager
|
2014-01-29 18:11:11 +01:00
|
|
|
*
|
|
|
|
* @return {etemplate2}
|
2011-08-15 16:29:58 +02:00
|
|
|
*/
|
|
|
|
getInstanceManager: function() {
|
|
|
|
if (this._inst != null)
|
|
|
|
{
|
|
|
|
return this._inst;
|
|
|
|
}
|
|
|
|
else if (this._parent)
|
|
|
|
{
|
|
|
|
return this._parent.getInstanceManager();
|
|
|
|
}
|
|
|
|
|
2011-08-31 18:00:45 +02:00
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-10-06 18:33:55 +02:00
|
|
|
/**
|
|
|
|
* Returns the path into the data array. By default, array manager takes care of
|
|
|
|
* this, but some extensions need to override this
|
|
|
|
*/
|
|
|
|
getPath: function() {
|
2014-05-27 22:16:02 +02:00
|
|
|
var path = this.getArrayMgr("content").getPath();
|
|
|
|
|
|
|
|
// Prevent namespaced widgets with value from going an extra layer deep
|
|
|
|
if(this.id && this.createNamespace && path[path.length -1] == this.id) path.pop();
|
|
|
|
|
|
|
|
return path;
|
2011-08-12 18:29:24 +02:00
|
|
|
}
|
2011-08-04 21:08:50 +02:00
|
|
|
});
|
|
|
|
|