From 9b426cf539f69e7dae8d179c59b99c6a576a36d1 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 4 May 2006 15:49:24 +0000 Subject: Fixed #150 - TDataGrid and TDataList now render table section tags --- HISTORY | 5 +- .../quickstart/protected/pages/Advanced/State.page | 4 +- framework/Web/UI/WebControls/TDataGrid.php | 93 ++++++++++++++++++++-- framework/Web/UI/WebControls/TRepeatInfo.php | 8 ++ 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/HISTORY b/HISTORY index 7029455d..6b704ee7 100644 --- a/HISTORY +++ b/HISTORY @@ -1,9 +1,10 @@ Version 3.0.1 June 1, 2006 ========================== -CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang) -CHG: Ticket#154 - HTML comments are now parsed as regular template strings (Qiang) +ENH: Ticket#150 - TDataGrid and TDataList now render table section tags (Qiang) ENH: Ticket#151 - added sanity check GET parameters in constructUrl() (Qiang) ENH: Ticket#152 - constituent parts of TWizard are exposed (Qiang) +CHG: Ticket#153 - TAssetManager now ignores .svn directories (Qiang) +CHG: Ticket#154 - HTML comments are now parsed as regular template strings (Qiang) ENH: added sanity check to calling event handlers (Qiang) NEW: TTableHeaderRow, TTableFooterRow and table section support (Qiang) diff --git a/demos/quickstart/protected/pages/Advanced/State.page b/demos/quickstart/protected/pages/Advanced/State.page index 30d5b2fc..8d69d6a4 100644 --- a/demos/quickstart/protected/pages/Advanced/State.page +++ b/demos/quickstart/protected/pages/Advanced/State.page @@ -27,7 +27,7 @@ $caption = $this->getViewState('Caption'); Control state is like view state in every aspect except that control state cannot be disabled. Control state is intended to be used for storing crucial state information without which a page or control may not work properly.

-To store and retrieve a variable in control state, use the followign commands, +To store and retrieve a variable in control state, use the following commands,

$this->setControlState('Caption',$caption); @@ -39,7 +39,7 @@ $caption = $this->getControlState('Caption'); Application state refers to data that is persistent across user sessions and page requests. A typical example of application state is the user visit counter. The counter value is persistent even if the current user session terminates. Note, view state and control state are lost if the user requests for a different page, while session state is lost if the user session terminates.

-To store and retrieve a variable in application state, use the followign commands, +To store and retrieve a variable in application state, use the following commands,

$application->setGlobalState('Caption',$caption); diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index 55b12ebc..6ff6faba 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -356,6 +356,39 @@ class TDataGrid extends TBaseDataList implements INamingContainer return $style; } + /** + * @return string caption for the datagrid + */ + public function getCaption() + { + return $this->getViewState('Caption',''); + } + + /** + * @param string caption for the datagrid + */ + public function setCaption($value) + { + $this->setViewState('Caption',$value,''); + } + + /** + * @return string datagrid caption alignment. Defaults to 'NotSet'. + */ + public function getCaptionAlign() + { + return $this->getViewState('CaptionAlign','NotSet'); + } + + /** + * @param string datagrid caption alignment. Valid values include + * 'NotSet','Top','Bottom','Left','Right'. + */ + public function setCaptionAlign($value) + { + $this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'NotSet','Top','Bottom','Left','Right'),'NotSet'); + } + /** * @return TDataGridItem the header item */ @@ -1443,6 +1476,23 @@ class TDataGrid extends TBaseDataList implements INamingContainer } } + /** + * Renders the openning tag for the datagrid control which will render table caption if present. + * @param THtmlWriter the writer used for the rendering purpose + */ + public function renderBeginTag($writer) + { + parent::renderBeginTag($writer); + if(($caption=$this->getCaption())!=='') + { + if(($align=$this->getCaptionAlign())!=='NotSet') + $writer->addAttribute('align',strtolower($align)); + $writer->renderBeginTag('caption'); + $writer->write($caption); + $writer->renderEndTag(); + } + } + /** * Renders the datagrid. * @param THtmlWriter writer for the rendering purpose @@ -1457,12 +1507,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer $this->_topPager->renderControl($writer); $writer->writeLine(); } - $this->renderBeginTag($writer); - $this->_header->renderControl($writer); - foreach($this->getItems() as $item) - $item->renderControl($writer); - $this->_footer->renderControl($writer); - $this->renderEndTag($writer); + $this->renderTable($writer); if($this->_bottomPager) { $writer->writeLine(); @@ -1470,6 +1515,38 @@ class TDataGrid extends TBaseDataList implements INamingContainer } } } + + /** + * Renders the tabular data. + * @param THtmlWriter writer + */ + protected function renderTable($writer) + { + $this->renderBeginTag($writer); + if($this->_header->getVisible()) + { + $writer->writeLine(); + $writer->renderBeginTag('thead'); + $this->_header->render($writer); + $writer->renderEndTag(); + } + $writer->writeLine(); + $writer->renderBeginTag('tbody'); + foreach($this->getItems() as $item) + $item->renderControl($writer); + $writer->renderEndTag(); + + if($this->_footer->getVisible()) + { + $writer->writeLine(); + $writer->renderBeginTag('tfoot'); + $this->_footer->render($writer); + $writer->renderEndTag(); + } + + $writer->writeLine(); + $this->renderEndTag($writer); + } } /** @@ -1758,6 +1835,10 @@ class TDataGridItem extends TTableRow implements INamingContainer $this->_itemIndex=$itemIndex; $this->_dataSourceIndex=$dataSourceIndex; $this->setItemType($itemType); + if($itemType===TDataGrid::IT_HEADER) + $this->setTableSection('Header'); + else if($itemType===TDataGrid::IT_FOOTER) + $this->setTableSection('Footer'); } /** diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php index 10c49691..81b82c33 100644 --- a/framework/Web/UI/WebControls/TRepeatInfo.php +++ b/framework/Web/UI/WebControls/TRepeatInfo.php @@ -261,6 +261,7 @@ class TRepeatInfo extends TComponent // render items if($tableLayout) { + $writer->renderBeginTag('tbody'); $column=0; for($i=0;$i<$itemCount;++$i) { @@ -297,6 +298,7 @@ class TRepeatInfo extends TComponent $column=0; } } + $writer->renderEndTag(); } else { @@ -353,6 +355,7 @@ class TRepeatInfo extends TComponent if($tableLayout) { + $writer->renderBeginTag('tbody'); $renderedItems=0; for($row=0;$row<$rows;++$row) { @@ -407,6 +410,7 @@ class TRepeatInfo extends TComponent $writer->renderEndTag(); $writer->writeLine(); } + $writer->renderEndTag(); } else { @@ -461,6 +465,7 @@ class TRepeatInfo extends TComponent { if($tableLayout) { + $writer->renderBeginTag('thead'); $writer->renderBeginTag('tr'); if($columns>1) $writer->addAttribute('colspan',"$columns"); @@ -471,6 +476,7 @@ class TRepeatInfo extends TComponent $user->renderItem($writer,$this,'Header',-1); $writer->renderEndTag(); $writer->renderEndTag(); + $writer->renderEndTag(); } else { @@ -492,6 +498,7 @@ class TRepeatInfo extends TComponent { if($tableLayout) { + $writer->renderBeginTag('tfoot'); $writer->renderBeginTag('tr'); if($columns>1) $writer->addAttribute('colspan',"$columns"); @@ -501,6 +508,7 @@ class TRepeatInfo extends TComponent $user->renderItem($writer,$this,'Footer',-1); $writer->renderEndTag(); $writer->renderEndTag(); + $writer->renderEndTag(); } else $user->renderItem($writer,$this,'Footer',-1); -- cgit v1.2.3