2011-08-10 16:36:31 +02:00
|
|
|
/**
|
2013-04-13 21:00:13 +02:00
|
|
|
* EGroupware eTemplate2 - JS Box object
|
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
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*egw:uses
|
2016-06-06 17:38:20 +02:00
|
|
|
/vendor/bower-asset/jquery/dist/jquery.js;
|
2011-08-24 12:18:07 +02:00
|
|
|
et2_core_baseWidget;
|
2011-08-10 16:36:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-01-27 10:48:43 +01:00
|
|
|
* Class which implements box and vbox tag
|
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @augments et2_baseWidget
|
2014-01-27 10:48:43 +01:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_box = (function(){ "use strict"; return et2_baseWidget.extend([et2_IDetachedDOM],
|
2013-04-13 21:00:13 +02:00
|
|
|
{
|
2012-07-26 00:37:56 +02:00
|
|
|
attributes: {
|
|
|
|
// Not needed
|
|
|
|
"rows": {"ignore": true},
|
|
|
|
"cols": {"ignore": true}
|
|
|
|
},
|
|
|
|
|
2011-08-19 18:00:44 +02:00
|
|
|
createNamespace: true,
|
|
|
|
|
2013-04-13 21:00:13 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
2014-01-27 10:48:43 +01:00
|
|
|
*
|
2013-04-13 21:00:13 +02:00
|
|
|
* @memberOf et2_box
|
|
|
|
*/
|
2011-08-19 18:00:44 +02:00
|
|
|
init: function() {
|
2011-08-10 16:36:31 +02:00
|
|
|
this._super.apply(this, arguments);
|
|
|
|
|
2016-06-02 16:51:15 +02:00
|
|
|
this.div = jQuery(document.createElement("div"))
|
2011-08-19 18:00:44 +02:00
|
|
|
.addClass("et2_" + this._type)
|
2011-08-16 18:46:22 +02:00
|
|
|
.addClass("et2_box_widget");
|
2011-08-10 16:36:31 +02:00
|
|
|
|
|
|
|
this.setDOMNode(this.div[0]);
|
2011-10-25 00:06:21 +02:00
|
|
|
},
|
2014-01-27 10:48:43 +01:00
|
|
|
|
2013-07-04 21:38:36 +02:00
|
|
|
/**
|
|
|
|
* Overriden so we can check for autorepeating children. We only check for
|
|
|
|
* $ in the immediate children & grandchildren of this node.
|
2014-01-27 10:48:43 +01:00
|
|
|
*
|
|
|
|
* @param {object} _node
|
2013-07-04 21:38:36 +02:00
|
|
|
*/
|
2015-08-20 16:57:18 +02:00
|
|
|
loadFromXML: function(_node) {
|
2014-01-27 10:48:43 +01:00
|
|
|
if(this._type != "box")
|
2013-07-04 21:38:36 +02:00
|
|
|
{
|
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
// Load the child nodes.
|
|
|
|
var childIndex = 0;
|
|
|
|
var repeatNode = null;
|
2015-08-20 16:57:18 +02:00
|
|
|
for (var i=0; i < _node.childNodes.length; i++)
|
2013-07-04 21:38:36 +02:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
var node = _node.childNodes[i];
|
|
|
|
var widgetType = node.nodeName.toLowerCase();
|
|
|
|
|
|
|
|
if (widgetType == "#comment")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetType == "#text")
|
|
|
|
{
|
|
|
|
if (node.data.replace(/^\s+|\s+$/g, ''))
|
|
|
|
{
|
|
|
|
this.loadContent(node.data);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2013-07-04 21:38:36 +02:00
|
|
|
|
|
|
|
// Create the new element, if no expansion needed
|
|
|
|
var id = et2_readAttrWithDefault(node, "id", "");
|
2013-07-08 21:06:28 +02:00
|
|
|
if(id.indexOf('$') < 0 || widgetType != 'box')
|
2013-07-04 21:38:36 +02:00
|
|
|
{
|
2015-08-20 16:57:18 +02:00
|
|
|
this.createElementFromNode(node);
|
2013-07-04 21:38:36 +02:00
|
|
|
childIndex++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
repeatNode = node;
|
|
|
|
}
|
|
|
|
}
|
2014-01-27 10:48:43 +01:00
|
|
|
|
2013-07-04 21:38:36 +02:00
|
|
|
// Only the last child repeats(?)
|
|
|
|
if(repeatNode != null)
|
|
|
|
{
|
|
|
|
var currentPerspective = this.getArrayMgr("content").perspectiveData;
|
|
|
|
// Extra content
|
|
|
|
for(childIndex; typeof this.getArrayMgr("content").data[childIndex] != "undefined" && this.getArrayMgr("content").data[childIndex]; childIndex++) {
|
|
|
|
// Adjust for the row
|
|
|
|
var mgrs = this.getArrayMgrs();
|
|
|
|
for(var name in mgrs)
|
|
|
|
{
|
|
|
|
if(this.getArrayMgr(name).getEntry(childIndex))
|
|
|
|
{
|
|
|
|
this.getArrayMgr(name).perspectiveData.row = childIndex;
|
|
|
|
}
|
|
|
|
}
|
2011-10-25 00:06:21 +02:00
|
|
|
|
2015-08-20 16:57:18 +02:00
|
|
|
this.createElementFromNode(repeatNode);
|
2013-07-04 21:38:36 +02:00
|
|
|
}
|
2014-01-27 10:48:43 +01:00
|
|
|
|
2013-07-04 21:38:36 +02:00
|
|
|
// Reset
|
|
|
|
for(var name in this.getArrayMgrs())
|
|
|
|
{
|
|
|
|
this.getArrayMgr(name).perspectiveData = currentPerspective;
|
|
|
|
}
|
2014-01-27 10:48:43 +01:00
|
|
|
}
|
2013-07-04 21:38:36 +02:00
|
|
|
},
|
2014-01-27 10:48:43 +01:00
|
|
|
|
2011-10-25 00:06:21 +02:00
|
|
|
/**
|
2013-07-04 21:38:36 +02:00
|
|
|
* Code for implementing et2_IDetachedDOM
|
2011-10-25 00:06:21 +02:00
|
|
|
* This doesn't need to be implemented.
|
|
|
|
* Individual widgets are detected and handled by the grid, but the interface is needed for this to happen
|
2014-01-27 10:48:43 +01:00
|
|
|
*
|
|
|
|
* @param {array} _attrs array to add further attributes to
|
2013-07-04 21:38:36 +02:00
|
|
|
*/
|
|
|
|
getDetachedAttributes: function(_attrs)
|
|
|
|
{
|
2015-01-21 19:59:12 +01:00
|
|
|
_attrs.push('data');
|
2013-07-04 21:38:36 +02:00
|
|
|
},
|
2011-10-25 00:06:21 +02:00
|
|
|
|
2013-07-04 21:38:36 +02:00
|
|
|
getDetachedNodes: function()
|
|
|
|
{
|
2011-10-25 00:52:01 +02:00
|
|
|
return [this.getDOMNode()];
|
2013-07-04 21:38:36 +02:00
|
|
|
},
|
2011-10-25 00:06:21 +02:00
|
|
|
|
2013-07-04 21:38:36 +02:00
|
|
|
setDetachedAttributes: function(_nodes, _values)
|
|
|
|
{
|
2015-01-21 19:59:12 +01:00
|
|
|
if (_values.data)
|
|
|
|
{
|
|
|
|
var pairs = _values.data.split(/,/g);
|
|
|
|
for(var i=0; i < pairs.length; ++i)
|
|
|
|
{
|
|
|
|
var name_value = pairs[i].split(':');
|
2016-06-02 16:51:15 +02:00
|
|
|
jQuery(_nodes[0]).attr('data-'+name_value[0], name_value[1]);
|
2015-01-21 19:59:12 +01:00
|
|
|
}
|
|
|
|
}
|
2013-07-04 21:38:36 +02:00
|
|
|
}
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2011-08-16 18:46:22 +02:00
|
|
|
et2_register_widget(et2_box, ["vbox", "box"]);
|
2011-08-10 16:36:31 +02:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
/**
|
|
|
|
* Details widget implementation
|
|
|
|
* widget name is "details" and can be use as a wrapping container
|
|
|
|
* in order to make its children collapsible.
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2016-01-19 12:42:11 +01:00
|
|
|
* Note: details widget does not represent html5 "details" tag in DOM
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2016-01-19 12:42:11 +01:00
|
|
|
* <details>
|
|
|
|
* <widgets>
|
|
|
|
* ....
|
|
|
|
* <details/>
|
2016-02-29 21:40:43 +01:00
|
|
|
*
|
2016-01-19 12:42:11 +01:00
|
|
|
*/
|
2016-02-29 21:40:43 +01:00
|
|
|
var et2_details = (function(){ "use strict"; return et2_box.extend(
|
2016-01-19 12:42:11 +01:00
|
|
|
{
|
|
|
|
attributes:{
|
|
|
|
"toggle_align": {
|
|
|
|
name: "Toggle button alignment",
|
|
|
|
description:" Defines where to align the toggle button, default is right alignment",
|
|
|
|
type:"string",
|
|
|
|
default: "right"
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
name: "title",
|
|
|
|
description:"Set a header title for box and shows it next to toggle button, default is no title",
|
|
|
|
type:"string",
|
|
|
|
default: ""
|
|
|
|
}
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
init: function() {
|
|
|
|
this._super.apply(this, arguments);
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
this.div = jQuery(document.createElement('div')).addClass('et2_details');
|
|
|
|
this.title = jQuery(document.createElement('span'))
|
|
|
|
.addClass('et2_label et2_details_title')
|
|
|
|
.appendTo(this.div);
|
|
|
|
this.span = jQuery(document.createElement('span'))
|
|
|
|
.addClass('et2_details_toggle')
|
|
|
|
.appendTo(this.div);
|
|
|
|
this.wrapper = jQuery(document.createElement('div'))
|
|
|
|
.addClass('et2_details_wrapper')
|
|
|
|
.appendTo(this.div);
|
2016-02-29 21:40:43 +01:00
|
|
|
|
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
this._createWidget();
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
/**
|
|
|
|
* Function happens on toggle action
|
|
|
|
*/
|
|
|
|
_toggle: function (){
|
|
|
|
this.div.toggleClass('et2_details_expanded');
|
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
/**
|
|
|
|
* Create widget, set contents, and binds handlers
|
|
|
|
*/
|
|
|
|
_createWidget: function () {
|
|
|
|
var self = this;
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
this.span.on('click', function (e){
|
|
|
|
self._toggle();
|
|
|
|
});
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
//Set header title
|
|
|
|
if (this.options.title)
|
|
|
|
{
|
2016-01-20 15:48:04 +01:00
|
|
|
this.title
|
|
|
|
.click (function(){self._toggle();})
|
|
|
|
.text(this.options.title);
|
2016-01-19 12:42:11 +01:00
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
// Align toggle button left/right
|
2016-01-20 15:25:14 +01:00
|
|
|
if (this.options.toggle_align === "left") this.span.css({float:'left'});
|
2016-01-19 12:42:11 +01:00
|
|
|
},
|
2016-02-29 21:40:43 +01:00
|
|
|
|
2016-01-19 12:42:11 +01:00
|
|
|
getDOMNode: function(_sender) {
|
|
|
|
if (!_sender || _sender === this)
|
|
|
|
{
|
|
|
|
return this.div[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.wrapper[0];
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 21:40:43 +01:00
|
|
|
});}).call(this);
|
2016-01-19 12:42:11 +01:00
|
|
|
et2_register_widget(et2_details, ["details"]);
|