Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TActiveListBox class file.
4
 *
5
 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6
 * @link http://www.pradosoft.com/
7
 * @copyright Copyright &copy; 2005-2008 PradoSoft
8
 * @license http://www.pradosoft.com/license/
9
 * @version $Id: TActiveListBox.php 2600 2009-01-07 12:58:53Z christophe.boulain $
10
 * @package System.Web.UI.ActiveControls
11
 */
12
 
13
/**
14
 * TActiveListBox class.
15
 *
16
 * List items can be added dynamically during a callback request.
17
 *
18
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
19
 * @version $Id: TActiveListBox.php 2600 2009-01-07 12:58:53Z christophe.boulain $
20
 * @package System.Web.UI.ActiveControls
21
 * @since 3.1
22
 */
23
class TActiveListBox extends TListBox implements IActiveControl, ICallbackEventHandler
24
{
25
	/**
26
	 * Creates a new callback control, sets the adapter to
27
	 * TActiveListControlAdapter. If you override this class, be sure to set the
28
	 * adapter appropriately by, for example, by calling this constructor.
29
	 */
30
	public function __construct()
31
	{
32
		parent::__construct();
33
		$this->setAdapter(new TActiveListControlAdapter($this));
34
		$this->setAutoPostBack(true);
35
	}
36
 
37
	/**
38
	 * @return TBaseActiveCallbackControl standard callback control options.
39
	 */
40
	public function getActiveControl()
41
	{
42
		return $this->getAdapter()->getBaseActiveControl();
43
	}
44
 
45
	/**
46
	 * @return TCallbackClientSide client side request options.
47
	 */
48
	public function getClientSide()
49
	{
50
		return $this->getAdapter()->getBaseActiveControl()->getClientSide();
51
	}
52
 
53
	/**
54
	 * Creates a collection object to hold list items. A specialized
55
	 * TActiveListItemCollection is created to allow the drop down list options
56
	 * to be added.
57
	 * This method may be overriden to create a customized collection.
58
	 * @return TActiveListItemCollection the collection object
59
	 */
60
	protected function createListItemCollection()
61
	{
62
		$collection  = new TActiveListItemCollection;
63
		$collection->setControl($this);
64
		return $collection;
65
	}
66
 
67
	/**
68
	 * Javascript client class for this control.
69
	 * This method overrides the parent implementation.
70
	 * @return null no javascript class name.
71
	 */
72
	protected function getClientClassName()
73
	{
74
		return 'Prado.WebUI.TActiveListBox';
75
	}
76
 
77
	/**
78
	 * Sets the selection mode of the list control (Single, Multiple)
79
	 * on the client-side if the  {@link setEnableUpdate EnableUpdate}
80
	 * property is set to true.
81
	 * @param string the selection mode
82
	 */
83
	public function setSelectionMode($value)
84
	{
85
		parent::setSelectionMode($value);
86
		$multiple = $this->getIsMultiSelect();
87
		$id = $this->getUniqueID(); $multi_id = $id.'[]';
88
		if($multiple)
89
			$this->getPage()->registerPostDataLoader($multi_id);
90
		if($this->getActiveControl()->canUpdateClientSide())
91
		{
92
			$client = $this->getPage()->getCallbackClient();
93
			$client->setAttribute($this, 'multiple', $multiple ? 'multiple' : false);
94
			$client->setAttribute($this, 'name', $multiple ? $multi_id : $id);
95
			if($multiple)
96
				$client->addPostDataLoader($multi_id);
97
		}
98
	}
99
 
100
	/**
101
	 * Raises the callback event. This method is required by {@link
102
	 * ICallbackEventHandler} interface.
103
	 * This method is mainly used by framework and control developers.
104
	 * @param TCallbackEventParameter the event parameter
105
	 */
106
 	public function raiseCallbackEvent($param)
107
	{
108
		$this->onCallback($param);
109
	}
110
 
111
	/**
112
	 * This method is invoked when a callback is requested. The method raises
113
	 * 'OnCallback' event to fire up the event handlers. If you override this
114
	 * method, be sure to call the parent implementation so that the event
115
	 * handler can be invoked.
116
	 * @param TCallbackEventParameter event parameter to be passed to the event handlers
117
	 */
118
	public function onCallback($param)
119
	{
120
		$this->raiseEvent('OnCallback', $this, $param);
121
	}
122
 
123
	/**
124
	 * Updates the client-side options if the item list has changed after the OnLoad event.
125
	 */
126
	public function onPreRender($param)
127
	{
128
		parent::onPreRender($param);
129
		$this->getAdapter()->updateListItems();
130
		$multiple = $this->getIsMultiSelect();
131
		$id = $this->getUniqueID(); $multi_id = $id.'[]';
132
		if($multiple)
133
			$this->getPage()->registerPostDataLoader($multi_id);
134
	}
135
 
136
	/**
137
	 * Override parent implementation, no javascript is rendered here instead
138
	 * the javascript required for active control is registered in {@link addAttributesToRender}.
139
	 */
140
	protected function renderClientControlScript($writer)
141
	{
142
	}
143
 
144
	/**
145
	 * Ensure that the ID attribute is rendered and registers the javascript code
146
	 * for initializing the active control.
147
	 */
148
	protected function addAttributesToRender($writer)
149
	{
150
		parent::addAttributesToRender($writer);
151
		$writer->addAttribute('id',$this->getClientID());
152
		if ($this->getAutoPostBack())
153
			$this->getActiveControl()->registerCallbackClientScript(
154
				$this->getClientClassName(), $this->getPostBackOptions());
155
	}
156
}
157
 
158
?>