Added code for creating widget-rows in the dataview

This commit is contained in:
Andreas Stöckel
2011-09-05 14:35:28 +00:00
parent 366bad914d
commit d037187234
11 changed files with 312 additions and 28 deletions

View File

@ -13,6 +13,9 @@
/*egw:uses
jquery.jquery;
et2_core_inheritance;
et2_core_interfaces;
et2_core_arrayMgr;
et2_core_widget;
*/
/**
@ -27,6 +30,10 @@ var et2_dataview_rowProvider = Class.extend({
this._columnIds = _columnIds;
this._prototypes = {};
this._dataRowTemplate = null;
this._mgrs = null;
this._rootWidget = null;
// Create the default row "prototypes"
this._createFullRowPrototype();
this._createDefaultPrototype();
@ -55,6 +62,25 @@ var et2_dataview_rowProvider = Class.extend({
return this._prototypes[_name].clone();
},
setDataRowTemplate: function(_template, _rootWidget) {
this._dataRowTemplate = _template;
this._rootWidget = _rootWidget;
},
getDataRow: function(_data, _row, _idx) {
// Create the row widget
var rowWidget = new et2_dataview_rowWidget(this._rootWidget, _row[0]);
// Create array managers with the given data merged in
var mgrs = et2_arrayMgrs_expand(rowWidget, this._rootWidget.getArrayMgrs(),
_data, _idx);
// Let the row widget create the widgets
rowWidget.createWidgets(mgrs, this._dataRowTemplate);
return rowWidget;
},
/* ---- PRIVATE FUNCTIONS ---- */
_createFullRowPrototype: function() {
@ -93,3 +119,56 @@ var et2_dataview_rowProvider = Class.extend({
});
var et2_dataview_rowWidget = et2_widget.extend(et2_IDOMNode, {
init: function(_parent, _row) {
// Call the parent constructor with some dummy attributes
this._super(_parent, {"id": "", "type": "rowWidget"});
// Initialize some variables
this._widgets = [];
// Copy the given DOM node
this._row = _row;
},
/**
* Copies the given array manager and clones the given widgets and inserts
* them into the row which has been passed in the constructor.
*/
createWidgets: function(_mgrs, _widgets) {
// Set the array managers - don't use setArrayMgrs here as this creates
// an unnecessary copy of the object
this._mgrs = _mgrs;
// Clone the given the widgets with this element as parent
this._widgets = new Array(_widgets.length);
for (var i = 0; i < _widgets.length; i++)
{
this._widgets[i] = _widgets[i].clone(this);
this._widgets[i].loadingFinished();
}
},
/**
* Returns the column node for the given sender
*/
getDOMNode: function(_sender) {
if (typeof _sender == "undefined" || !_sender)
{
return this.row;
}
for (var i = 0; i < this._widgets.length; i++)
{
if (this._widgets[i] == _sender)
{
return this._row.childNodes[i]; // Return the i-th td tag
}
}
}
});