summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2006-01-02 20:59:17 +0000
committerxue <>2006-01-02 20:59:17 +0000
commit4d8ed423f7b4a8eae2898cc5552829595717a581 (patch)
tree69d23707abe6eedf9eda943fe029004aad39ccc8 /framework/Web
parent2df9a40f504933e28ddb9974b97ae4b2bb893f86 (diff)
TCheckBoxList and TRadioButtonList completed.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/UI/WebControls/TCheckBoxList.php49
-rw-r--r--framework/Web/UI/WebControls/TListControl.php4
-rw-r--r--framework/Web/UI/WebControls/TRadioButtonList.php26
-rw-r--r--framework/Web/UI/WebControls/TRepeatInfo.php1
-rw-r--r--framework/Web/UI/WebControls/TStyle.php114
5 files changed, 132 insertions, 62 deletions
diff --git a/framework/Web/UI/WebControls/TCheckBoxList.php b/framework/Web/UI/WebControls/TCheckBoxList.php
index c4addcdd..f351acba 100644
--- a/framework/Web/UI/WebControls/TCheckBoxList.php
+++ b/framework/Web/UI/WebControls/TCheckBoxList.php
@@ -6,6 +6,7 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
{
private $_repeatedControl;
private $_isEnabled;
+ private $_changedEventRaised=false;
public function __construct()
{
@@ -154,14 +155,6 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
$this->getStyle()->setCellPadding($value);
}
- public function loadPostData($key,$values)
- {
- }
-
- public function raisePostDataChangedEvent()
- {
- }
-
public function getHasHeader()
{
return false;
@@ -200,10 +193,50 @@ class TCheckBoxList extends TListControl implements IRepeatInfoUser, INamingCont
$this->_repeatedControl->setID("$index");
$this->_repeatedControl->setText($item->getText());
$this->_repeatedControl->setChecked($item->getSelected());
+ $this->_repeatedControl->setAttribute('value',$item->getValue());
$this->_repeatedControl->setEnabled($this->_isEnabled && $item->getEnabled());
$this->_repeatedControl->renderControl($writer);
}
+ public function loadPostData($key,$values)
+ {
+ if($this->getEnabled(true))
+ {
+ $index=(int)substr($key,strlen($this->getUniqueID())+1);
+ $this->ensureDataBound();
+ if($index>=0 && $index<$this->getRepeatedItemCount())
+ {
+ $item=$this->getItems()->itemAt($index);
+ if($item->getEnabled())
+ {
+ $checked=isset($values[$key]);
+ if($item->getSelected()!=$checked)
+ {
+ $item->setSelected($checked);
+ if(!$this->_changedEventRaised)
+ {
+ $this->_changedEventRaised=true;
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ public function raisePostDataChangedEvent()
+ {
+ $page=$this->getPage();
+ if($this->getAutoPostBack() && !$page->getPostBackEventTarget())
+ {
+ $page->setPostBackEventTarget($this);
+ if($this->getCausesValidation())
+ $page->validate($this->getValidationGroup());
+ }
+ $this->onSelectedIndexChanged(null);
+ }
+
protected function onPreRender($param)
{
parent::onPreRender($param);
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index b32471fb..860cbc48 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -254,7 +254,7 @@ abstract class TListControl extends TDataBoundControl
}
}
- protected function getSelectedIndices()
+ public function getSelectedIndices()
{
$selections=array();
if($this->_items)
@@ -267,7 +267,7 @@ abstract class TListControl extends TDataBoundControl
return $selections;
}
- protected function setSelectedIndices($indices)
+ public function setSelectedIndices($indices)
{
if($this->_items)
{
diff --git a/framework/Web/UI/WebControls/TRadioButtonList.php b/framework/Web/UI/WebControls/TRadioButtonList.php
index 8d80745e..e434e709 100644
--- a/framework/Web/UI/WebControls/TRadioButtonList.php
+++ b/framework/Web/UI/WebControls/TRadioButtonList.php
@@ -2,17 +2,35 @@
class TRadioButtonList extends TCheckBoxList
{
- protected function createRepeatedControl()
+ protected function getIsMultiSelect()
{
- return new TRadioButton;
+ return false;
}
- public function loadPostData($key,$values)
+ protected function createRepeatedControl()
{
+ return new TRadioButton;
}
- public function raisePostDataChangedEvent()
+ public function loadPostData($key,$values)
{
+ $value=isset($values[$key])?$values[$key]:'';
+ $oldSelection=$this->getSelectedIndex();
+ $this->ensureDataBound();
+ foreach($this->getItems() as $index=>$item)
+ {
+ if($item->getEnabled() && $item->getValue()===$value)
+ {
+ if($index===$oldSelection)
+ return false;
+ else
+ {
+ $this->setSelectedIndex($index);
+ return true;
+ }
+ }
+ }
+ return false;
}
}
diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php
index 14b57cfb..d3178c0c 100644
--- a/framework/Web/UI/WebControls/TRepeatInfo.php
+++ b/framework/Web/UI/WebControls/TRepeatInfo.php
@@ -271,6 +271,7 @@ class TRepeatInfo extends TComponent
}
if($index>=$itemCount)
continue;
+ $renderedItems++;
$user->renderItem($writer,$this,'Item',$index);
$writer->writeLine();
if(!$hasSeparators)
diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php
index 4585cca3..bc77bfcf 100644
--- a/framework/Web/UI/WebControls/TStyle.php
+++ b/framework/Web/UI/WebControls/TStyle.php
@@ -259,14 +259,6 @@ class TStyle extends TComponent
}
/**
- * @param boolean if the style contains nothing
- */
- public function getIsEmpty()
- {
- return empty($this->_fields) && $this->_class==='' && $this->_customStyle==='' && (!$this->_font || $this->_font->getIsEmpty());
- }
-
- /**
* Resets the style to the original empty state.
*/
public function reset()
@@ -278,48 +270,19 @@ class TStyle extends TComponent
}
/**
- * Merges the current style with another one.
- * If the two styles have the same style field, the new one
- * will overwrite the current one.
- * @param TStyle the new style
- */
- public function mergeWith($style)
- {
- if($style===null)
- return;
- foreach($style->_fields as $name=>$value)
- $this->_fields[$name]=$value;
- if($style->_class!=='')
- $this->_class=$style->_class;
- if($style->_customStyle!=='')
- $this->_customStyle=$style->_customStyle;
- if($style->_font!==null)
- $this->getFont()->mergeWith($style->_font);
- }
-
- /**
* Copies from a style.
* Existing style will be reset first.
* @param TStyle the new style
*/
public function copyFrom($style)
{
- $this->reset();
- $this->mergeWith($style);
- }
-
- /**
- * Converts the style into a string representation suitable for rendering.
- * @return string the string representation of the style
- */
- public function toString()
- {
- $str='';
- foreach($this->_fields as $name=>$value)
- $str.=' '.$name.':'.$value.';';
- if($this->_font)
- $str.=$this->_font->toString();
- return $str;
+ $this->_fields=$style->_fields;
+ $this->_class=$style->_class;
+ $this->_customStyle=$style->_customStyle;
+ if($style->_font!==null)
+ $this->getFont()->copyFrom($style->_font);
+ else
+ $this->_font=null;
}
/**
@@ -378,6 +341,35 @@ class TTableStyle extends TStyle
*/
private $_gridLines='None';
+ /**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableStyle specific attributes.
+ */
+ public function reset()
+ {
+ $this->_backImageUrl='';
+ $this->_horizontalAlign='NotSet';
+ $this->_cellPadding=-1;
+ $this->_cellSpacing=-1;
+ $this->_gridLines='None';
+ }
+
+ /**
+ * Copies the style content from an existing style
+ * This method overrides the parent implementation by
+ * adding additional TTableStyle specific attributes.
+ * @param TStyle source style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ $this->_backImageUrl=$style->_backImageUrl;
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ $this->_cellPadding=$style->_cellPadding;
+ $this->_cellSpacing=$style->_cellSpacing;
+ $this->_gridLines=$style->_gridLines;
+ }
/**
* Adds attributes related to CSS styles to renderer.
@@ -387,10 +379,10 @@ class TTableStyle extends TStyle
public function addAttributesToRender($writer)
{
if(($url=trim($this->_backImageUrl))!=='')
- $this->setStyleField('background-image','url('.$url.')');
+ $writer->addStyleAttribute('background-image','url('.$url.')');
if($this->_horizontalAlign!=='NotSet')
- $this->setStyleField('text-align',strtolower($this->_horizontalAlign));
+ $writer->addStyleAttribute('text-align',strtolower($this->_horizontalAlign));
if($this->_cellPadding>=0)
$writer->addAttribute('cellpadding',"$this->_cellPadding");
@@ -399,7 +391,7 @@ class TTableStyle extends TStyle
{
$writer->addAttribute('cellspacing',"$this->_cellSpacing");
if($this->_cellSpacing===0)
- $this->setStyleField('border-collapse','collapse');
+ $writer->addStyleAttribute('border-collapse','collapse');
}
switch($this->_gridLines)
@@ -527,6 +519,32 @@ class TTableItemStyle extends TStyle
private $_wrap=true;
/**
+ * Sets the style attributes to default values.
+ * This method overrides the parent implementation by
+ * resetting additional TTableItemStyle specific attributes.
+ */
+ public function reset()
+ {
+ $this->_verticalAlign='NotSet';
+ $this->_horizontalAlign='NotSet';
+ $this->_wrap=true;
+ }
+
+ /**
+ * Copies the style content from an existing style
+ * This method overrides the parent implementation by
+ * adding additional TTableItemStyle specific attributes.
+ * @param TStyle source style
+ */
+ public function copyFrom($style)
+ {
+ parent::copyFrom($style);
+ $this->_verticalAlign=$style->_verticalAlign;
+ $this->_horizontalAlign=$style->_horizontalAlign;
+ $this->_wrap=$style->_wrap;
+ }
+
+ /**
* Adds attributes related to CSS styles to renderer.
* This method overrides the parent implementation.
* @param THtmlWriter the writer used for the rendering purpose
@@ -534,7 +552,7 @@ class TTableItemStyle extends TStyle
public function addAttributesToRender($writer)
{
if(!$this->_wrap)
- $this->setStyleField('nowrap','nowrap');
+ $writer->addStyleAttribute('nowrap','nowrap');
if($this->_horizontalAlign!=='NotSet')
$writer->addAttribute('align',strtolower($this->_horizontalAlign));