2011-03-02 22:18:20 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare egw_action framework - egw action framework
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Andreas Stöckel <as@stylite.de>
|
|
|
|
* @copyright 2011 by Andreas Stöckel
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package egw_action
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
uses
|
2011-03-14 21:11:08 +01:00
|
|
|
egw_action,
|
2011-03-02 22:18:20 +01:00
|
|
|
egw_action_common,
|
2011-03-09 23:16:41 +01:00
|
|
|
egw_action_view,
|
|
|
|
egw_action_data,
|
|
|
|
egw_action_columns
|
2011-03-02 22:18:20 +01:00
|
|
|
*/
|
|
|
|
|
2011-03-22 15:00:03 +01:00
|
|
|
function egwGrid(_parentNode, _columns, _objectManager, _fetchCallback, _columnChangeCallback, _context)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
|
|
|
this.parentNode = _parentNode;
|
2011-03-09 23:16:41 +01:00
|
|
|
this.objectManager = _objectManager;
|
2011-03-02 22:18:20 +01:00
|
|
|
|
2011-03-22 15:00:03 +01:00
|
|
|
this.columnChangeCallback = _columnChangeCallback;
|
|
|
|
this.context = _context;
|
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
this.width = 0;
|
|
|
|
this.height = 0;
|
2011-03-02 22:18:20 +01:00
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
// Create the column handler and connect its update event to this object
|
|
|
|
this.columns = new egwGridColumns(_columns, this.columnsUpdate, this);
|
2011-03-02 22:18:20 +01:00
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
// Create the read queue
|
|
|
|
this.readQueue = new egwGridDataQueue(_fetchCallback, _context);
|
2011-03-02 22:18:20 +01:00
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
// Create the root data element
|
|
|
|
this.dataRoot = new egwGridDataElement("", null, this.columns, this.readQueue,
|
|
|
|
_objectManager);
|
2011-03-02 22:18:20 +01:00
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
// Create the outer view component and pass the dataRoot element so that
|
|
|
|
// the grid outer element will be capable of fetching the root data and
|
|
|
|
// can create a spacer for that.
|
2011-03-16 18:50:25 +01:00
|
|
|
this.gridOuter = new egwGridViewOuter(_parentNode, this.dataRoot, this.selectcolsClick, this);
|
2011-03-09 23:16:41 +01:00
|
|
|
this.gridOuter.updateColumns(this.columns.getColumnData());
|
2011-03-02 22:18:20 +01:00
|
|
|
}
|
|
|
|
|
2011-03-14 21:11:08 +01:00
|
|
|
egwGrid.prototype.setActionLinkGroup = function(_group, _links)
|
|
|
|
{
|
|
|
|
this.dataRoot.actionLinkGroups[_group] = _links;
|
|
|
|
}
|
|
|
|
|
2011-03-16 18:50:25 +01:00
|
|
|
/**
|
|
|
|
* Updates the action link groups.
|
|
|
|
*
|
|
|
|
* @param object _groups is an object used as associative array, which will be
|
|
|
|
* merged into the existing actionLinkGroups
|
|
|
|
* @param boolean _replace specifies whether existing action link groups will
|
|
|
|
* be deleted. Defaults to false.
|
|
|
|
*/
|
|
|
|
egwGrid.prototype.setActionLinkGroups = function(_groups, _replace)
|
|
|
|
{
|
|
|
|
if (typeof _replace == "undefined")
|
|
|
|
{
|
|
|
|
_replace = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_replace)
|
|
|
|
{
|
|
|
|
this.dataRoot.actionLinkGroups = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var k in _groups)
|
|
|
|
{
|
|
|
|
this.dataRoot.actionLinkGroups[k] = _groups[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
egwGrid.prototype.resize = function(_w, _h)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
2011-03-09 23:16:41 +01:00
|
|
|
if (_w != this.width)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
2011-03-09 23:16:41 +01:00
|
|
|
this.columns.setTotalWidth(_w - this.gridOuter.scrollbarWidth);
|
|
|
|
this.gridOuter.updateColumns(this.columns.getColumnData());
|
|
|
|
this.height = -1;
|
2011-03-02 22:18:20 +01:00
|
|
|
}
|
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
if (_h != this.height)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
2011-03-09 23:16:41 +01:00
|
|
|
this.gridOuter.setHeight(_h);
|
2011-03-02 22:18:20 +01:00
|
|
|
}
|
|
|
|
|
2011-03-09 23:16:41 +01:00
|
|
|
this.height = _h;
|
|
|
|
this.width = _w;
|
2011-03-02 22:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-09 23:16:41 +01:00
|
|
|
* If the columns have changed, call the gridOuter "updateColumns" function,
|
|
|
|
* which will rebuild the view.
|
2011-03-02 22:18:20 +01:00
|
|
|
*/
|
2011-03-09 23:16:41 +01:00
|
|
|
egwGrid.prototype.columnsUpdate = function(_column)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
2011-03-09 23:16:41 +01:00
|
|
|
if (this.gridOuter)
|
2011-03-02 22:18:20 +01:00
|
|
|
{
|
2011-03-09 23:16:41 +01:00
|
|
|
this.gridOuter.updateColumns(this.columns.getColumnData());
|
2011-03-02 22:18:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 18:50:25 +01:00
|
|
|
/**
|
|
|
|
* Handle the selectcols callback
|
|
|
|
*/
|
|
|
|
egwGrid.prototype.selectcolsClick = function(_at)
|
|
|
|
{
|
|
|
|
var column_data = this.columns.getColumnVisibilitySet();
|
|
|
|
|
|
|
|
// Create a menu which contains these elements and show it
|
|
|
|
var menu_data = [];
|
|
|
|
for (var k in column_data)
|
|
|
|
{
|
|
|
|
var col = column_data[k];
|
|
|
|
|
|
|
|
menu_data.push(
|
|
|
|
{
|
|
|
|
"id": k,
|
|
|
|
"caption": col.caption,
|
|
|
|
"enabled": col.enabled,
|
|
|
|
"checkbox": true,
|
|
|
|
"checked": col.visible
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
var menu = new egwMenu();
|
|
|
|
menu.loadStructure(menu_data);
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
menu.setGlobalOnClick(function(_elem) {
|
|
|
|
column_data[_elem.id].visible = _elem.checked;
|
2011-03-22 15:00:03 +01:00
|
|
|
|
|
|
|
if (self.columnChangeCallback)
|
|
|
|
{
|
|
|
|
// Create the user data column visibility set
|
|
|
|
var set = {};
|
|
|
|
for (k in column_data)
|
|
|
|
{
|
|
|
|
set[k] = {
|
|
|
|
"visible": column_data[k].visible
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the column change callback with the user data
|
|
|
|
self.columnChangeCallback.call(self.context, set);
|
|
|
|
}
|
|
|
|
|
2011-03-16 18:50:25 +01:00
|
|
|
self.columns.setColumnVisibilitySet(column_data);
|
|
|
|
});
|
|
|
|
|
|
|
|
menu.showAt(_at.offset().left, _at.offset().top);
|
|
|
|
}
|
|
|
|
|
2011-03-14 21:11:08 +01:00
|
|
|
/**
|
|
|
|
* Emptys the grid
|
|
|
|
*/
|
|
|
|
egwGrid.prototype.empty = function()
|
|
|
|
{
|
|
|
|
this.dataRoot.empty();
|
|
|
|
this.gridOuter.grid.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
egwGrid.prototype.reload = function()
|
|
|
|
{
|
|
|
|
this.gridOuter.empty();
|
|
|
|
}
|
|
|
|
|