summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2006-01-01 21:28:57 +0000
committerxue <>2006-01-01 21:28:57 +0000
commitf618592c07c32c4955367a4c5bf9c4e18727cefe (patch)
tree05fea8cc46f84307d41e30f61fd008b88435972c /framework/Web
parentc4ffe5fe2b3556f0fcbf6f7a28ef09ce24d06e74 (diff)
Enhanced support to attribute access.
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/UI/TControl.php8
-rw-r--r--framework/Web/UI/WebControls/TListBox.php2
-rw-r--r--framework/Web/UI/WebControls/TListControl.php65
-rw-r--r--framework/Web/UI/WebControls/TRadioButton.php2
-rw-r--r--framework/Web/UI/WebControls/TRepeatInfo.php4
-rw-r--r--framework/Web/UI/WebControls/TWebControl.php4
6 files changed, 70 insertions, 15 deletions
diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php
index 545bdf66..03d962f4 100644
--- a/framework/Web/UI/TControl.php
+++ b/framework/Web/UI/TControl.php
@@ -506,14 +506,14 @@ class TControl extends TComponent
}
/**
- * @return string attribute value, '' if attribute does not exist
+ * @return string attribute value, null if attribute does not exist
*/
public function getAttribute($name)
{
if($attributes=$this->getViewState('Attributes',null))
return $attributes->itemAt($name);
else
- return '';
+ return null;
}
/**
@@ -528,14 +528,14 @@ class TControl extends TComponent
/**
* Removes the named attribute.
* @param string the name of the attribute to be removed.
- * @return string attribute value removed, empty string if attribute does not exist.
+ * @return string attribute value removed, null if attribute does not exist.
*/
public function removeAttribute($name)
{
if($attributes=$this->getViewState('Attributes',null))
return $attributes->remove($name);
else
- return '';
+ return null;
}
/**
diff --git a/framework/Web/UI/WebControls/TListBox.php b/framework/Web/UI/WebControls/TListBox.php
index 7f47a49e..02e07013 100644
--- a/framework/Web/UI/WebControls/TListBox.php
+++ b/framework/Web/UI/WebControls/TListBox.php
@@ -130,7 +130,7 @@ class TListBox extends TListControl implements IPostBackDataHandler
* Sets the selection mode of the component (Single, Multiple)
* @param string the selection mode
*/
- function setSelectionMode($value)
+ public function setSelectionMode($value)
{
$this->setViewState('SelectionMode',TPropertyValue::ensureEnum($value,array('Single','Multiple')),'Single');
}
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index ec7df0c9..b32471fb 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -213,6 +213,11 @@ abstract class TListControl extends TDataBoundControl
$this->setViewState('DataValueField',$value,'');
}
+ public function getHasItems()
+ {
+ return ($this->_items && $this->_items->getCount()>0);
+ }
+
public function getItems()
{
if(!$this->_items)
@@ -376,12 +381,18 @@ abstract class TListControl extends TDataBoundControl
{
if($item->getEnabled())
{
- $str='<option';
if($item->getSelected())
- $str.=' selected="selected"';
- $str.=' value="'.THttpUtility::htmlEncode($item->getValue()).'"';
- $str.='>'.THttpUtility::htmlEncode($item->getText()).'</option>';
- $writer->writeLine($str);
+ $writer->addAttribute('selected','selected');
+ $writer->addAttribute('value',$item->getValue());
+ if($item->getHasAttributes())
+ {
+ foreach($item->getAttributes() as $name=>$value)
+ $writer->addAttribute($name,$value);
+ }
+ $writer->renderBeginTag('option');
+ $writer->write(THttpUtility::htmlEncode($item->getText()));
+ $writer->renderEndTag();
+ $writer->writeLine();
}
}
}
@@ -533,6 +544,50 @@ class TListItem extends TComponent
{
$this->_value=TPropertyValue::ensureString($value);
}
+
+ public function getAttributes()
+ {
+ if(!$this->_attributes)
+ $this->_attributes=new TMap;
+ return $this->_attributes;
+ }
+
+ public function getHasAttributes()
+ {
+ return $this->_attributes!==null;
+ }
+
+ public function hasAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->contains($name):false;
+ }
+
+ /**
+ * @return string attribute value, '' if attribute does not exist
+ */
+ public function getAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->itemAt($name):null;
+ }
+
+ /**
+ * @param string attribute name
+ * @param string value of the attribute
+ */
+ public function setAttribute($name,$value)
+ {
+ $this->getAttributes()->add($name,$value);
+ }
+
+ /**
+ * Removes the named attribute.
+ * @param string the name of the attribute to be removed.
+ * @return string attribute value removed, empty string if attribute does not exist.
+ */
+ public function removeAttribute($name)
+ {
+ return $this->_attributes?$this->_attributes->remove($name):null;
+ }
}
?> \ No newline at end of file
diff --git a/framework/Web/UI/WebControls/TRadioButton.php b/framework/Web/UI/WebControls/TRadioButton.php
index 85a28941..d7901ec8 100644
--- a/framework/Web/UI/WebControls/TRadioButton.php
+++ b/framework/Web/UI/WebControls/TRadioButton.php
@@ -128,7 +128,7 @@ class TRadioButton extends TCheckBox
*/
private function getValueAttribute()
{
- if(($value=$this->getAttribute('value'))==='')
+ if(($value=$this->getAttribute('value'))===null)
{
$value=$this->getID();
return empty($value)?$this->getUniqueID():$value;
diff --git a/framework/Web/UI/WebControls/TRepeatInfo.php b/framework/Web/UI/WebControls/TRepeatInfo.php
index 414f5db9..ffb10c12 100644
--- a/framework/Web/UI/WebControls/TRepeatInfo.php
+++ b/framework/Web/UI/WebControls/TRepeatInfo.php
@@ -2,12 +2,12 @@
interface IRepeatInfoUser
{
- public function getItemStyle($itemType,$index);
- public function renderItem($writer,$repeatInfo,$itemType,$index);
public function getHasFooter();
public function getHasHeader();
public function getHasSeparators();
public function getRepeatedItemCount();
+ public function getItemStyle($itemType,$index);
+ public function renderItem($writer,$repeatInfo,$itemType,$index);
}
class TRepeatInfo extends TComponent
diff --git a/framework/Web/UI/WebControls/TWebControl.php b/framework/Web/UI/WebControls/TWebControl.php
index e86b9161..8ef47ede 100644
--- a/framework/Web/UI/WebControls/TWebControl.php
+++ b/framework/Web/UI/WebControls/TWebControl.php
@@ -352,9 +352,9 @@ class TWebControl extends TControl
$writer->addAttribute('title',$toolTip);
if($style=$this->getViewState('Style',null))
$style->addAttributesToRender($writer);
- if($attributes=$this->getViewState('Attributes',null))
+ if($this->getHasAttributes())
{
- foreach($attributes as $name=>$value)
+ foreach($this->getAttributes() as $name=>$value)
$writer->addAttribute($name,$value);
}
}