Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * TDropContainer class file
4
 *
5
 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
6
 * @copyright Copyright &copy; 2008, PradoSoft
7
 * @license http://www.pradosoft.com/license
8
 * @version $Id: TDropContainer.php 2517 2008-10-13 13:40:34Z tof $
9
 */
10
 
11
/**
12
 * Load active control adapter.
13
 */
14
Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
15
/**
16
 * Load active panel.
17
 */
18
Prado::using('System.Web.UI.ActiveControls.TActivePanel');
19
 
20
 
21
/**
22
 * TDropContainer is a panel where TDraggable controls can be dropped.
23
 * When a TDraggable component is dropped into a TDropContainer, the {@link OnDrop OnDrop} event is raised.
24
 * The {@link TDropContainerEventParameter} param will contain the dropped control.
25
 *
26
 * Properties :
27
 *
28
 * <b>{@link setAcceptCssClass AcceptCssClass}</b> : a coma delimited classname of elements that the drop container can accept.
29
 * <b>{@link setHoverCssClass HoverCssClass}</b>: CSS classname of the container when a draggable element hovers over the container.
30
 *
31
 * Events:
32
 *
33
 * <b>{@link OnDrop OnDrop} : raised when a TDraggable control is dropped. The dropped control is encapsulated in the event parameter
34
 *
35
 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
36
 * @copyright Copyright &copy; 2008, PradoSoft
37
 * @license http://www.pradosoft.com/license
38
 * @version $Id: TDropContainer.php 2517 2008-10-13 13:40:34Z tof $
39
 */
40
class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHandler
41
{
42
	private $_container=null;
43
 
44
	/**
45
	 * Creates a new callback control, sets the adapter to
46
	 * TActiveControlAdapter. If you override this class, be sure to set the
47
	 * adapter appropriately by, for example, by calling this constructor.
48
	 */
49
	public function __construct()
50
	{
51
		parent::__construct();
52
		$this->setAdapter(new TActiveControlAdapter($this));
53
	}
54
 
55
	/**
56
	 * @return TBaseActiveControl standard active control options.
57
	 */
58
	public function getActiveControl()
59
	{
60
		return $this->getAdapter()->getBaseActiveControl();
61
	}
62
 
63
 
64
	/**
65
	 * Gets the Css class name that this container can accept.
66
	 * @return string
67
	 */
68
	public function getAcceptCssClass()
69
	{
70
		return $this->getViewState('Accepts', '');
71
	}
72
 
73
	/**
74
	 * Sets the Css class name that this container can accept.
75
	 * @param string comma delimited css class names.
76
	 */
77
	public function setAcceptCssClass($value)
78
	{
79
		$this->setViewState('Accepts', TPropertyValue::ensureArray($value), '');
80
	}
81
 
82
	/**
83
	 * Sets the Css class name used when a draggble element is hovering
84
	 * over this container.
85
	 * @param string css class name during draggable hover.
86
	 */
87
	public function setHoverCssClass($value)
88
	{
89
		$this->setViewState('HoverClass', $value, '');
90
	}
91
 
92
	/**
93
	 * Gets the Css class name used when a draggble element is hovering
94
	 * over this container.
95
	 * @return string css class name during draggable hover.
96
	 */
97
	public function getHoverCssClass()
98
	{
99
		return $this->getViewState('HoverClass', '');
100
	}
101
 
102
 
103
	/**
104
	 * Raises callback event. This method is required bu {@link ICallbackEventHandler}
105
	 * interface.
106
	 * It raises the {@link onDrop OnDrop} event, then, the {@link onCallback OnCallback} event
107
	 * This method is mainly used by framework and control developers.
108
	 * @param TCallbackEventParameter the parameter associated with the callback event
109
	 */
110
	public function raiseCallbackEvent($param)
111
	{
112
		$this->onDrop($param->getCallbackParameter());
113
		$this->onCallback($param);
114
	}
115
 
116
	/**
117
	 * Raises the onDrop event.
118
	 * The dropped control is encapsulated into a {@link TDropContainerEventParameter}
119
	 *
120
	 * @param string $dropControlId
121
	 */
122
	public function onDrop ($dropControlId)
123
	{
124
		// Find the control
125
		// Warning, this will not work if you have a '_' in your control Id !
126
		$control=$this->getPage();
127
		$namingContainers=explode(TControl::CLIENT_ID_SEPARATOR, $dropControlId);
128
		foreach ($namingContainers as $nc)
129
		{
130
			$control=$control->findControl($nc);
131
		}
132
		$this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($control));
133
 
134
	}
135
 
136
	/**
137
	 * This method is invoked when a callback is requested. The method raises
138
	 * 'OnCallback' event to fire up the event handlers. If you override this
139
	 * method, be sure to call the parent implementation so that the event
140
	 * handler can be invoked.
141
	 * @param TCallbackEventParameter event parameter to be passed to the event handlers
142
	 */
143
	public function onCallback($param)
144
	{
145
		$this->raiseEvent('OnCallback', $this, $param);
146
	}
147
 
148
	/**
149
	 * Gets the post back options for this textbox.
150
	 * @return array
151
	 */
152
	protected function getPostBackOptions()
153
	{
154
		$options['ID'] = $this->getClientID();
155
		$options['EventTarget'] = $this->getUniqueID();
156
 
157
		$options['accept'] = TJavascript::encode($this->getAcceptCssClass());
158
		$options['hoverclass'] = $this->getHoverCssClass();
159
		return $options;
160
	}
161
 
162
	/**
163
	 * Gets the name of the javascript class responsible for performing postback for this control.
164
	 * This method overrides the parent implementation.
165
	 * @return string the javascript class name
166
	 */
167
	protected function getClientClassName()
168
	{
169
		return 'Prado.WebUI.DropContainer';
170
	}
171
 
172
 
173
	/**
174
	 * Ensure that the ID attribute is rendered and registers the javascript code
175
	 * for initializing the active control.
176
	 */
177
	protected function addAttributesToRender($writer)
178
	{
179
		parent::addAttributesToRender($writer);
180
		$writer->addAttribute('id',$this->getClientID());
181
 
182
		$this->getPage()->getClientScript()->registerPradoScript('dragdrop');
183
 
184
		$this->getActiveControl()->registerCallbackClientScript(
185
			$this->getClientClassName(), $this->getPostBackOptions());
186
	}
187
 
188
	/**
189
	 * Creates child control
190
	 * Override parent implementation to create a container which will contain all
191
	 * child controls. This container will be a TActivePanel, in order to allow user
192
	 * to update its content on callback.
193
	 */
194
	public function createChildControls ()
195
	{
196
		if ($this->_container===null)
197
		{
198
			$this->_container=Prado::CreateComponent('System.Web.UI.ActiveControls.TActivePanel');
199
			$this->_container->setId($this->getId().'_content');
200
			parent::getControls()->add($this->_container);
201
		}
202
	}
203
 
204
	/**
205
	 * Override parent implementation to return the container control collection.
206
	 *
207
	 * @return TControlCollection
208
	 */
209
	public function getControls()
210
	{
211
		$this->ensureChildControls();
212
		return $this->_container->getControls();
213
	}
214
 
215
	/**
216
	 * Renders and replaces the panel's content on the client-side.
217
	 * When render() is called before the OnPreRender event, such as when render()
218
	 * is called during a callback event handler, the rendering
219
	 * is defered until OnPreRender event is raised.
220
	 * @param THtmlWriter html writer
221
	 */
222
	public function render ($writer)
223
	{
224
		if($this->getHasPreRendered())
225
		{
226
			parent::render($writer);
227
			if($this->getActiveControl()->canUpdateClientSide())
228
				$this->getPage()->getCallbackClient()->replaceContent($this->_container,$writer);
229
		}
230
		else
231
		{
232
			$this->getPage()->getAdapter()->registerControlToRender($this->_container,$writer);
233
		}
234
	}
235
 
236
}
237
 
238
/**
239
 * TDropContainerEventParameter class
240
 *
241
 * TDropContainerEventParameter encapsulate the parameter
242
 * data for <b>OnDrop</b> event of TDropContainer components
243
 *
244
 * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr)
245
 * @copyright Copyright &copy; 2008, PradoSoft
246
 * @license http://www.pradosoft.com/license
247
 * @version $Id: TDropContainer.php 2517 2008-10-13 13:40:34Z tof $
248
 */
249
class TDropContainerEventParameter extends TEventParameter
250
{
251
	/*
252
	 * the id of control which has been dropped
253
	 * @var string
254
	 */
255
	private $_droppedControl;
256
 
257
	/**
258
	 * constructor
259
	 *
260
	 * @param string the id of control which been dropped
261
	 */
262
	public function __construct ($control)
263
	{
264
		$this->_droppedControl=$control;
265
	}
266
 
267
	/**
268
	 * @return TDraggable
269
	 */
270
	public function getDroppedControl ()
271
	{
272
		return $this->_droppedControl;
273
	}
274
}
275
?>