diff options
Diffstat (limited to 'framework/Web/UI')
-rw-r--r-- | framework/Web/UI/WebControls/TListControl.php | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/framework/Web/UI/WebControls/TListControl.php b/framework/Web/UI/WebControls/TListControl.php index 15b6ec94..1c65259c 100644 --- a/framework/Web/UI/WebControls/TListControl.php +++ b/framework/Web/UI/WebControls/TListControl.php @@ -94,6 +94,8 @@ abstract class TListControl extends TDataBoundControl */
private $_cachedSelectedIndex=-1;
private $_cachedSelectedValue=null;
+ private $_cachedSelectedIndices=null;
+ private $_cachedSelectedValues=null;
/**
* @return string tag name of the list control
@@ -204,20 +206,34 @@ abstract class TListControl extends TDataBoundControl // so we make them be effective now
if($this->_cachedSelectedValue!==null)
{
- $index=$items->findIndexByValue($this->_cachedSelectedValue);
- if($index===-1 || ($this->_cachedSelectedIndex!==-1 && $this->_cachedSelectedIndex!==$index))
- throw new TInvalidDataValueException('listcontrol_selection_invalid',get_class($this));
- $this->setSelectedIndex($index);
- $this->_cachedSelectedValue=null;
- $this->_cachedSelectedIndex=-1;
+ $this->setSelectedValue($this->_cachedSelectedValue);
+ $this->resetCachedSelections();
}
else if($this->_cachedSelectedIndex!==-1)
{
$this->setSelectedIndex($this->_cachedSelectedIndex);
- $this->_cachedSelectedIndex=-1;
+ $this->resetCachedSelections();
+ }
+ else if($this->_cachedSelectedValues!==null)
+ {
+ $this->setSelectedValues($this->_cachedSelectedValues);
+ $this->resetCachedSelections();
+ }
+ else if($this->_cachedSelectedIndices!==null)
+ {
+ $this->setSelectedIndices($this->_cachedSelectedIndices);
+ $this->resetCachedSelections();
}
}
+ private function resetCachedSelections()
+ {
+ $this->_cachedSelectedValue=null;
+ $this->_cachedSelectedIndex=-1;
+ $this->_cachedSelectedValues=null;
+ $this->_cachedSelectedIndices=null;
+ }
+
/**
* Creates a collection object to hold list items.
* This method may be overriden to create a customized collection.
@@ -446,23 +462,26 @@ abstract class TListControl extends TDataBoundControl }
/**
- * Selects a list of values by their indices.
- * Unlike {@link setSelectedIndex}, this function should only be called
- * after the list items are populated. Otherwise, it would have no effect.
* @param array list of index of items to be selected
*/
public function setSelectedIndices($indices)
{
- if($this->_items)
+ if($this->getIsMultiSelect())
{
- $this->clearSelection();
- $n=$this->_items->getCount();
- foreach($indices as $index)
+ if($this->_items)
{
- if($index>=0 && $index<$n)
- $this->_items->itemAt($index)->setSelected(true);
+ $this->clearSelection();
+ $n=$this->_items->getCount();
+ foreach($indices as $index)
+ {
+ if($index>=0 && $index<$n)
+ $this->_items->itemAt($index)->setSelected(true);
+ }
}
+ $this->_cachedSelectedIndices=$indices;
}
+ else
+ throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
}
/**
@@ -527,27 +546,30 @@ abstract class TListControl extends TDataBoundControl }
/**
- * Selects a list of values.
- * Unlike {@link setSelectedValue}, this function should only be called
- * after the list items are populated. Otherwise, it would have no effect.
* @param array list of the selected item values
*/
public function setSelectedValues($values)
{
- if($this->_items)
+ if($this->getIsMultiSelect())
{
- $this->clearSelection();
- $lookup=array();
- foreach($this->_items as $item)
- $lookup[$item->getValue()]=$item;
- foreach($values as $value)
+ if($this->_items)
{
- if(isset($lookup["$value"]))
- $lookup["$value"]->setSelected(true);
- else
- throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
+ $this->clearSelection();
+ $lookup=array();
+ foreach($this->_items as $item)
+ $lookup[$item->getValue()]=$item;
+ foreach($values as $value)
+ {
+ if(isset($lookup["$value"]))
+ $lookup["$value"]->setSelected(true);
+ else
+ throw new TInvalidDataValueException('listcontrol_selectedvalue_invalid',get_class($this),$value);
+ }
}
+ $this->_cachedSelectedValues=$values;
}
+ else
+ throw new TNotSupportedException('listcontrol_multiselect_unsupported',get_class($this));
}
/**
|