2011-08-10 16:36:31 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate2 - JS Widget 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
|
2011-08-16 15:12:39 +02:00
|
|
|
* @version $Id$
|
2011-08-10 16:36:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2011-08-13 19:34:22 +02:00
|
|
|
lib/tooltip;
|
2011-08-11 15:53:35 +02:00
|
|
|
et2_DOMWidget;
|
2011-08-10 16:36:31 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-16 18:46:22 +02:00
|
|
|
/**
|
|
|
|
* Interface for widgets which have the align attribute
|
|
|
|
*/
|
|
|
|
var et2_IAligned = new Interface({
|
|
|
|
get_align: function() {}
|
|
|
|
});
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
/**
|
|
|
|
* Class which manages the DOM node itself. The simpleWidget class is derrived
|
|
|
|
* from et2_DOMWidget and implements the getDOMNode function. A setDOMNode
|
|
|
|
* function is provided, which attatches the given node to the DOM if possible.
|
|
|
|
*/
|
2011-08-16 18:46:22 +02:00
|
|
|
var et2_baseWidget = et2_DOMWidget.extend(et2_IAligned, {
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
attributes: {
|
|
|
|
"statustext": {
|
|
|
|
"name": "Tooltip",
|
|
|
|
"type": "string",
|
|
|
|
"description": "Tooltip which is shown for this element"
|
2011-08-16 18:46:22 +02:00
|
|
|
},
|
|
|
|
"align": {
|
|
|
|
"name": "Align",
|
|
|
|
"type": "string",
|
|
|
|
"default": "left",
|
|
|
|
"description": "Position of this element in the parent hbox"
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function() {
|
2011-08-16 18:46:22 +02:00
|
|
|
this.align = "left";
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.node = null;
|
|
|
|
this.statustext = "";
|
|
|
|
|
2011-08-21 17:22:00 +02:00
|
|
|
this._labelContainer = null;
|
|
|
|
this._widgetPlaceholder = null;
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
this._tooltipElem = null;
|
|
|
|
},
|
|
|
|
|
2011-08-21 17:22:00 +02:00
|
|
|
destroy: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.node = null;
|
|
|
|
},
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
detatchFromDOM: function() {
|
|
|
|
// Detach this node from the tooltip node
|
|
|
|
if (this._tooltipElem)
|
|
|
|
{
|
|
|
|
egw_global_tooltip.unbindFromElement(this._tooltipElem);
|
|
|
|
this._tooltipElem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
attachToDOM: function() {
|
2011-08-21 17:22:00 +02:00
|
|
|
this._super.apply(this, arguments);
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
// Update the statustext
|
|
|
|
this.set_statustext(this.statustext);
|
|
|
|
},
|
|
|
|
|
|
|
|
setDOMNode: function(_node) {
|
|
|
|
if (_node != this.node)
|
|
|
|
{
|
|
|
|
// Deatch the old node from the DOM
|
|
|
|
this.detatchFromDOM();
|
|
|
|
|
|
|
|
// Set the new DOM-Node
|
|
|
|
this.node = _node;
|
|
|
|
|
|
|
|
// Attatch the DOM-Node to the tree
|
|
|
|
return this.attachToDOM();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
getDOMNode: function() {
|
|
|
|
return this.node;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTooltipElement: function() {
|
2011-08-16 18:46:22 +02:00
|
|
|
return this.getDOMNode(this);
|
2011-08-10 16:36:31 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set_statustext: function(_value) {
|
|
|
|
// Don't execute the code below, if no tooltip will be attached/detached
|
|
|
|
if (_value == "" && !this._tooltipElem)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statustext = _value;
|
|
|
|
|
|
|
|
//Get the domnode the tooltip should be attached to
|
|
|
|
var elem = $j(this.getTooltipElement());
|
|
|
|
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
//If a tooltip is already attached to the element, remove it first
|
|
|
|
if (this._tooltipElem)
|
|
|
|
{
|
|
|
|
egw_global_tooltip.unbindFromElement(this._tooltipElem);
|
|
|
|
this._tooltipElem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_value && _value != '')
|
|
|
|
{
|
|
|
|
egw_global_tooltip.bindToElement(elem, _value);
|
|
|
|
this._tooltipElem = elem;
|
|
|
|
}
|
|
|
|
}
|
2011-08-16 18:46:22 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set_align: function(_value) {
|
2011-08-19 18:00:44 +02:00
|
|
|
this.align = _value;
|
2011-08-16 18:46:22 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
get_align: function(_value) {
|
|
|
|
return this.align;
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-08-10 16:39:35 +02:00
|
|
|
/**
|
|
|
|
* Simple container object
|
|
|
|
*/
|
|
|
|
var et2_container = et2_baseWidget.extend({
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.setDOMNode(document.createElement("div"));
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Container object for not-yet supported widgets
|
|
|
|
*/
|
|
|
|
var et2_placeholder = et2_baseWidget.extend({
|
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
// The attrNodes object will hold the DOM nodes which represent the
|
|
|
|
// values of this object
|
|
|
|
this.attrNodes = {};
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
this.visible = false;
|
|
|
|
|
2011-08-10 16:39:35 +02:00
|
|
|
// Create the placeholder div
|
|
|
|
this.placeDiv = $j(document.createElement("span"))
|
|
|
|
.addClass("et2_placeholder");
|
|
|
|
|
|
|
|
var headerNode = $j(document.createElement("span"))
|
2011-08-19 18:00:44 +02:00
|
|
|
.text(this._type)
|
2011-08-10 16:39:35 +02:00
|
|
|
.addClass("et2_caption")
|
|
|
|
.appendTo(this.placeDiv);
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
var attrsCntr = $j(document.createElement("span"))
|
|
|
|
.appendTo(this.placeDiv)
|
|
|
|
.hide();
|
2011-08-10 16:39:35 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
headerNode.click(this, function(e) {
|
|
|
|
e.data.visible = !e.data.visible;
|
|
|
|
if (e.data.visible)
|
2011-08-10 16:39:35 +02:00
|
|
|
{
|
2011-08-19 18:00:44 +02:00
|
|
|
attrsCntr.show();
|
2011-08-10 16:39:35 +02:00
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
attrsCntr.hide();
|
|
|
|
}
|
|
|
|
});
|
2011-08-10 16:39:35 +02:00
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
for (var key in this.options)
|
|
|
|
{
|
|
|
|
if (typeof this.options[key] != "undefined")
|
|
|
|
{
|
|
|
|
if (typeof this.attrNodes[key] == "undefined")
|
|
|
|
{
|
|
|
|
this.attrNodes[key] = $j(document.createElement("span"))
|
|
|
|
.addClass("et2_attr");
|
|
|
|
attrsCntr.append(this.attrNodes[key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.attrNodes[key].text(key + "=" + this.options[key]);
|
|
|
|
}
|
2011-08-10 16:39:35 +02:00
|
|
|
}
|
2011-08-19 18:00:44 +02:00
|
|
|
|
|
|
|
this.setDOMNode(this.placeDiv[0]);
|
2011-08-10 16:39:35 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|