diff options
author | xue <> | 2006-01-15 19:46:50 +0000 |
---|---|---|
committer | xue <> | 2006-01-15 19:46:50 +0000 |
commit | a9d62d90ad6b78618a8491d292d75ceced033f2b (patch) | |
tree | 1ffec11d4a2ac9757f57044a488e61c2a6eafa83 /framework/Web/UI | |
parent | 8c841835a7d3cbc938201b33ebfad0cb181d47a9 (diff) |
Added column components of datagrid.
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/WebControls/TBoundColumn.php | 144 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TButtonColumn.php | 208 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TDataGridColumn.php | 15 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TEditCommandColumn.php | 182 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/THyperLinkColumn.php | 203 | ||||
-rw-r--r-- | framework/Web/UI/WebControls/TTemplateColumn.php | 185 |
6 files changed, 937 insertions, 0 deletions
diff --git a/framework/Web/UI/WebControls/TBoundColumn.php b/framework/Web/UI/WebControls/TBoundColumn.php new file mode 100644 index 00000000..729f21fd --- /dev/null +++ b/framework/Web/UI/WebControls/TBoundColumn.php @@ -0,0 +1,144 @@ +<?php
+/**
+ * TBoundColumn 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 file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TBoundColumn class
+ *
+ * TBoundColumn represents a column that is bound to a field in a data source.
+ * The cells in the column will be displayed using the data indexed by
+ * <b>DataField</b>. You can customize the display by setting <b>DataFormatString</b>.
+ *
+ * If <b>ReadOnly</b> is false, TBoundColumn will display cells in edit mode
+ * with textboxes. Otherwise, a static text is displayed.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TBoundColumn extends TDataGridColumn
+{
+ /**
+ * @return string the field name from the data source to bind to the column
+ */
+ public function getDataField()
+ {
+ return $this->getViewState('DataField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the column
+ */
+ public function setDataField($value)
+ {
+ $this->setViewState('DataField',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the formatting string used to control how the bound data will be displayed.
+ */
+ public function getDataFormatString()
+ {
+ return $this->getViewState('DataFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the bound data will be displayed.
+ */
+ public function setDataFormatString($value)
+ {
+ $this->setViewState('DataFormatString',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return boolean whether the items in the column can be edited. Defaults to false.
+ */
+ public function getReadOnly()
+ {
+ return $this->getViewState('ReadOnly',false);
+ }
+
+ /**
+ * @param boolean whether the items in the column can be edited
+ */
+ public function setReadOnly($value)
+ {
+ $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
+ $this->onColumnChanged();
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a textbox for item in edit mode and the column is not read-only.
+ * Otherwise it displays a static text.
+ * The caption of the button and the static text are retrieved
+ * from the datasource.
+ * @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)
+ {
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ switch($itemType)
+ {
+ case 'EditItem':
+ $control=$cell;
+ if(!$this->getReadOnly())
+ {
+ $textBox=Prado::createComponent('System.Web.UI.WebControls.TTextBox');
+ $cell->getControls()->add($textBox);
+ $control=$textBox;
+ }
+ case 'Item':
+ case 'AlternatingItem':
+ case 'SelectedItem':
+ if(($dataField=$this->getDataField())!=='')
+ $control->attachEventHandler('DataBinding',array($this,'dataBindColumn'));
+ break;
+ }
+ }
+
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getDataItem();
+ if(($field=$this->getDataField())!=='')
+ $value=$this->formatDataValue($this->getDataFieldValue($data,$field));
+ else
+ $value=$this->formatDataValue($data);
+ if(($sender instanceof TTableCell) || ($sender instanceof TTextBox))
+ $sender->setText($value);
+ }
+
+ /**
+ * Formats the text value according to format string.
+ * This method is invoked when setting the text to a cell.
+ * This method can be overriden.
+ * @param mixed the data associated with the cell
+ * @return string the formatted result
+ */
+ protected function formatDataValue($formatString,$value)
+ {
+ return $formatString===''?TPropertyValue::ensureString($value):sprintf($formatString,$value);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TButtonColumn.php b/framework/Web/UI/WebControls/TButtonColumn.php new file mode 100644 index 00000000..34b4ba51 --- /dev/null +++ b/framework/Web/UI/WebControls/TButtonColumn.php @@ -0,0 +1,208 @@ +<?php
+/**
+ * TButtonColumn 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 file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TButtonColumn class
+ *
+ * TButtonColumn contains a user-defined command button, such as Add or Remove,
+ * that corresponds with each row in the column.
+ *
+ * The caption of the buttons in the column is determined by <b>Text</b>
+ * and <b>DataTextField</b> properties. If both are present, the latter takes
+ * precedence. The <b>DataTextField</b> refers to the name of the field in datasource
+ * whose value will be used as the button caption. If <b>DataTextFormatString</b>
+ * is not empty, the value will be formatted before rendering.
+ *
+ * The buttons in the column can be set to display as hyperlinks or push buttons
+ * by setting the <b>ButtonType</b> property.
+ * The <b>CommandName</b> will assign its value to all button's <b>CommandName</b>
+ * property. The datagrid will capture the command event where you can write event handlers
+ * based on different command names.
+ *
+ * Note, the command buttons created in the column will not cause validation.
+ * To enable validation, please use TTemplateColumn instead.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TButtonColumn extends TDataGridColumn
+{
+ /**
+ * @return string the text caption of the button
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the button.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the button caption
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the button caption
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the formatting string used to control how the button caption will be displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the button caption will be displayed.
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the type of command button. Defaults to LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType','LinkButton');
+ }
+
+ /**
+ * @param string the type of command button, LinkButton or PushButton
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'LinkButton','PushButton'),'LinkButton');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the command name associated with the <b>Command</b> event.
+ */
+ public function getCommandName()
+ {
+ return $this->getViewState('CommandName','');
+ }
+
+ /**
+ * Sets the command name associated with the <b>Command</b> event.
+ * @param string the text caption to be set
+ */
+ public function setCommandName($value)
+ {
+ $this->setViewState('CommandName',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a command button within the cell.
+ * @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)
+ {
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem')
+ {
+ if($this->getButtonType()==='LinkButton')
+ $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
+ else
+ $button=Prado::createComponent('System.Web.UI.WebControls.TButton');
+ $button->setText($this->getText());
+ $button->setCommandName($this->getCommandName());
+ $button->setCausesValidation($this->getCausesValidation());
+ $button->setValidationGroup($this->getValidationGroup());
+ if($this->getDataTextField()!=='')
+ $button->attachEventHandler('DataBinding',array($this,'dataBindColumn'));
+ $cell->getControls()->add($button);
+ }
+ }
+
+ public function dataBindColumn($sender,$param)
+ {
+ if(($field=$this->getDataTextField())!=='')
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getDataItem();
+ $value=$this->getDataFieldValue($data,$field);
+ $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
+ if(($sender instanceof TLinkButton) || ($sender instanceof TButton))
+ $sender->setText($text);
+ }
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php index f78c636d..dc1d8521 100644 --- a/framework/Web/UI/WebControls/TDataGridColumn.php +++ b/framework/Web/UI/WebControls/TDataGridColumn.php @@ -226,6 +226,21 @@ abstract class TDataGridColumn extends TComponent {
}
+ protected function getDataFieldValue($data,$field)
+ {
+ if(is_array($data))
+ return $data[$field];
+ else if($data instanceof TMap)
+ return $data->itemAt($field);
+ else if(($data instanceof TComponent) && $data->canGetProperty($field))
+ {
+ $getter='get'.$field;
+ return $data->$getter();
+ }
+ else
+ throw new TInvalidDataValueException('datagridcolumn_data_invalid');
+ }
+
/**
* Initializes the specified cell to its initial values.
* The default implementation sets the content of header and footer cells.
diff --git a/framework/Web/UI/WebControls/TEditCommandColumn.php b/framework/Web/UI/WebControls/TEditCommandColumn.php new file mode 100644 index 00000000..a51b703f --- /dev/null +++ b/framework/Web/UI/WebControls/TEditCommandColumn.php @@ -0,0 +1,182 @@ +<?php
+/**
+ * TEditCommandColumn 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 file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TEditCommandColumn class
+ *
+ * TEditCommandColumn contains the Edit command buttons for editing data items in each row.
+ *
+ * TEditCommandColumn will create an edit button if a cell is not in edit mode.
+ * Otherwise an update button and a cancel button will be created within the cell.
+ * The button captions are specified using <b>EditText</b>, <b>UpdateText</b>
+ * and <b>CancelText</b>.
+ *
+ * The buttons in the column can be set to display as hyperlinks or push buttons
+ * by setting the <b>ButtonType</b> property.
+ *
+ * When an edit button is clicked, the datagrid will generate an <b>OnEditCommand</b>
+ * event. When an update/cancel button is clicked, the datagrid will generate an
+ * <b>OnUpdateCommand</b> or an <b>OnCancelCommand</b>. You can write these event handlers
+ * to change the state of specific datagrid item.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TEditCommandColumn extends TDataGridColumn
+{
+ /**
+ * @return string the type of command button. Defaults to LinkButton.
+ */
+ public function getButtonType()
+ {
+ return $this->getViewState('ButtonType','LinkButton');
+ }
+
+ /**
+ * @param string the type of command button, LinkButton or PushButton
+ */
+ public function setButtonType($value)
+ {
+ $this->setViewState('ButtonType',TPropertyValue::ensureEnum($value,'LinkButton','PushButton'),'LinkButton');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the caption of the edit button
+ */
+ public function getEditText()
+ {
+ return $this->getViewState('EditText','');
+ }
+
+ /**
+ * @param string the caption of the edit button
+ */
+ public function setEditText($value)
+ {
+ $this->setViewState('EditText',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the caption of the update button
+ */
+ public function getUpdateText()
+ {
+ return $this->getViewState('UpdateText','');
+ }
+
+ /**
+ * @param string the caption of the update button
+ */
+ public function setUpdateText($value)
+ {
+ $this->setViewState('UpdateText',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the caption of the cancel button
+ */
+ public function getCancelText()
+ {
+ return $this->getViewState('CancelText','');
+ }
+
+ /**
+ * @param string the caption of the cancel button
+ */
+ public function setCancelText($value)
+ {
+ $this->setViewState('CancelText',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return boolean whether postback event trigger by this button will cause input validation, default is true
+ */
+ public function getCausesValidation()
+ {
+ return $this->getViewState('CausesValidation',true);
+ }
+
+ /**
+ * @param boolean whether postback event trigger by this button will cause input validation
+ */
+ public function setCausesValidation($value)
+ {
+ $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true);
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the group of validators which the button causes validation upon postback
+ */
+ public function getValidationGroup()
+ {
+ return $this->getViewState('ValidationGroup','');
+ }
+
+ /**
+ * @param string the group of validators which the button causes validation upon postback
+ */
+ public function setValidationGroup($value)
+ {
+ $this->setViewState('ValidationGroup',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates an update and a cancel button for cell in edit mode.
+ * Otherwise it creates an edit button.
+ * @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)
+ {
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ $buttonType=$this->getButtonType()=='LinkButton'?'TLinkButton':'TButton';
+ if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem')
+ $this->addButtonToCell($cell,'Edit',$this->getUpdateText(),false,'');
+ else if($itemType==='EditItem')
+ {
+ $this->addButtonToCell($cell,'Update',$this->getUpdateText(),$this->getCausesValidation(),$this->getValidationGroup());
+ $cell->getControls()->add(' ');
+ $this->addButtonToCell($cell,'Cancel',$this->getUpdateText(),false,'');
+ }
+ }
+
+ private function addButtonToCell($cell,$commandName,$text,$causesValidation,$validationGroup)
+ {
+ if($this->getButtonType()==='LinkButton')
+ $button=Prado::createComponent('System.Web.UI.WebControls.TLinkButton');
+ else
+ $button=Prado::createComponent('System.Web.UI.WebControls.TButton');
+ $button->setText($text);
+ $button->setCommandName($commandName);
+ $button->setCausesValidation($causesValidation);
+ $button->setValidationGroup($validationGroup);
+ $cell->getControls()->add($button);
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/THyperLinkColumn.php b/framework/Web/UI/WebControls/THyperLinkColumn.php new file mode 100644 index 00000000..34991845 --- /dev/null +++ b/framework/Web/UI/WebControls/THyperLinkColumn.php @@ -0,0 +1,203 @@ +<?php
+/**
+ * THyperLinkColumn 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 file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * THyperLinkColumn class
+ *
+ * THyperLinkColumn contains a hyperlink for each item in the column.
+ * You can set the text and the url of the hyperlink by <b>Text</b> and <b>NavigateUrl</b>
+ * properties, respectively. You can also bind the text and url to specific
+ * data field in datasource by setting <b>DataTextField</b> and <b>DataNavigateUrlField</b>.
+ * Both can be formatted before rendering according to the <b>DataTextFormatString</b>
+ * and <b>DataNavigateUrlFormatString</b> properties, respectively.
+ * If both <b>Text</b> and <b>DataTextField</b> are present, the latter takes precedence.
+ * The same rule applies to <b>NavigateUrl</b> and <b>DataNavigateUrlField</b> properties.
+ *
+ * Namespace: System.Web.UI.WebControls
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class THyperLinkColumn extends TDataGridColumn
+{
+ /**
+ * @return string the text caption of the hyperlink
+ */
+ public function getText()
+ {
+ return $this->getViewState('Text','');
+ }
+
+ /**
+ * Sets the text caption of the hyperlink.
+ * @param string the text caption to be set
+ */
+ public function setText($value)
+ {
+ $this->setViewState('Text',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the hyperlink caption
+ */
+ public function getDataTextField()
+ {
+ return $this->getViewState('DataTextField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the hyperlink caption
+ */
+ public function setDataTextField($value)
+ {
+ $this->setViewState('DataTextField',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the formatting string used to control how the hyperlink caption will be displayed.
+ */
+ public function getDataTextFormatString()
+ {
+ return $this->getViewState('DataTextFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the hyperlink caption will be displayed.
+ */
+ public function setDataTextFormatString($value)
+ {
+ $this->setViewState('DataTextFormatString',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the URL to link to when the hyperlink is clicked.
+ */
+ public function getNavigateUrl()
+ {
+ return $this->getViewState('NavigateUrl','');
+ }
+
+ /**
+ * Sets the URL to link to when the hyperlink is clicked.
+ * @param string the URL
+ */
+ public function setNavigateUrl($value)
+ {
+ $this->setViewState('NavigateUrl',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the field name from the data source to bind to the navigate url of hyperlink
+ */
+ public function getDataNavigateUrlField()
+ {
+ return $this->getViewState('DataNavigateUrlField','');
+ }
+
+ /**
+ * @param string the field name from the data source to bind to the navigate url of hyperlink
+ */
+ public function setDataNavigateUrlField($value)
+ {
+ $this->setViewState('DataNavigateUrlField',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the formatting string used to control how the navigate url of hyperlink will be displayed.
+ */
+ public function getDataNavigateUrlFormatString()
+ {
+ return $this->getViewState('DataNavigateUrlFormatString','');
+ }
+
+ /**
+ * @param string the formatting string used to control how the navigate url of hyperlink will be displayed.
+ */
+ public function setDataNavigateUrlFormatString($value)
+ {
+ $this->setViewState('DataNavigateUrlFormatString',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * @return string the target window or frame to display the Web page content linked to when the hyperlink is clicked.
+ */
+ public function getTarget()
+ {
+ return $this->getViewState('Target','');
+ }
+
+ /**
+ * Sets the target window or frame to display the Web page content linked to when the hyperlink is clicked.
+ * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
+ */
+ public function setTarget($value)
+ {
+ $this->setViewState('Target',$value,'');
+ $this->onColumnChanged();
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It creates a hyperlink within the cell.
+ * @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)
+ {
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ if($itemType==='Item' || $itemType==='AlternatingItem' || $itemType==='SelectedItem' || $itemType==='EditItem')
+ {
+ $link=Prado::createComponent('System.Web.UI.WebControls.THyperLink');
+ $link->setText($this->getText());
+ $link->setNavigateUrl($this->getNavigateUrl());
+ $link->setTarget($this->getTarget());
+ if($this->getDataTextField()!=='' || $this->getDataNavigateUrlField()!=='')
+ $link->attachEventHandler('DataBinding',array($this,'dataBindColumn'));
+ $cell->getControls()->add($link);
+ }
+ }
+
+ public function dataBindColumn($sender,$param)
+ {
+ $item=$sender->getNamingContainer();
+ $data=$item->getDataItem();
+ if(($field=$this->getDataTextField())!=='')
+ {
+ $value=$this->getDataFieldValue($data,$field);
+ $text=$this->formatDataValue($this->getDataTextFormatString(),$value);
+ $sender->setText($text);
+ }
+ if(($field=$this->getDataNavigateUrlField())!=='')
+ {
+ $value=$this->getDataFieldValue($data,$field);
+ $url=$this->formatDataValue($this->getDataNavigateUrlFormatString(),$value);
+ $sender->setNavigateUrl($url);
+ }
+ }
+}
+
+?>
\ No newline at end of file diff --git a/framework/Web/UI/WebControls/TTemplateColumn.php b/framework/Web/UI/WebControls/TTemplateColumn.php new file mode 100644 index 00000000..ec4f191d --- /dev/null +++ b/framework/Web/UI/WebControls/TTemplateColumn.php @@ -0,0 +1,185 @@ +<?php
+/**
+ * TTemplateColumn 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 file
+ */
+Prado::using('System.Web.UI.WebControls.TDataGridColumn');
+
+/**
+ * TTemplateColumn class
+ *
+ * TTemplateColumn customizes the layout of controls in the column with templates.
+ * In particular, you can specify <b>ItemTemplate</b>, <b>EditItemTemplate</b>
+ * <b>HeaderTemplate</b> and <b>FooterTemplate</b> to customize specific
+ * type of cells in the column.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Web.UI.WebControls
+ * @since 3.0
+ */
+class TTemplateColumn extends TDataGridColumn
+{
+ /**
+ * Number of seconds that a cached template will expire after
+ */
+ const CACHE_EXPIRY=18000;
+ /**
+ * Various item templates
+ * @var string
+ */
+ private $_itemTemplate='';
+ private $_editItemTemplate='';
+ private $_headerTemplate='';
+ private $_footerTemplate='';
+ private static $_templates=array();
+
+ /**
+ * @return string the edit item template string
+ */
+ public function getEditItemTemplate()
+ {
+ return $this->_editItemTemplate;
+ }
+
+ /**
+ * Sets the edit item template string
+ * @param string the edit item template
+ */
+ public function setEditItemTemplate($value)
+ {
+ $this->_editItemTemplate=$value;
+ }
+
+ /**
+ * @return string the template string for the item
+ */
+ public function getItemTemplate()
+ {
+ return $this->_itemTemplate;
+ }
+
+ /**
+ * Sets the template string for the item
+ * @param string the item template
+ */
+ public function setItemTemplate($value)
+ {
+ $this->_itemTemplate=$value;
+ }
+
+ /**
+ * @return string the header template string
+ */
+ public function getHeaderTemplate()
+ {
+ return $this->_headerTemplate;
+ }
+
+ /**
+ * Sets the header template.
+ * The template will be parsed immediately.
+ * @param string the header template
+ */
+ public function setHeaderTemplate($value)
+ {
+ $this->_headerTemplate=$value;
+ }
+
+ /**
+ * @return string the footer template string
+ */
+ public function getFooterTemplate()
+ {
+ return $this->_footerTemplate;
+ }
+
+ /**
+ * Sets the footer template.
+ * The template will be parsed immediately.
+ * @param string the footer template
+ */
+ public function setFooterTemplate($value)
+ {
+ $this->_footerTemplate=$value;
+ }
+
+ /**
+ * Initializes the specified cell to its initial values.
+ * This method overrides the parent implementation.
+ * It initializes the cell based on different templates
+ * (ItemTemplate, EditItemTemplate, HeaderTemplate, FooterTemplate).
+ * @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)
+ {
+ parent::initializeCell($cell,$columnIndex,$itemType);
+ $tplContent='';
+ switch($itemType)
+ {
+ case 'Header':
+ $tplContent=$this->_headerTemplate;
+ break;
+ case 'Footer':
+ $tplContent=$this->_footerTemplate;
+ break;
+ case 'Item':
+ case 'AlternatingItem':
+ case 'SelectedItem':
+ $tplContent=$this->_itemTemplate;
+ break;
+ case 'EditItem':
+ $tplContent=$this->_editItemTemplate===''?$this->_itemTemplate:$this->_editItemTemplate;
+ break;
+ }
+ if($tplContent!=='')
+ {
+ $cell->setText('');
+ $cell->getControls()->clear();
+ $this->createTemplate($tplContent)->instantiateIn($cell);
+ }
+ }
+
+ /**
+ * Parses item template.
+ * This method uses caching technique to accelerate template parsing.
+ * @param string template string
+ * @return ITemplate parsed template object
+ */
+ protected function createTemplate($str)
+ {
+ $key=md5($str);
+ if(isset(self::$_templates[$key]))
+ return self::$_templates[$key];
+ else
+ {
+ $contextPath=$this->getOwner()->getTemplateControl()->getTemplate()->getContextPath();
+ if(($cache=$this->getApplication()->getCache())!==null)
+ {
+ if(($template=$cache->get($key))===null)
+ {
+ $template=new TTemplate($str,$contextPath);
+ $cache->set($key,$template,self::CACHE_EXPIRY);
+ }
+ }
+ else
+ $template=new TTemplate($str,$contextPath);
+ self::$_templates[$key]=$template;
+ return $template;
+ }
+ }
+}
+
+?>
\ No newline at end of file |