From f9f431ec8e564465d08a18d9b402ed8643841fa1 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sun, 1 Jan 2006 22:58:37 +0000 Subject: Added initial TCheckBoxList implementation. --- framework/Web/UI/WebControls/TCheckBoxList.php | 237 +++++++++++++++++++++++++ framework/Web/UI/WebControls/TPanel.php | 4 +- framework/Web/UI/WebControls/TRepeatInfo.php | 16 +- framework/Web/UI/WebControls/TWebControl.php | 4 +- 4 files changed, 247 insertions(+), 14 deletions(-) create mode 100644 framework/Web/UI/WebControls/TCheckBoxList.php (limited to 'framework/Web/UI/WebControls') diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php new file mode 100644 index 00000000..31d06ef9 --- /dev/null +++ b/framework/Web/UI/WebControls/TCheckBoxList.php @@ -0,0 +1,237 @@ +_repeatedControl=new TCheckBox; + $this->_repeatedControl->setEnableViewState(false); + $this->_repeatedControl->setID('0'); + $this->getControls()->add($this->_repeatedControl); + } + + public function findControl($id) + { + return $this; + } + + protected function getIsMultiSelect() + { + return true; + } + + protected function createStyle() + { + return new TTableStyle; + } + + protected function getRepeatInfo() + { + if(($repeatInfo=$this->getViewState('RepeatInfo',null))===null) + { + $repeatInfo=new TRepeatInfo; + $this->setViewState('RepeatInfo',$repeatInfo,null); + } + return $repeatInfo; + } + + /** + * @return string the alignment of the text caption, defaults to 'Right'. + */ + public function getTextAlign() + { + return $this->getViewState('TextAlign','Right'); + } + + /** + * Sets the text alignment of the checkboxes + * @param string either 'Left' or 'Right' + */ + public function setTextAlign($value) + { + $this->setViewState('TextAlign',TPropertyValue::ensureEnum($value,array('Left','Right')),'Right'); + } + + /** + * @return integer the number of columns that the list should be displayed with. Defaults to 0 meaning not set. + */ + public function getRepeatColumns() + { + return $this->getRepeatInfo()->getRepeatColumns(); + } + + /** + * Sets the number of columns that the list should be displayed with. + * @param integer the number of columns that the list should be displayed with. + */ + public function setRepeatColumns($value) + { + $this->getRepeatInfo()->setRepeatColumns($value); + } + + /** + * @return string the direction of traversing the list, defaults to 'Vertical' + */ + public function getRepeatDirection() + { + return $this->getRepeatInfo()->getRepeatDirection(); + } + + /** + * Sets the direction of traversing the list (Vertical, Horizontal) + * @param string the direction of traversing the list + */ + public function setRepeatDirection($value) + { + $this->getRepeatInfo()->setRepeatDirection($value); + } + + /** + * @return string how the list should be displayed, using table or using line breaks. Defaults to 'Table'. + */ + public function getRepeatLayout() + { + return $this->getRepeatInfo()->getRepeatLayout(); + } + + /** + * Sets how the list should be displayed, using table or using line breaks (Table, Flow) + * @param string how the list should be displayed, using table or using line breaks (Table, Flow) + */ + public function setRepeatLayout($value) + { + $this->getRepeatInfo()->setRepeatLayout($value); + } + + /** + * @return integer the cellspacing for the table keeping the checkbox list. Defaults to -1, meaning not set. + */ + public function getCellSpacing() + { + if($this->getHasStyle()) + return $this->getStyle()->getCellSpacing(); + else + return -1; + } + + /** + * Sets the cellspacing for the table keeping the checkbox list. + * @param integer the cellspacing for the table keeping the checkbox list. + */ + public function setCellSpacing($value) + { + $this->getStyle()->setCellSpacing($value); + } + + /** + * @return integer the cellpadding for the table keeping the checkbox list. Defaults to -1, meaning not set. + */ + public function getCellPadding() + { + if($this->getHasStyle()) + return $this->getStyle()->getCellPadding(); + else + return -1; + } + + /** + * Sets the cellpadding for the table keeping the checkbox list. + * @param integer the cellpadding for the table keeping the checkbox list. + */ + public function setCellPadding($value) + { + $this->getStyle()->setCellPadding($value); + } + + public function loadPostData($key,$values) + { + } + + public function raisePostDataChangedEvent() + { + } + + public function getHasHeader() + { + return false; + } + + public function getHasFooter() + { + return false; + } + + public function getHasSeparators() + { + return false; + } + + public function getItemStyle($itemType,$index) + { + return null; + } + + public function getRepeatedItemCount() + { + if($this->getHasItems()) + return $this->getItems()->getCount(); + else + return 0; + } + + public function renderItem($writer,$repeatInfo,$itemType,$index) + { + $item=$this->getItems()->itemAt($index); + if($item->getHasAttributes()) + $this->_repeatedControl->getAttributes()->copyFrom($item->getAttributes()); + else if($this->_repeatedControl->getHasAttributes()) + $this->_repeatedControl->getAttributes()->clear(); + $this->_repeatedControl->setID("$index"); + $this->_repeatedControl->setText($item->getText()); + $this->_repeatedControl->setChecked($item->getSelected()); + $this->_repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled()); + $this->_repeatedControl->renderControl($writer); + } + + protected function onPreRender($param) + { + parent::onPreRender($param); + $this->_repeatedControl->setAutoPostBack($this->getAutoPostBack()); + $this->_repeatedControl->setCausesValidation($this->getCausesValidation()); + $this->_repeatedControl->setValidationGroup($this->getValidationGroup()); + $page=$this->getPage(); + $n=$this->getRepeatedItemCount(); + for($i=0;$i<$n;++$i) + { + $this->_repeatedControl->setID("$i"); + $page->registerRequiresPostData($this->_repeatedControl); + } + } + + protected function render($writer) + { + if($this->getRepeatedItemCount()>0) + { + $this->_isEnabled=$this->getEnabled(true); + $repeatInfo=$this->getRepeatInfo(); + $accessKey=$this->getAccessKey(); + $tabIndex=$this->getTabIndex(); + $this->_repeatedControl->setTextAlign($this->getTextAlign()); + $this->_repeatedControl->setAccessKey($accessKey); + $this->_repeatedControl->setTabIndex($tabIndex); + $this->setAccessKey(''); + $this->setTabIndex(0); + $repeatInfo->renderRepeater($writer,$this); + $this->setAccessKey($accessKey); + $this->setTabIndex($tabIndex); + } + } +} + +?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/TPanel.php b/framework/Web/UI/WebControls/TPanel.php index eeee4d59..c7464c7c 100644 --- a/framework/Web/UI/WebControls/TPanel.php +++ b/framework/Web/UI/WebControls/TPanel.php @@ -204,7 +204,7 @@ class TPanel extends TWebControl * Renders the openning tag for the control (including attributes) * @param THtmlWriter the writer used for the rendering purpose */ - protected function renderBeginTag($writer) + public function renderBeginTag($writer) { parent::renderBeginTag($writer); if(($text=$this->getGroupingText())!=='') @@ -220,7 +220,7 @@ class TPanel extends TWebControl * Renders the closing tag for the control * @param THtmlWriter the writer used for the rendering purpose */ - protected function renderEndTag($writer) + public function renderEndTag($writer) { if($this->getGroupingText()!=='') $writer->renderEndTag(); diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php index ffb10c12..66584ded 100644 --- a/framework/Web/UI/WebControls/TRepeatInfo.php +++ b/framework/Web/UI/WebControls/TRepeatInfo.php @@ -92,7 +92,7 @@ class TRepeatInfo extends TComponent else $this->renderHorizontalContents($writer,$user); - $control->renderEndTag(); + $control->renderEndTag($writer); } protected function renderHorizontalContents($writer,$user) @@ -251,7 +251,6 @@ class TRepeatInfo extends TComponent for($row=0;$row<$rows;++$row) { $index=$row; - $writer->renderBeginTag('tr'); for($col=0;$col<$columns;++$col) { if($renderedItems>=$itemCount) @@ -273,8 +272,6 @@ class TRepeatInfo extends TComponent $writer->writeBreak(); $user->renderItem($writer,$this,'Separator',$index); } - else if($columns>1) - $writer->write(''); } if($row<$rows-1 || $user->getHasFooter()) $writer->writeBreak(); @@ -297,13 +294,13 @@ class TRepeatInfo extends TComponent if(($style=$user->getItemStyle('Header',-1))!==null) $style->addAttributesToRender($writer); $writer->renderBeginTag('th'); - $user->renderItem($writer,$this,'Header',-1) + $user->renderItem($writer,$this,'Header',-1); $writer->renderEndTag(); $writer->renderEndTag(); } else { - $user->renderItem($writer,$this,'Header',-1) + $user->renderItem($writer,$this,'Header',-1); if($needBreak) $writer->writeBreak(); } @@ -316,16 +313,15 @@ class TRepeatInfo extends TComponent $writer->renderBeginTag('tr'); if($columns>1) $writer->addAttribute('colspan',"$columns"); - $writer->addAttribute('scope','col'); - if(($style=$user->getItemStyle('Header',-1))!==null) + if(($style=$user->getItemStyle('Footer',-1))!==null) $style->addAttributesToRender($writer); $writer->renderBeginTag('td'); - $user->renderItem($writer,$this,'Header',-1) + $user->renderItem($writer,$this,'Footer',-1); $writer->renderEndTag(); $writer->renderEndTag(); } else - $user->renderItem($writer,$this,'Header',-1) + $user->renderItem($writer,$this,'Footer',-1); } } diff --git a/framework/Web/UI/WebControls/TWebControl.php b/framework/Web/UI/WebControls/TWebControl.php index 8ef47ede..ba6fe04c 100644 --- a/framework/Web/UI/WebControls/TWebControl.php +++ b/framework/Web/UI/WebControls/TWebControl.php @@ -379,7 +379,7 @@ class TWebControl extends TControl * Renders the openning tag for the control (including attributes) * @param THtmlWriter the writer used for the rendering purpose */ - protected function renderBeginTag($writer) + public function renderBeginTag($writer) { $this->addAttributesToRender($writer); $writer->renderBeginTag($this->getTagName()); @@ -400,7 +400,7 @@ class TWebControl extends TControl * Renders the closing tag for the control * @param THtmlWriter the writer used for the rendering purpose */ - protected function renderEndTag($writer) + public function renderEndTag($writer) { $writer->renderEndTag(); } -- cgit v1.2.3