From 2617f1d34a9ec366fefea3db010748a2dcdb46a1 Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 27 Feb 2006 17:02:04 +0000 Subject: Added PushButton to pager in TDataGrid. --- framework/Web/UI/TPage.php | 114 +++++++++++++++++++++-------- framework/Web/UI/WebControls/TDataGrid.php | 107 +++++++++++++++++++-------- 2 files changed, 160 insertions(+), 61 deletions(-) (limited to 'framework/Web/UI') diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php index 60397260..cb49d325 100644 --- a/framework/Web/UI/TPage.php +++ b/framework/Web/UI/TPage.php @@ -34,8 +34,9 @@ class TPage extends TTemplateControl const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER'; const FIELD_LASTFOCUS='PRADO_LASTFOCUS'; const FIELD_PAGESTATE='PRADO_PAGESTATE'; - const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID'; + const FIELD_CALLBACK_TARGET='PRADO_CALLBACK_TARGET'; const FIELD_CALLBACK_PARAMETER='PRADO_CALLBACK_PARAMETER'; + const FIELD_CALLBACK_ID='PRADO_CALLBACK_ID'; /** * @var array system post fields */ @@ -44,8 +45,9 @@ class TPage extends TTemplateControl 'PRADO_POSTBACK_PARAMETER'=>true, 'PRADO_LASTFOCUS'=>true, 'PRADO_PAGESTATE'=>true, - 'PRADO_CALLBACK_ID'=>true, - 'PRADO_CALLBACK_PARAMETER'=>true + 'PRADO_CALLBACK_TARGET'=>true, + 'PRADO_CALLBACK_PARAMETER'=>true, + 'PRADO_CALLBACK_ID'=>true ); /** * @var TForm form instance @@ -155,6 +157,19 @@ class TPage extends TTemplateControl Prado::trace("Running page life cycles",'System.Web.UI.TPage'); $this->determinePostBackMode(); + if($this->getIsPostBack()) + { + if($this->getIsCallback()) + $this->processCallbackRequest($writer); + else + $this->processPostBackRequest($writer); + } + else + $this->processNormalRequest($writer); + } + + protected function processNormalRequest($writer) + { Prado::trace("Page onPreInit()",'System.Web.UI.TPage'); $this->onPreInit(null); @@ -164,35 +179,57 @@ class TPage extends TTemplateControl Prado::trace("Page onInitComplete()",'System.Web.UI.TPage'); $this->onInitComplete(null); - if($this->getIsPostBack()) - { - $this->_restPostData=new TMap; - Prado::trace("Page loadPageState()",'System.Web.UI.TPage'); - $this->loadPageState(); - Prado::trace("Page processPostData()",'System.Web.UI.TPage'); - $this->processPostData($this->_postData,true); - Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); - $this->onPreLoad(null); - Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); - $this->loadRecursive(); - Prado::trace("Page processPostData()",'System.Web.UI.TPage'); - $this->processPostData($this->_restPostData,false); - Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage'); - $this->raiseChangedEvents(); - Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage'); - $this->raisePostBackEvent(); - Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); - $this->onLoadComplete(null); - } - else - { - Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); - $this->onPreLoad(null); - Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); - $this->loadRecursive(); - Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); - $this->onLoadComplete(null); - } + Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); + $this->onPreLoad(null); + Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); + $this->loadRecursive(); + Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); + $this->onLoadComplete(null); + + Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage'); + $this->preRenderRecursive(); + Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage'); + $this->onPreRenderComplete(null); + + Prado::trace("Page savePageState()",'System.Web.UI.TPage'); + $this->savePageState(); + Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage'); + $this->onSaveStateComplete(null); + + Prado::trace("Page renderControl()",'System.Web.UI.TPage'); + $this->renderControl($writer); + Prado::trace("Page unloadRecursive()",'System.Web.UI.TPage'); + $this->unloadRecursive(); + } + + protected function processPostBackRequest($writer) + { + Prado::trace("Page onPreInit()",'System.Web.UI.TPage'); + $this->onPreInit(null); + + Prado::trace("Page initRecursive()",'System.Web.UI.TPage'); + $this->initRecursive(); + + Prado::trace("Page onInitComplete()",'System.Web.UI.TPage'); + $this->onInitComplete(null); + + $this->_restPostData=new TMap; + Prado::trace("Page loadPageState()",'System.Web.UI.TPage'); + $this->loadPageState(); + Prado::trace("Page processPostData()",'System.Web.UI.TPage'); + $this->processPostData($this->_postData,true); + Prado::trace("Page onPreLoad()",'System.Web.UI.TPage'); + $this->onPreLoad(null); + Prado::trace("Page loadRecursive()",'System.Web.UI.TPage'); + $this->loadRecursive(); + Prado::trace("Page processPostData()",'System.Web.UI.TPage'); + $this->processPostData($this->_restPostData,false); + Prado::trace("Page raiseChangedEvents()",'System.Web.UI.TPage'); + $this->raiseChangedEvents(); + Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage'); + $this->raisePostBackEvent(); + Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage'); + $this->onLoadComplete(null); Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage'); $this->preRenderRecursive(); @@ -210,6 +247,10 @@ class TPage extends TTemplateControl $this->unloadRecursive(); } + protected function processCallbackRequest($writer) + { + } + /** * @return TForm the form on the page */ @@ -487,6 +528,15 @@ class TPage extends TTemplateControl return $this->_postData!==null; } + /** + * TBD + * @return boolean whether this is a callback request + */ + public function getIsCallback() + { + return false; + } + /** * This method is invoked when control state is to be saved. * You can override this method to do last step state saving. diff --git a/framework/Web/UI/WebControls/TDataGrid.php b/framework/Web/UI/WebControls/TDataGrid.php index 367b2c9b..b70e84fc 100644 --- a/framework/Web/UI/WebControls/TDataGrid.php +++ b/framework/Web/UI/WebControls/TDataGrid.php @@ -1087,6 +1087,27 @@ class TDataGrid extends TBaseDataList implements INamingContainer } } + /** + * Creates a pager button. + * @param string button type, LinkButton or PushButton + * @param boolean whether the button should be enabled + * @return mixed the button instance + */ + protected function createPagerButton($buttonType,$enabled) + { + if($buttonType==='LinkButton') + { + return $enabled?new TLinkButton:new TLabel; + } + else + { + $button=new TButton; + if(!$enabled) + $button->setEnabled(false); + return $button; + } + } + /** * Builds a next-prev pager * @param TTableCell table cell for the pager @@ -1095,16 +1116,17 @@ class TDataGrid extends TBaseDataList implements INamingContainer protected function buildNextPrevPager($cell,$dataSource) { $style=$this->getPagerStyle(); + $buttonType=$style->getButtonType(); $controls=$cell->getControls(); if($dataSource->getIsFirstPage()) { - $label=new TLabel; + $label=$this->createPagerButton($buttonType,false); $label->setText($style->getPrevPageText()); $controls->add($label); } else { - $button=new TLinkButton; + $button=$this->createPagerButton($buttonType,true); $button->setText($style->getPrevPageText()); $button->setCommandName('page'); $button->setCommandParameter('prev'); @@ -1114,13 +1136,13 @@ class TDataGrid extends TBaseDataList implements INamingContainer $controls->add(' '); if($dataSource->getIsLastPage()) { - $label=new TLabel; + $label=$this->createPagerButton($buttonType,false); $label->setText($style->getNextPageText()); $controls->add($label); } else { - $button=new TLinkButton; + $button=$this->createPagerButton($buttonType,true); $button->setText($style->getNextPageText()); $button->setCommandName('page'); $button->setCommandParameter('next'); @@ -1137,6 +1159,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer protected function buildNumericPager($cell,$dataSource) { $style=$this->getPagerStyle(); + $buttonType=$style->getButtonType(); $controls=$cell->getControls(); $pageCount=$dataSource->getPageCount(); $pageIndex=$dataSource->getCurrentPageIndex()+1; @@ -1158,7 +1181,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer if($startPageIndex>1) { - $button=new TLinkButton; + $button=$this->createPagerButton($buttonType,true); $button->setText($style->getPrevPageText()); $button->setCommandName('page'); $button->setCommandParameter($startPageIndex-1); @@ -1171,13 +1194,13 @@ class TDataGrid extends TBaseDataList implements INamingContainer { if($i===$pageIndex) { - $label=new TLabel; + $label=$this->createPagerButton($buttonType,false); $label->setText("$i"); $controls->add($label); } else { - $button=new TLinkButton; + $button=$this->createPagerButton($buttonType,true); $button->setText("$i"); $button->setCommandName('page'); $button->setCommandParameter($i); @@ -1191,7 +1214,7 @@ class TDataGrid extends TBaseDataList implements INamingContainer if($pageCount>$endPageIndex) { $controls->add(' '); - $button=new TLinkButton; + $button=$this->createPagerButton($buttonType,true); $button->setText($style->getNextPageText()); $button->setCommandName('page'); $button->setCommandParameter($endPageIndex+1); @@ -1824,6 +1847,7 @@ class TDataGridPagerStyle extends TTableItemStyle private $_buttonCount=null; private $_position=null; private $_visible=null; + private $_buttonType=null; /** * @return string pager mode. Defaults to 'NextPrev'. @@ -1841,6 +1865,22 @@ class TDataGridPagerStyle extends TTableItemStyle $this->_mode=TPropertyValue::ensureEnum($value,'NextPrev','Numeric'); } + /** + * @return string the type of command button. Defaults to LinkButton. + */ + public function getButtonType() + { + return $this->_buttonType===null?'LinkButton':$this->_buttonType; + } + + /** + * @param string the type of command button, LinkButton or PushButton + */ + public function setButtonType($value) + { + $this->_buttonType=TPropertyValue::ensureEnum($value,'LinkButton','PushButton'); + } + /** * @return string text for the next page button. Defaults to '>'. */ @@ -1936,34 +1976,41 @@ class TDataGridPagerStyle extends TTableItemStyle $this->_prevText=null; $this->_nextText=null; $this->_mode=null; + $this->_buttonType=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 + * Copies the fields in a new style to this style. + * If a style field is set in the new style, the corresponding field + * in this style will be overwritten. + * @param TStyle the new 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; + if($style->_visible!==null) + $this->_visible=$style->_visible; + if($style->_position!==null) + $this->_position=$style->_position; + if($style->_buttonCount!==null) + $this->_buttonCount=$style->_buttonCount; + if($style->_prevText!==null) + $this->_prevText=$style->_prevText; + if($style->_nextText!==null) + $this->_nextText=$style->_nextText; + if($style->_mode!==null) + $this->_mode=$style->_mode; + if($style->_buttonType!==null) + $this->_buttonType=$style->_buttonType; } } /** - * Merges with a style. - * If a style field is set in the new style, the current style field - * will be overwritten. - * This method overrides the parent implementation by - * merging with additional TDataGridPagerStyle specific attributes. + * Merges the style with a new one. + * If a style field is not set in this style, it will be overwritten by + * the new one. * @param TStyle the new style */ public function mergeWith($style) @@ -1971,18 +2018,20 @@ class TDataGridPagerStyle extends TTableItemStyle parent::mergeWith($style); if($style instanceof TDataGridPagerStyle) { - if($style->_visible!==null) + if($this->_visible===null) $this->_visible=$style->_visible; - if($style->_position!==null) + if($this->_position===null) $this->_position=$style->_position; - if($style->_buttonCount!==null) + if($this->_buttonCount===null) $this->_buttonCount=$style->_buttonCount; - if($style->_prevText!==null) + if($this->_prevText===null) $this->_prevText=$style->_prevText; - if($style->_nextText!==null) + if($this->_nextText===null) $this->_nextText=$style->_nextText; - if($style->_mode!==null) + if($this->_mode===null) $this->_mode=$style->_mode; + if($this->_buttonType===null) + $this->_buttonType=$style->_buttonType; } } } -- cgit v1.2.3