2011-08-10 16:36:31 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Widget base class
|
2011-08-10 16:36:31 +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
|
2011-08-16 15:12:39 +02:00
|
|
|
* @version $Id$
|
2011-08-10 16:36:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
|
|
|
jquery.jquery;
|
2011-08-13 19:34:22 +02:00
|
|
|
lib/tooltip;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_DOMWidget;
|
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.
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_DOMWidget
|
2011-08-10 16:36:31 +02:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_baseWidget = (function(){ "use strict"; return et2_DOMWidget.extend(et2_IAligned,
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2011-08-10 16:36:31 +02:00
|
|
|
attributes: {
|
|
|
|
"statustext": {
|
|
|
|
"name": "Tooltip",
|
|
|
|
"type": "string",
|
2011-08-23 19:05:05 +02:00
|
|
|
"description": "Tooltip which is shown for this element",
|
|
|
|
"translate": true
|
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-22 16:38:05 +02:00
|
|
|
},
|
|
|
|
"onclick": {
|
|
|
|
"name": "onclick",
|
2013-10-09 16:35:03 +02:00
|
|
|
"type": "js",
|
2013-10-10 15:17:07 +02:00
|
|
|
"default": et2_no_init,
|
2011-08-22 16:38:05 +02:00
|
|
|
"description": "JS code which is executed when the element is clicked."
|
2011-08-10 16:36:31 +02:00
|
|
|
}
|
|
|
|
},
|
2014-02-10 19:25:02 +01:00
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2BaseWidget
|
|
|
|
*/
|
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-23 16:59:49 +02:00
|
|
|
this._messageDiv = 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-23 16:59:49 +02:00
|
|
|
this._messageDiv = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The setMessage function can be used to attach a small message box to the
|
|
|
|
* widget. This is e.g. used to display validation errors or success messages
|
|
|
|
*
|
|
|
|
* @param _text is the text which should be displayed as a message
|
|
|
|
* @param _type is an css class which is attached to the message box.
|
|
|
|
* Currently available are "hint", "success" and "validation_error", defaults
|
|
|
|
* to "hint"
|
|
|
|
* @param _floating if true, the object will be in one row with the element,
|
|
|
|
* defaults to true
|
|
|
|
* @param _prepend if set, the message is displayed behind the widget node
|
|
|
|
* instead of before. Defaults to false.
|
|
|
|
*/
|
|
|
|
showMessage: function(_text, _type, _floating, _prepend) {
|
|
|
|
|
|
|
|
// Preset the parameters
|
|
|
|
if (typeof _type == "undefined")
|
|
|
|
{
|
2013-04-13 21:00:13 +02:00
|
|
|
_type = "hint";
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof _floating == "undefined")
|
|
|
|
{
|
|
|
|
_floating = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof _prepend == "undefined")
|
|
|
|
{
|
|
|
|
_prepend = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var surr = this.getSurroundings();
|
|
|
|
|
|
|
|
// Remove the message div from the surroundings before creating a new
|
|
|
|
// one
|
2011-08-26 00:13:54 +02:00
|
|
|
this.hideMessage(false, true);
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
// Create the message div and add it to the "surroundings" manager
|
2016-06-02 16:51:15 +02:00
|
|
|
this._messageDiv = jQuery(document.createElement("div"))
|
2011-08-23 16:59:49 +02:00
|
|
|
.addClass("message")
|
|
|
|
.addClass(_type)
|
|
|
|
.addClass(_floating ? "floating" : "")
|
2013-06-26 22:50:10 +02:00
|
|
|
.text(_text.valueOf() + "");
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
// Decide whether to prepend or append the div
|
|
|
|
if (_prepend)
|
|
|
|
{
|
|
|
|
surr.prependDOMNode(this._messageDiv[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
surr.appendDOMNode(this._messageDiv[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
surr.update();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2011-08-26 00:13:54 +02:00
|
|
|
* The hideMessage function can be used to hide a previously shown message.
|
2011-08-23 16:59:49 +02:00
|
|
|
*
|
|
|
|
* @param _fade if true, the message div will fade out, otherwise the message
|
|
|
|
* div is removed immediately. Defaults to true.
|
|
|
|
* @param _noUpdate is used internally to prevent an update of the surroundings
|
|
|
|
* manager.
|
|
|
|
*/
|
2011-08-26 00:13:54 +02:00
|
|
|
hideMessage: function(_fade, _noUpdate) {
|
2011-08-23 16:59:49 +02:00
|
|
|
if (typeof _fade == "undefined")
|
|
|
|
{
|
|
|
|
_fade = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof _noUpdate == "undefined")
|
|
|
|
{
|
|
|
|
_noUpdate = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the message from the surroundings manager and remove the
|
|
|
|
// reference to it
|
|
|
|
if (this._messageDiv != null)
|
|
|
|
{
|
|
|
|
var surr = this.getSurroundings();
|
|
|
|
var self = this;
|
2013-06-26 22:50:10 +02:00
|
|
|
var messageDiv = this._messageDiv;
|
|
|
|
self._messageDiv = null;
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
var _done = function() {
|
2013-06-26 22:50:10 +02:00
|
|
|
surr.removeDOMNode(messageDiv[0]);
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
// Update the surroundings manager
|
|
|
|
if (!_noUpdate)
|
|
|
|
{
|
|
|
|
surr.update();
|
|
|
|
}
|
2013-04-13 21:00:13 +02:00
|
|
|
};
|
2011-08-23 16:59:49 +02:00
|
|
|
|
|
|
|
// Either fade out or directly call the function which removes the div
|
|
|
|
if (_fade)
|
|
|
|
{
|
2013-06-26 22:50:10 +02:00
|
|
|
messageDiv.fadeOut("fast", _done);
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_done();
|
|
|
|
}
|
|
|
|
}
|
2011-08-21 17:22:00 +02:00
|
|
|
},
|
|
|
|
|
2013-05-28 01:24:22 +02:00
|
|
|
detachFromDOM: function() {
|
2011-08-10 16:36:31 +02:00
|
|
|
// Detach this node from the tooltip node
|
|
|
|
if (this._tooltipElem)
|
|
|
|
{
|
2012-03-06 14:22:01 +01:00
|
|
|
this.egw().tooltipUnbind(this._tooltipElem);
|
2011-08-10 16:36:31 +02:00
|
|
|
this._tooltipElem = null;
|
|
|
|
}
|
|
|
|
|
2011-08-22 16:38:05 +02:00
|
|
|
// Remove the binding to the click handler
|
|
|
|
if (this.node)
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.node).unbind("click.et2_baseWidget");
|
2011-08-22 16:38:05 +02:00
|
|
|
}
|
|
|
|
|
2011-08-10 16:36:31 +02:00
|
|
|
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
|
|
|
|
2011-08-22 16:38:05 +02:00
|
|
|
// Add the binding for the click handler
|
2013-10-16 17:04:52 +02:00
|
|
|
if (this.node)
|
2011-08-22 16:38:05 +02:00
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(this.node).bind("click.et2_baseWidget", this, function(e) {
|
2014-02-10 19:25:02 +01:00
|
|
|
return e.data.click.call(e.data, e, this);
|
2013-10-16 17:04:52 +02:00
|
|
|
});
|
2016-06-02 16:51:15 +02:00
|
|
|
if (typeof this.onclick == 'function') jQuery(this.node).addClass('et2_clickable');
|
2011-08-22 16:38:05 +02:00
|
|
|
}
|
|
|
|
|
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
|
2013-05-28 01:24:22 +02:00
|
|
|
this.detachFromDOM();
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
},
|
|
|
|
|
2013-10-09 16:35:03 +02:00
|
|
|
/**
|
|
|
|
* Click handler calling custom handler set via onclick attribute to this.onclick
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-10-09 16:35:03 +02:00
|
|
|
* @param _ev
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
click: function(_ev) {
|
|
|
|
if(typeof this.onclick == 'function')
|
2011-08-23 16:59:49 +02:00
|
|
|
{
|
2013-10-09 16:35:03 +02:00
|
|
|
// Make sure function gets a reference to the widget, splice it in as 2. argument if not
|
|
|
|
var args = Array.prototype.slice.call(arguments);
|
|
|
|
if(args.indexOf(this) == -1) args.splice(1, 0, this);
|
2014-02-10 19:25:02 +01:00
|
|
|
|
2013-10-09 16:35:03 +02:00
|
|
|
return this.onclick.apply(this, args);
|
2011-08-23 16:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
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
|
2016-06-02 16:51:15 +02:00
|
|
|
var elem = jQuery(this.getTooltipElement());
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
//If a tooltip is already attached to the element, remove it first
|
|
|
|
if (this._tooltipElem)
|
|
|
|
{
|
2012-03-06 14:22:01 +01:00
|
|
|
this.egw().tooltipUnbind(this._tooltipElem);
|
2011-08-10 16:36:31 +02:00
|
|
|
this._tooltipElem = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_value && _value != '')
|
|
|
|
{
|
2012-03-06 14:22:01 +01:00
|
|
|
this.egw().tooltipBind(elem, _value);
|
2011-08-10 16:36:31 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2011-08-10 16:39:35 +02:00
|
|
|
/**
|
|
|
|
* Simple container object
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_baseWidget
|
2011-08-10 16:39:35 +02:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_container = (function(){ "use strict"; return et2_baseWidget.extend(
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_container
|
|
|
|
*/
|
2011-08-10 16:39:35 +02:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
|
|
|
this.setDOMNode(document.createElement("div"));
|
2013-02-08 14:25:56 +01:00
|
|
|
},
|
2011-08-10 16:39:35 +02:00
|
|
|
|
2013-02-08 14:25:56 +01:00
|
|
|
/**
|
|
|
|
* The destroy function destroys all children of the widget, removes itself
|
|
|
|
* from the parents children list.
|
|
|
|
* Overriden to not try to remove self from parent, as that's not possible.
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
|
|
|
// Call the destructor of all children
|
|
|
|
for (var i = this._children.length - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
this._children[i].free();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2011-08-10 16:39:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Container object for not-yet supported widgets
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_baseWidget
|
2011-08-10 16:39:35 +02:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_placeholder = (function(){ "use strict"; return et2_baseWidget.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
2014-02-10 19:25:02 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_placeholder
|
|
|
|
*/
|
2011-08-10 16:39:35 +02:00
|
|
|
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
|
2016-06-02 16:51:15 +02:00
|
|
|
this.placeDiv = jQuery(document.createElement("span"))
|
2011-08-10 16:39:35 +02:00
|
|
|
.addClass("et2_placeholder");
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
var headerNode = jQuery(document.createElement("span"))
|
2013-05-06 19:12:45 +02:00
|
|
|
.text(this._type || "")
|
2011-08-10 16:39:35 +02:00
|
|
|
.addClass("et2_caption")
|
|
|
|
.appendTo(this.placeDiv);
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
var attrsCntr = jQuery(document.createElement("span"))
|
2011-08-19 18:00:44 +02:00
|
|
|
.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")
|
|
|
|
{
|
2016-06-02 16:51:15 +02:00
|
|
|
this.attrNodes[key] = jQuery(document.createElement("span"))
|
2011-08-19 18:00:44 +02:00
|
|
|
.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-09-14 22:52:59 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedAttributes: function(_attrs) {
|
|
|
|
_attrs.push("value");
|
|
|
|
},
|
|
|
|
|
|
|
|
getDetachedNodes: function() {
|
|
|
|
return [this.placeDiv[0]];
|
|
|
|
},
|
|
|
|
|
|
|
|
setDetachedAttributes: function(_nodes, _values) {
|
|
|
|
this.placeDiv = jQuery(_nodes[0]);
|
2011-08-10 16:39:35 +02:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2011-08-10 16:39:35 +02:00
|
|
|
|