summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TListControl.php
diff options
context:
space:
mode:
authorxue <>2005-12-22 21:22:22 +0000
committerxue <>2005-12-22 21:22:22 +0000
commit5c0517b7748dcfae1264d28df7ea111a67bd3aa4 (patch)
treed3756f95c16e09f2404bd8d7859d10f7aee1b000 /framework/Web/UI/WebControls/TListControl.php
parentda7bb7a797e298418a8b45580bba6d50073fa09f (diff)
Diffstat (limited to 'framework/Web/UI/WebControls/TListControl.php')
-rw-r--r--framework/Web/UI/WebControls/TListControl.php63
1 files changed, 58 insertions, 5 deletions
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php
index c965ddb0..7e81fd6c 100644
--- a/framework/Web/UI/WebControls/TListControl.php
+++ b/framework/Web/UI/WebControls/TListControl.php
@@ -54,9 +54,47 @@ abstract class TListControl extends TDataBoundControl
$this->getItems()->add($object);
}
+ protected function validateDataSource($value)
+ {
+ if(is_string($value))
+ {
+ $list=new TList;
+ foreach(TPropertyValue::ensureArray($value) as $key=>$value)
+ $list->add(array($value,is_string($key)?$key:$value));
+ return $list;
+ }
+ else
+ return parent::validateDataSource($value);
+ return $value;
+ }
+
protected function performDataBinding($data)
{
- // TODO;
+ if($data instanceof Traversable)
+ {
+ $textField=$this->getDataTextField();
+ if($textField==='')
+ $textField=0;
+ $valueField=$this->getDataValueField();
+ if($valueField==='')
+ $valueField=1;
+ $textFormat=$this->getDataTextFormatString();
+ $items=$this->getItems();
+ if(!$this->getAppendDataBoundItems())
+ $items->clear();
+ foreach($data as $object)
+ {
+ $item=new TListItem;
+ if(isset($object[$textField]))
+ $text=$object[$textField];
+ else
+ $text=TPropertyValue::ensureString($object);
+ $item->setText($textFormat===''?$text:sprintf($textFormat,$text));
+ if(isset($object[$valueField]))
+ $item->setValue($object[$valueField]);
+ $items->add($item);
+ }
+ }
}
protected function onSaveState($param)
@@ -204,7 +242,7 @@ abstract class TListControl extends TDataBoundControl
$index=TPropertyValue::ensureInteger($index);
if($this->_items)
{
- $this->_items->clearSelection();
+ $this->clearSelection();
if($index>=0 && $index<$this->_items->getCount())
$this->_items->itemAt($index)->setSelected(true);
}
@@ -223,6 +261,20 @@ abstract class TListControl extends TDataBoundControl
return $selections;
}
+ protected function setSelectedIndices($indices)
+ {
+ if($this->_items)
+ {
+ $this->clearSelection();
+ $n=$this->_items->getCount();
+ foreach($indices as $index)
+ {
+ if($index>=0 && $index<$n)
+ $this->_items->itemAt($index)->setSelected(true);
+ }
+ }
+ }
+
/**
* @return TListItem|null the selected item with the lowest cardinal index, null if no selection.
*/
@@ -308,6 +360,7 @@ abstract class TListControl extends TDataBoundControl
$this->raiseEvent('SelectedIndexChanged',$this,$param);
}
+ // ????
public function onTextChanged($param)
{
$this->raiseEvent('TextChanged',$this,$param);
@@ -351,12 +404,12 @@ class TListItemCollection extends TList
throw new TInvalidDataTypeException('listitemcollection_item_invalid');
}
- public function addAt($index,$item)
+ public function insert($index,$item)
{
if(is_string($item))
- parent::addAt($index,new TListItem($item));
+ parent::insert($index,new TListItem($item));
else if($item instanceof TListItem)
- parent::addAt($index,$item);
+ parent::insert($index,$item);
else
throw new TInvalidDataTypeException('listitemcollection_item_invalid');
}