/**
 *  data structures and events for dynamic tables
 *
 *  @author   Tobias Hettinger
 *  @version  $Id: table.js,v 1.21 2009/05/25 14:12:31 tobias Exp $
 */

 
//=====================================================================================================================
//  table caption
//=====================================================================================================================

/**
 *  constructor
 *
 *  @param string caption      content of the column caption. This can be plain text or HTML code
 *  @param bool   sortable     if true, the column is sortable, if false the column can not be sorted
 *  @param bool   filterInput  if true, a filter input field is shown in the caption of the column
 */
var WATTableColumn = function(caption, sortable, filterInput)
{
  //  set the property member variables
  this.caption = caption;
  this.sortable = sortable;
  this.filterInput = filterInput;
  this.filterInputNewLine = false;
  this.filterValues = new Array();
  this.verticalText = false;
  
  //  width of the column (in pixels) or 0 if no fixed width is defined
  this.width = 0;
  
  //  initialize runtime variables
  this.filterString = null;
}

 
//=====================================================================================================================
//  table cell
//=====================================================================================================================

/**
 *  constructor
 *
 *  @param string value  value of the cell. This can be plain text or HTML code
 */
var WATTableCell = function(value)
{
  //  set the member variables
  this.value = value;
  
  //  optional data
  this.filterValue = null;
  this.sortableValue = null;
  this.sortDataType = 's';  //  [s: string, n:numeric]
}


//=====================================================================================================================
//  table row
//=====================================================================================================================

/**
 *  constructor
 *
 *  @param array cells  array of cell objects
 */
var WATTableRow = function(cells)
{
  //  set the member variables
  this.cells = cells;
  
  //  initialize row properties
  this.key = null;
  this.d1 = null;
  this.d2 = null;
  this.d3 = null;
  this.href = null;
  
  //  each row has to know the sort properties during the sort process
  this.sortColumnName = null;
  this.sortDesc = false;
  
  //  information about the table row DHTML element
  this.tableView = null;
  this.tr = null;
  this.cssClass = null;
}


//=====================================================================================================================
//  table row group
//=====================================================================================================================

/**
 *  constructor
 *
 *  @param string key      key of the group
 *  @param string caption  caption of the group
 */
var WATTableGroupType = function(key, caption)
{
  //  set the member variables
  this.key = key;
  this.caption = caption;
  
  //  initialize the objects
  this.groups = new Array();
}

/**
 *  constructor
 *
 *  @param string key      key of the row group
 *  @param string caption  caption of the row group
 */
var WATTableGroup = function(key, caption)
{
  //  set the member variables
  this.key = key;
  this.caption = caption;
  this.order = 1;
  
  //  initialize the objects
  this.rows = new Array();
}


//=====================================================================================================================
//  table events
//=====================================================================================================================

/**
 *  constructor of the OnSelectRow event
 */
function WATTableViewSelectRowEvent()
{
  //  set the member variables
  this.eventHandlers = new Array();
}

/**
 *  function to register the passed event handler
 */
WATTableViewSelectRowEvent.prototype.AddHandler = function(eventHandler)
{
  this.eventHandlers.push(eventHandler);
}

/**
 *  function to raise the event
 *
 *  @param class tableView  tableView object that raised the event
 *  @param class row        row that has been selected or deselected
 *  @param bool  selected   true if the row has been selected or false if the row was deselected
 */
WATTableViewSelectRowEvent.prototype.Raise = function(tableView, row, selected)
{
  for(var i=0; i<this.eventHandlers.length; i++)
    this.eventHandlers[i](tableView, row, selected);
}

//  create an instance of the OnSelectRow event
WATOnTableViewSelectRow = new WATTableViewSelectRowEvent();



/**
 *  constructor of the OnDblClickRow event
 */
function WATTableViewDblClickRowEvent()
{
  //  set the member variables
  this.eventHandlers = new Array();
}

/**
 *  function to register the passed event handler
 */
WATTableViewDblClickRowEvent.prototype.AddHandler = function(eventHandler)
{
  this.eventHandlers.push(eventHandler);
}

/**
 *  function to raise the event
 *
 *  @param class tableView  tableView object that raised the event
 *  @param class row        row that has been clicked
 */
WATTableViewDblClickRowEvent.prototype.Raise = function(tableView, row)
{
  for(var i=0; i<this.eventHandlers.length; i++)
    this.eventHandlers[i](tableView, row);
}

//  create an instance of the OnDblClickRow event
WATOnTableViewDblClickRow = new WATTableViewDblClickRowEvent();



/**
 *  constructor of the OnContextMenuRow event
 */
function WATTableViewContextMenuRowEvent()
{
  //  set the member variables
  this.eventHandlers = new Array();
}

/**
 *  function to register the passed event handler
 */
WATTableViewContextMenuRowEvent.prototype.AddHandler = function(eventHandler)
{
  this.eventHandlers.push(eventHandler);
}

/**
 *  function to raise the event
 *
 *  @param class tableView  tableView object that raised the event
 *  @param class row        row that has been clicked
 */
WATTableViewContextMenuRowEvent.prototype.Raise = function(tableView, row)
{
  for(var i=0; i<this.eventHandlers.length; i++)
    this.eventHandlers[i](tableView, row);
}

//  create an instance of the OnContextMenuRow event
WATOnTableViewContextMenuRow = new WATTableViewContextMenuRowEvent();
