diff options
Diffstat (limited to 'framework/Web/UI/WebControls')
| -rw-r--r-- | framework/Web/UI/WebControls/TDataGrid.php | 220 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TDataGridColumn.php | 295 | ||||
| -rw-r--r-- | framework/Web/UI/WebControls/TStyle.php | 2 | 
3 files changed, 429 insertions, 88 deletions
| diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index 23b45842..205b97a0 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -96,96 +96,10 @@   *
   * An <b>OnItemCreated</b> event will be raised right after each item is created in the datagrid.
   *
 - * Namespace: System.Web.UI.WebControls
 - *
 - * Properties
 - * - <b>Items</b>, TDataGridItemCollection, read-only
 - *   <br>Gets the list of TDataGridItem controls that correspond to each data item.
 - * - <b>Columns</b>, TCollection, read-only
 - *   <br>Gets the list of TDataGridColumn controls that are manually specified or created.
 - * - <b>AutoGenerateColumns</b>, boolean, default=true, kept in viewstate
 - *   <br>Gets or sets the value indicating whether columns should be generated automatically based on the data in datasource.
 - * - <b>AllowSorting</b>, boolean, default=false, kept in viewstate
 - *   <br>Gets or sets the value indicating whether sorting should be enabled.
 - * - <b>AllowPaging</b>, boolean, default=false, kept in viewstate
 - *   <br>Gets or sets the value indicating whether paging should be enabled.
 - * - <b>AllowCustomPaging</b>, boolean, default=false, kept in viewstate
 - *   <br>Gets or sets the value indicating whether custom paging should be enabled.
 - * - <b>CurrentPageIndex</b>, integer, default=0, stored in viewstate
 - *   <br>Gets or sets the index for the page to be displayed
 - * - <b>PageSize</b>, integer, default=10, stored in viewstate
 - *   <br>Gets or sets the number of data items to be displayed in each page.
 - * - <b>PageCount</b>, integer, read-only
 - *   <br>Gets the number of pages to be displayed.
 - * - <b>VirtualItemCount</b>, integer, default=0, stored in viewstate
 - *   <br>Gets or sets the number of data items available for paging purpose when custom paging is enabled.
 - * - <b>PagerButtonCount</b>, integer, default=10, stored in viewstate
 - *   <br>Gets or sets the number of buttons to be displayed in pager for navigating among pages.
 - * - <b>PagerDisplay</b>, string (None,Top,Bottom,TopAndBottom), default=Bottom, stored in viewstate
 - *   <br>Gets or sets where the pager should be displayed.
 - * - <b>EditItemIndex</b>, integer, default=-1, stored in viewstate
 - *   <br>Gets or sets the index for edit item.
 - * - <b>EditItem</b>, TDataGridItem, read-only
 - *   <br>Gets the edit item, null if none
 - * - <b>EditItemStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for the edit item
 - * - <b>EditItemCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css classs for the edit item
 - * - <b>SelectedItemIndex</b>, integer, default=-1, stored in viewstate
 - *   <br>Gets or sets the index for selected item.
 - * - <b>SelectedItem</b>, TDataGridItem, read-only
 - *   <br>Gets the selected item, null if none
 - * - <b>SelectedItemStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for the selected item
 - * - <b>SelectedItemCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for the selected item
 - * - <b>ItemStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for each item
 - * - <b>ItemCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for each item
 - * - <b>AlternatingItemStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for each alternating item
 - * - <b>AlternatingItemCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for each alternating item
 - * - <b>HeaderStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for the header
 - * - <b>HeaderCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for the header
 - * - <b>FooterStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for the footer
 - * - <b>FooterCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for the footer
 - * - <b>PagerStyle</b>, string, stored in viewstate
 - *   <br>Gets or sets the css style for the pager
 - * - <b>PagerCssClass</b>, string, stored in viewstate
 - *   <br>Gets or sets the css class for the pager
 - * - <b>ShowHeader</b>, boolean, default=true, stored in viewstate
 - *   <br>Gets or sets the value whether to show header
 - * - <b>ShowFooter</b>, boolean, default=true, stored in viewstate
 - *   <br>Gets or sets the value whether to show footer
 - * - <b>Header</b>, TDataGridItem
 - *   <br>Gets the header of the data grid.
 - * - <b>Footer</b>, TDataGridItem
 - *   <br>Gets the footer of the data grid.
 - * - <b>Pager</b>, TDataGridItem
 - *   <br>Gets the pager of the data grid.
 - * - <b>BackImageUrl</b>, string, kept in viewstate
 - *   <br>Gets or sets the URL of the background image to display behind the datagrid.
 - *
 - * Events
 - * - <b>OnEditCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'edit' command.
 - * - <b>OnSelectCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'select' command.
 - * - <b>OnUpdateCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'update' command.
 - * - <b>OnCancelCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'cancel' command.
 - * - <b>OnDeleteCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'delete' command.
 - * - <b>OnPageCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'page' command.
 - * - <b>OnSortCommand</b>, raised when a button control raises an <b>OnCommand</b> event with 'sort' command.
 - * - <b>OnItemCommand</b>, raised when a button control raises an <b>OnCommand</b> event.
 - * - <b>OnItemCreatedCommand</b>, raised right after an item is created.
 - *
   * @author Qiang Xue <qiang.xue@gmail.com>
 - * @version $Revision: 1.25 $ $Date: 2005/12/17 06:11:28 $
 + * @version $Revision: $  $Date: $
   * @package System.Web.UI.WebControls
 + * @since 3.0
   */
  class TDataGrid extends TBaseDataList
  {
 @@ -1152,6 +1066,136 @@ class TDataGridColumnCollection extends TList  class TDataGridPagerStyle extends TTableItemStyle
  {
 +	private $_mode=null;
 +	private $_nextText=null;
 +	private $_prevText=null;
 +	private $_buttonCount=null;
 +	private $_position=null;
 +	private $_visible=null;
 +
 +	public function getMode()
 +	{
 +		return $this->_mode===null?'NextPrev':$this->_mode;
 +	}
 +
 +	public function setMode($value)
 +	{
 +		$this->_mode=TPropertyValue::ensureEnum($value,'NextPrev','NumericPages');
 +	}
 +
 +	public function getNextPageText()
 +	{
 +		return $this->_nextText===null?'>':$this->_nextText;
 +	}
 +
 +	public function setNextPageText($value)
 +	{
 +		$this->_nextText=$value;
 +	}
 +
 +	public function getPrevPageText()
 +	{
 +		return $this->_prevText===null?'<':$this->_prevText;
 +	}
 +
 +	public function setPrevPageText($value)
 +	{
 +		$this->_prevText=$value;
 +	}
 +
 +	public function getPageButtonCount()
 +	{
 +		return $this->_buttonCount===null?10:$this->_buttonCount;
 +	}
 +
 +	public function setPageButtonCount($value)
 +	{
 +		if(($value=TPropertyValue::ensureInteger($value))<1)
 +			throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid');
 +		$this->_buttonCount=$value;
 +	}
 +
 +	public function getPosition()
 +	{
 +		return $this->_position===null?'Bottom':$this->_position;
 +	}
 +
 +	public function setPosition($value)
 +	{
 +		$this->_position=TPropertyValue::ensureEnum($value,'Bottom','Top','TopAndBottom');
 +	}
 +
 +	public function getVisible()
 +	{
 +		return $this->_visible===null?true:$this->_visible;
 +	}
 +
 +	public function setVisible($value)
 +	{
 +		$this->_visible=TPropertyValue::ensureBoolean($value);
 +	}
 +
 +	/**
 +	 * Resets the style to the original empty state.
 +	 */
 +	public function reset()
 +	{
 +		parent::reset();
 +		$this->_visible=null;
 +		$this->_position=null;
 +		$this->_buttonCount=null;
 +		$this->_prevText=null;
 +		$this->_nextText=null;
 +		$this->_mode=null;
 +	}
 +
 +	/**
 +	 * Copies the style content from an existing style
 +	 * This method overrides the parent implementation by
 +	 * adding additional TDataGridPagerStyle specific attributes.
 +	 * @param TStyle source style
 +	 */
 +	public function copyFrom($style)
 +	{
 +		parent::copyFrom($style);
 +		if($style instanceof TDataGridPagerStyle)
 +		{
 +			$this->_visible=$style->_visible;
 +			$this->_position=$style->_position;
 +			$this->_buttonCount=$style->_buttonCount;
 +			$this->_prevText=$style->_prevText;
 +			$this->_nextText=$style->_nextText;
 +			$this->_mode=$style->_mode;
 +		}
 +	}
 +
 +	/**
 +	 * Merges with a style.
 +	 * If a style field is not set in the current style but set in the new style
 +	 * it will take the value from the new style.
 +	 * This method overrides the parent implementation by
 +	 * merging with additional TDataGridPagerStyle specific attributes.
 +	 * @param TStyle the new style
 +	 */
 +	public function mergeWith($style)
 +	{
 +		parent::mergeWith($style);
 +		if($style instanceof TDataGridPagerStyle)
 +		{
 +			if($style->_visible!==null && $this->_visible===null)
 +				$this->_visible=$style->_visible;
 +			if($style->_position!==null && $this->_position===null)
 +				$this->_position=$style->_position;
 +			if($style->_buttonCount!==null && $this->_buttonCount===null)
 +				$this->_buttonCount=$style->_buttonCount;
 +			if($style->_prevText!==null && $this->_prevText===null)
 +				$this->_prevText=$style->_prevText;
 +			if($style->_nextText!==null && $this->_nextText===null)
 +				$this->_nextText=$style->_nextText;
 +			if($style->_mode!==null && $this->_mode===null)
 +				$this->_mode=$style->_mode;
 +		}
 +	}
  }
  ?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php new file mode 100644 index 00000000..f78c636d --- /dev/null +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -0,0 +1,295 @@ +<?php
 +/**
 + * TDataGridColumn class file
 + *
 + * @author Qiang Xue <qiang.xue@gmail.com>
 + * @link http://www.pradosoft.com/
 + * @copyright Copyright © 2005 PradoSoft
 + * @license http://www.pradosoft.com/license/
 + * @version $Revision: $  $Date: $
 + * @package System.Web.UI.WebControls
 + */
 +
 +/**
 + * TDataGridColumn class
 + *
 + * TDataGridColumn serves as the base class for the different column types of the TDataGrid control.
 + * TDataGridColumn defines the properties and methods that are common to all column types.
 + * In particular, it initializes header and footer cells according to
 + * <b>HeaderText</b>, <b>HeaderStyle</b>, <b>FooterText</b>, and <b>FooterStyle</b>.
 + * If <b>HeaderImageUrl</b> is specified, the image will be displayed instead in the header cell.
 + * The <b>ItemStyle</b> is applied to non-header and -footer items.
 + *
 + * When the datagrid enables sorting, if the <b>SortExpression</b> is not empty,
 + * the header cell will display a button (linkbutton or imagebutton) that will
 + * bubble sort command event to the datagrid.
 + *
 + * The framework provides the following TDataGridColumn descendant classes,
 + * - TBoundColumn, associated with a specific field in datasource and displays the corresponding data.
 + * - TEditCommandColumn, displaying edit/update/cancel command buttons
 + * - TButtonColumn, displaying generic command buttons that may be bound to specific field in datasource.
 + * - THyperLinkColumn, displaying a hyperlink that may be boudn to specific field in datasource.
 + * - TTemplateColumn, displaying content based on templates.
 + *
 + * To create your own column class, simply override {@link initializeCell()} method,
 + * which is the major logic for managing the data and presentation of cells in the column.
 + *
 + * @author Qiang Xue <qiang.xue@gmail.com>
 + * @version $Revision: $  $Date: $
 + * @package System.Web.UI.WebControls
 + * @since 3.0
 + */
 +abstract class TDataGridColumn extends TComponent
 +{
 +	private $_owner=null;
 +	private $_viewState=array();
 +
 +	/**
 +	 * @return string the text to be displayed in the header of this column
 +	 */
 +	public function getHeaderText()
 +	{
 +		return $this->getViewState('HeaderText','');
 +	}
 +
 +	/**
 +	 * @param string text to be displayed in the header of this column
 +	 */
 +	public function setHeaderText($value)
 +	{
 +		$this->setViewState('HeaderText',$value,'');
 +		$this->onColumnChanged();
 +	}
 +
 +	/**
 +	 * @return string the url of the image to be displayed in header
 +	 */
 +	public function getHeaderImageUrl()
 +	{
 +		return $this->getViewState('HeaderImageUrl','');
 +	}
 +
 +	/**
 +	 * @param string the url of the image to be displayed in header
 +	 */
 +	public function setHeaderImageUrl($value)
 +	{
 +		$this->setViewState('HeaderImageUrl',$value,'');
 +		$this->onColumnChanged();
 +	}
 +
 +	/**
 +	 * @return TTableItemStyle the style for header
 +	 */
 +	public function getHeaderStyle()
 +	{
 +		if(($style=$this->getViewState('HeaderStyle',null))===null)
 +		{
 +			$style=new TTableItemStyle;
 +			$this->setViewState('HeaderStyle',$style,null);
 +		}
 +		return $style;
 +	}
 +
 +	/**
 +	 * @return string the text to be displayed in the footer of this column
 +	 */
 +	public function getFooterText()
 +	{
 +		return $this->getViewState('FooterText','');
 +	}
 +
 +	/**
 +	 * @param string text to be displayed in the footer of this column
 +	 */
 +	public function setFooterText($value)
 +	{
 +		$this->setViewState('FooterText',$value,'');
 +		$this->onColumnChanged();
 +	}
 +
 +	/**
 +	 * @return TTableItemStyle the style for footer
 +	 */
 +	public function getFooterStyle()
 +	{
 +		if(($style=$this->getViewState('FooterStyle',null))===null)
 +		{
 +			$style=new TTableItemStyle;
 +			$this->setViewState('FooterStyle',$style,null);
 +		}
 +		return $style;
 +	}
 +
 +	/**
 +	 * @return TTableItemStyle the style for item
 +	 */
 +	public function getItemStyle()
 +	{
 +		if(($style=$this->getViewState('ItemStyle',null))===null)
 +		{
 +			$style=new TTableItemStyle;
 +			$this->setViewState('ItemStyle',$style,null);
 +		}
 +		return $style;
 +	}
 +
 +	/**
 +	 * @param string the name of the field or expression for sorting
 +	 */
 +	public function setSortExpression($value)
 +	{
 +		$this->setViewState('SortExpression',$value,'');
 +		$this->onColumnChanged();
 +	}
 +
 +	/**
 +	 * @return string the name of the field or expression for sorting
 +	 */
 +	public function getSortExpression()
 +	{
 +		return $this->getViewState('SortExpression','');
 +	}
 +
 +	/**
 +	 * @return boolean whether the column is visible. Defaults to true.
 +	 */
 +	public function getVisible($checkParents=true)
 +	{
 +		return $this->getViewState('Visible',true);
 +	}
 +
 +	/**
 +	 * @param boolean whether the column is visible
 +	 */
 +	public function setVisible($value)
 +	{
 +		$this->setViewState('Visible',TPropertyValue::ensureBoolean($value),true);
 +		$this->onColumnChanged();
 +	}
 +
 +	/**
 +	 * Returns a viewstate value.
 +	 *
 +	 * @param string the name of the viewstate value to be returned
 +	 * @param mixed the default value. If $key is not found in viewstate, $defaultValue will be returned
 +	 * @return mixed the viewstate value corresponding to $key
 +	 */
 +	protected function getViewState($key,$defaultValue=null)
 +	{
 +		return isset($this->_viewState[$key])?$this->_viewState[$key]:$defaultValue;
 +	}
 +
 +	/**
 +	 * Sets a viewstate value.
 +	 *
 +	 * Make sure that the viewstate value must be serializable and unserializable.
 +	 * @param string the name of the viewstate value
 +	 * @param mixed the viewstate value to be set
 +	 * @param mixed default value. If $value===$defaultValue, the item will be cleared from the viewstate.
 +	 */
 +	protected function setViewState($key,$value,$defaultValue=null)
 +	{
 +		if($value===$defaultValue)
 +			unset($this->_viewState[$key]);
 +		else
 +			$this->_viewState[$key]=$value;
 +	}
 +
 +	protected function loadState($state)
 +	{
 +		$this->_viewState=$state;
 +	}
 +
 +	protected function saveState()
 +	{
 +		return $this->_viewState;
 +	}
 +
 +	protected function getOwner()
 +	{
 +		return $this->_owner;
 +	}
 +
 +	protected function setOwner(TDataGrid $value)
 +	{
 +		$this->_owner=$value;
 +	}
 +
 +	protected function onColumnChanged()
 +	{
 +		if($this->_owner)
 +			$this->_owner->onColumnsChanged();
 +	}
 +
 +	public function initialize()
 +	{
 +	}
 +
 +	/**
 +	 * Initializes the specified cell to its initial values.
 +	 * The default implementation sets the content of header and footer cells.
 +	 * If sorting is enabled by the grid and sort expression is specified in the column,
 +	 * the header cell will show a link/image button. Otherwise, the header/footer cell
 +	 * will only show static text/image.
 +	 * This method can be overriden to provide customized intialization to column cells.
 +	 * @param TTableCell the cell to be initialized.
 +	 * @param integer the index to the Columns property that the cell resides in.
 +	 * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
 +	 */
 +	public function initializeCell($cell,$columnIndex,$itemType)
 +	{
 +		switch($itemType)
 +		{
 +			case 'Header':
 +				$sortExpression=$this->getSortExpression();
 +				$allowSorting=$sortExpression!=='' && (!$this->_owner || $this->_owner->getAllowSorting());
 +				if($allowSorting)
 +				{
 +					if(($url=$this->getHeaderImageUrl())!=='')
 +					{
 +						$button=Prado::createComponent('System.Web.UI.WebControls.TImageButton');
 +						$button->setImageUrl($url);
 +						$button->setCommandName('Sort');
 +						$button->setCommandParameter($sortExpression);
 +						$button->setCausesValidation(false);
 +						$cell->getControls()->add($button);
 +					}
 +					else if(($text=$this->getHeaderText())!=='')
 +					{
 +						$button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
 +						$button->setText($text);
 +						$button->setCommandName('Sort');
 +						$button->setCommandParameter($sortExpression);
 +						$button->setCausesValidation(false);
 +						$cell->getControls()->add($button);
 +					}
 +					else
 +						$cell->setText(' ');
 +				}
 +				else
 +				{
 +					if(($url=$this->getHeaderImageUrl())!=='')
 +					{
 +						$image=Prado::createComponent('System.Web.UI.WebControls.TImage');
 +						$image->setImageUrl($url);
 +						$cell->getControls()->add($image);
 +					}
 +					else
 +					{
 +						if(($text=$this->getHeaderText())==='')
 +							$text=' ';
 +						$cell->setText($text);
 +					}
 +				}
 +				break;
 +			case 'Footer':
 +				if(($text=$this->getFooterText())==='')
 +					$text=' ';
 +				$cell->setText($text);
 +				break;
 +		}
 +	}
 +}
 +
 +?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php index 1996ca47..3198f770 100644 --- a/framework/Web/UI/WebControls/TStyle.php +++ b/framework/Web/UI/WebControls/TStyle.php @@ -260,6 +260,7 @@ class TStyle extends TComponent  	 */
  	public function reset()
  	{
 +		parent::reset();
  		$this->_fields=array();
  		$this->_font=null;
  		$this->_class=null;
 @@ -578,6 +579,7 @@ class TTableItemStyle extends TStyle  	 */
  	public function reset()
  	{
 +		parent::reset();
  		$this->_verticalAlign=null;
  		$this->_horizontalAlign=null;
  		$this->_wrap=null;
 | 
