Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TDropDownList class file
4
 *
5
 * @author Qiang Xue <qiang.xue@gmail.com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TDropDownList.php 2541 2008-10-21 15:05:13Z qiang.xue $
10
 * @package System.Web.UI.WebControls
11
 */
12
 
13
/**
14
 * Includes TListControl class
15
 */
16
Prado::using('System.Web.UI.WebControls.TListControl');
17
 
18
/**
19
 * TDropDownList class
20
 *
21
 * TDropDownList displays a dropdown list on a Web page.
22
 * It inherits all properties and events from {@link TListControl}.
23
 *
24
 * Since v3.0.3, TDropDownList starts to support optgroup. To specify an option group for
25
 * a list item, set a Group attribute with it,
26
 * <code>
27
 *  $listitem->Attributes->Group="Group Name";
28
 *  // or <com:TListItem Attributes.Group="Group Name" .../> in template
29
 * </code>
30
 *
31
 * Since v3.1.1, TDropDownList starts to support prompt text. That is, a prompt item can be
32
 * displayed as the first list item by specifying either {@link setPromptText PromptText} or
33
 * {@link setPromptValue PromptValue}, or both. Choosing the prompt item will unselect the TDropDownList.
34
 *
35
 * @author Qiang Xue <qiang.xue@gmail.com>
36
 * @version $Id: TDropDownList.php 2541 2008-10-21 15:05:13Z qiang.xue $
37
 * @package System.Web.UI.WebControls
38
 * @since 3.0
39
 */
40
class TDropDownList extends TListControl implements IPostBackDataHandler, IValidatable
41
{
42
	private $_dataChanged=false;
43
	private $_isValid=true;
44
 
45
	/**
46
	 * Adds attributes to renderer.
47
	 * @param THtmlWriter the renderer
48
	 */
49
	protected function addAttributesToRender($writer)
50
	{
51
		$writer->addAttribute('name',$this->getUniqueID());
52
		parent::addAttributesToRender($writer);
53
	}
54
 
55
	/**
56
	 * Gets the name of the javascript class responsible for performing postback for this control.
57
	 * This method overrides the parent implementation.
58
	 * @return string the javascript class name
59
	 */
60
	protected function getClientClassName()
61
	{
62
		return 'Prado.WebUI.TDropDownList';
63
	}
64
 
65
	/**
66
	 * Loads user input data.
67
	 * This method is primarly used by framework developers.
68
	 * @param string the key that can be used to retrieve data from the input data collection
69
	 * @param array the input data collection
70
	 * @return boolean whether the data of the component has been changed
71
	 */
72
	public function loadPostData($key,$values)
73
	{
74
		if(!$this->getEnabled(true))
75
			return false;
76
		$this->ensureDataBound();
77
		$selection=isset($values[$key])?$values[$key]:null;
78
		if($selection!==null)
79
		{
80
			$index=$this->getItems()->findIndexByValue($selection,false);
81
			if($this->getSelectedIndex()!==$index)
82
			{
83
				$this->setSelectedIndex($index);
84
				return $this->_dataChanged=true;
85
			}
86
		}
87
		return false;
88
	}
89
 
90
	/**
91
	 * Raises postdata changed event.
92
	 * This method is required by {@link IPostBackDataHandler} interface.
93
	 * It is invoked by the framework when {@link getSelectedIndex SelectedIndex} property
94
	 * is changed on postback.
95
	 * This method is primarly used by framework developers.
96
	 */
97
	public function raisePostDataChangedEvent()
98
	{
99
		if($this->getAutoPostBack() && $this->getCausesValidation())
100
			$this->getPage()->validate($this->getValidationGroup());
101
		$this->onSelectedIndexChanged(null);
102
	}
103
 
104
	/**
105
	 * Returns a value indicating whether postback has caused the control data change.
106
	 * This method is required by the IPostBackDataHandler interface.
107
	 * @return boolean whether postback has caused the control data change. False if the page is not in postback mode.
108
	 */
109
	public function getDataChanged()
110
	{
111
		return $this->_dataChanged;
112
	}
113
 
114
	/**
115
	 * @throws TNotSupportedException if this method is invoked
116
	 */
117
	public function setSelectedIndices($indices)
118
	{
119
		throw new TNotSupportedException('dropdownlist_selectedindices_unsupported');
120
	}
121
 
122
	/**
123
	 * Returns the value to be validated.
124
	 * This methid is required by IValidatable interface.
125
	 * @return mixed the value of the property to be validated.
126
	 */
127
	public function getValidationPropertyValue()
128
	{
129
		return $this->getSelectedValue();
130
	}
131
 
132
	/**
133
	 * Returns true if this control validated successfully.
134
	 * Defaults to true.
135
	 * @return bool wether this control validated successfully.
136
	 */
137
	public function getIsValid()
138
	{
139
	    return $this->_isValid;
140
	}
141
	/**
142
	 * @param bool wether this control is valid.
143
	 */
144
	public function setIsValid($value)
145
	{
146
	    $this->_isValid=TPropertyValue::ensureBoolean($value);
147
	}
148
}