mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-09 01:25:22 +01:00
5af5594f60
- All attributes of the widgets are now parsed from XML before the widget itself is created. These attributes plus all default values are then added to an associative array. The associative array is passed as second parameter to the init function of et2_widget, but is also available as this.options *after* the constructor of the et2_widget baseclass has been called. The et2_widget constructor also calls a function parseArrayMgrAttrs(_attrs) - in this function widget implementations can read the values from e.g. the content and validation_errors array and merge it into the given _attrs associative array. After the complete internal widgettree is completely loaded and created the "loadingFinished" function gets called and invokes all given setter functions. After that it "glues" the DOM tree together. This should also (I didn't measure it) be a bit faster than before, when the DOM-Tree was created on the fly. Please have a look at the changes of the et2_textbox widget to see how this affects writing widgets. Note: The "id" property is copied to the object scope on the top of the et2_widget constructor. - When widgets are cloned the "options" array gets passed along to the newly created widget. This means that changes made on the widgets during runtime are not automatically copied to the clone - as this didn't happen anyhow it is not a really disadvantage. On the other side there should be no difference between widgets directly inside the "overlay" xet tag and widgets which are inside instanciated templates. - The selbox widget doesn't work anymore - it relied on the loadAttributes function which isn't available anymore. et2_selbox should use the parseArrayMgrAttrs function to access - I've commented out some of the "validator"-code in etemplate2.js as it created some error messages when destroying the widget tree.
185 lines
4.0 KiB
JavaScript
185 lines
4.0 KiB
JavaScript
/**
|
|
* eGroupWare eTemplate2 - JS Tabs object
|
|
*
|
|
* @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$
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
/*egw:uses
|
|
jquery.jquery;
|
|
et2_widget;
|
|
*/
|
|
|
|
/**
|
|
* Class which implements the tabbox-tag
|
|
*/
|
|
var et2_tabbox = et2_DOMWidget.extend({
|
|
|
|
init: function(_parent, _type) {
|
|
// Create the outer tabbox container
|
|
this.container = $j(document.createElement("div"))
|
|
.addClass("et2_tabbox");
|
|
|
|
// Create the upper container for the tab flags
|
|
this.flagContainer = $j(document.createElement("div"))
|
|
.addClass("et2_tabheader")
|
|
.appendTo(this.container);
|
|
|
|
// Create the lower tab container
|
|
this.tabContainer = $j(document.createElement("div"))
|
|
.addClass("et2_tabs")
|
|
.appendTo(this.container);
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.tabData = [];
|
|
},
|
|
|
|
destroy: function(_parent, _type) {
|
|
|
|
this._super.apply(this, arguments);
|
|
|
|
this.container = null;
|
|
this.flagContainer = null;
|
|
this.tabData = [];
|
|
},
|
|
|
|
_readTabs: function(tabData, tabs) {
|
|
et2_filteredNodeIterator(tabs, function(node, nodeName) {
|
|
if (nodeName == "tab")
|
|
{
|
|
tabData.push({
|
|
"label": et2_readAttrWithDefault(node, "label", "Tab"),
|
|
"widget": null,
|
|
"contentDiv": null,
|
|
"flagDiv": null
|
|
});
|
|
}
|
|
else
|
|
{
|
|
throw("Error while parsing: Invalid tag '" + nodeName +
|
|
"' in tabs tag");
|
|
}
|
|
}, this);
|
|
},
|
|
|
|
_readTabPanels: function(tabData, tabpanels) {
|
|
var i = 0;
|
|
et2_filteredNodeIterator(tabpanels, function(node, nodeName) {
|
|
if (i < tabData.length)
|
|
{
|
|
// Create the widget corresponding to the given node
|
|
tabData[i].widget = this.createElementFromNode(node,
|
|
nodeName);
|
|
}
|
|
else
|
|
{
|
|
throw("Error while reading tabpanels tag, too many widgets!");
|
|
}
|
|
i++;
|
|
}, this);
|
|
},
|
|
|
|
loadFromXML: function(_node) {
|
|
// Get the tabs and tabpanels tags
|
|
var tabsElems = et2_directChildrenByTagName(_node, "tabs");
|
|
var tabpanelsElems = et2_directChildrenByTagName(_node, "tabpanels");
|
|
|
|
if (tabsElems.length == 1 && tabpanelsElems.length == 1)
|
|
{
|
|
var tabs = tabsElems[0];
|
|
var tabpanels = tabpanelsElems[0];
|
|
|
|
var tabData = [];
|
|
|
|
// Parse the "tabs" tag
|
|
this._readTabs(tabData, tabs);
|
|
|
|
// Read and create the widgets defined in the "tabpanels"
|
|
this._readTabPanels(tabData, tabpanels);
|
|
|
|
// Create the tab DOM-Nodes
|
|
this.createTabs(tabData)
|
|
}
|
|
else
|
|
{
|
|
throw("Error while parsing tabbox, none or multiple tabs or tabpanels tags!");
|
|
}
|
|
},
|
|
|
|
createTabs: function(tabData) {
|
|
this.tabData = tabData;
|
|
|
|
this.tabContainer.empty();
|
|
this.flagContainer.empty();
|
|
|
|
for (var i = 0; i < this.tabData.length; i++)
|
|
{
|
|
var entry = this.tabData[i];
|
|
|
|
entry.flagDiv = $j(document.createElement("span"))
|
|
.addClass("et2_tabflag")
|
|
.text(entry.label)
|
|
.appendTo(this.flagContainer)
|
|
.click({"tabs": this, "idx": i}, function(e) {
|
|
e.data.tabs.setActiveTab(e.data.idx);
|
|
});
|
|
|
|
entry.contentDiv = $j(document.createElement("div"))
|
|
.addClass("et2_tabcntr")
|
|
.appendTo(this.tabContainer);
|
|
}
|
|
|
|
this.setActiveTab(0);
|
|
},
|
|
|
|
setActiveTab: function(_idx) {
|
|
// Remove the "active" flag from all tabs-flags
|
|
$j(".et2_tabflag", this.flagContainer).removeClass("active");
|
|
|
|
// Hide all tab containers
|
|
this.tabContainer.children().hide();
|
|
|
|
// Set the tab flag with the given index active and show the corresponding
|
|
// container
|
|
this.flagContainer.children(":eq(" + _idx + ")").addClass("active");
|
|
this.tabContainer.children(":eq(" + _idx + ")").show();
|
|
},
|
|
|
|
getDOMNode: function(_sender) {
|
|
if (_sender == this)
|
|
{
|
|
return this.container[0];
|
|
}
|
|
else
|
|
{
|
|
for (var i = 0; i < this.tabData.length; i++)
|
|
{
|
|
if (this.tabData[i].widget == _sender)
|
|
{
|
|
return this.tabData[i].contentDiv[0];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
},
|
|
|
|
set_height: function(_value) {
|
|
this.height = _value;
|
|
|
|
this.tabContainer.css("height", _value);
|
|
}
|
|
|
|
});
|
|
|
|
et2_register_widget(et2_tabbox, ["tabbox"]);
|
|
|