From f8259bb73731552eb77dcd1254d711507e4932c4 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Sat, 14 Jan 2006 06:56:13 +0000
Subject: TDataList completed. A preliminary demo added.
---
framework/Web/UI/WebControls/TRepeater.php | 43 +++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 9 deletions(-)
(limited to 'framework/Web/UI/WebControls/TRepeater.php')
diff --git a/framework/Web/UI/WebControls/TRepeater.php b/framework/Web/UI/WebControls/TRepeater.php
index 664faa68..c71f6590 100644
--- a/framework/Web/UI/WebControls/TRepeater.php
+++ b/framework/Web/UI/WebControls/TRepeater.php
@@ -36,6 +36,18 @@ Prado::using('System.Web.UI.WebControls.TDataBoundControl');
* displayed between items.
*
* You can retrive the repeated contents by the {@link getItems Items} property.
+ * The header and footer items can be accessed by {@link getHeader Header}
+ * and {@link getFooter Footer} properties, respectively.
+ *
+ * When TRepeater creates an item, it will raise an {@link onItemCreated ItemCreated}
+ * so that you may customize the newly created item.
+ * When databinding is performed by TRepeater, for each item once it has finished
+ * databinding, an {@link onItemDataBound ItemDataBound} event will be raised.
+ *
+ * TRepeater raises an {@link onItemCommand ItemCommand} whenever a button control
+ * within some repeater item raises a Command event. Therefore,
+ * you can handle all sorts of Command event in a central place by
+ * writing an event handler for {@link onItemCommand ItemCommand}.
*
* @author Qiang Xue
* @version $Revision: $ $Date: $
@@ -223,6 +235,7 @@ class TRepeater extends TDataBoundControl implements INamingContainer
* @param string item type, may be 'Header', 'Footer', 'Item', 'Separator', 'AlternatingItem', 'SelectedItem', 'EditItem'.
* @param boolean whether to do databinding for the item
* @param mixed data to be associated with the item
+ * @return TRepeaterItem the created item
*/
private function createItemInternal($itemIndex,$itemType,$dataBind,$dataItem)
{
@@ -271,6 +284,12 @@ class TRepeater extends TDataBoundControl implements INamingContainer
$this->createTemplate($tplContent)->instantiateIn($item);
}
+ /**
+ * 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);
@@ -333,20 +352,28 @@ class TRepeater extends TDataBoundControl implements INamingContainer
}
/**
- * Creates repeater items based on viewstate information.
+ * Clears up all items in the repeater.
*/
- protected function restoreItemsFromViewState()
+ public function reset()
{
$this->getControls()->clear();
- $items=$this->getItems();
- $items->clear();
+ $this->getItems()->clear();
$this->_header=null;
$this->_footer=null;
+ }
+
+ /**
+ * Creates repeater items based on viewstate information.
+ */
+ protected function restoreItemsFromViewState()
+ {
+ $this->reset();
if(($itemCount=$this->getViewState('ItemCount',0))>0)
{
+ $items=$this->getItems();
+ $hasSeparator=$this->_separatorTemplate!=='';
if($this->_headerTemplate!=='')
$this->_header=$this->createItemInternal(-1,'Header',false,null);
- $hasSeparator=$this->_separatorTemplate!=='';
for($i=0;$i<$itemCount;++$i)
{
if($hasSeparator && $i>0)
@@ -368,11 +395,9 @@ class TRepeater extends TDataBoundControl implements INamingContainer
*/
protected function performDataBinding($data)
{
- $this->getControls()->clear();
- $this->clearChildState();
- $items=$this->getItems();
- $items->clear();
+ $this->reset();
$itemIndex=0;
+ $items=$this->getItems();
$hasSeparator=$this->_separatorTemplate!=='';
foreach($data as $dataItem)
{
--
cgit v1.2.3