3 * TDropContainer class file
5 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
6 * @copyright Copyright © 2008, PradoSoft
7 * @license http://www.pradosoft.com/license
8 * @license http://www.pradosoft.com/license
9 * @package System.Web.UI.ActiveControls
13 * Load active control adapter.
15 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
19 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
23 * TDropContainer is a panel where TDraggable controls can be dropped.
24 * When a TDraggable component is dropped into a TDropContainer, the {@link OnDrop OnDrop} event is raised.
25 * The {@link TDropContainerEventParameter} param will contain the dropped control.
29 * <b>{@link setAcceptCssClass AcceptCssClass}</b> : a coma delimited classname of elements that the drop container can accept.
30 * <b>{@link setHoverCssClass HoverCssClass}</b>: CSS classname of the container when a draggable element hovers over the container.
34 * <b>{@link OnDrop OnDrop}</b> : raised when a TDraggable control is dropped. The dropped control id is encapsulated in the event parameter,
35 * as well as mouse coordinates and key modifiers status
38 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
39 * @copyright Copyright © 2008, PradoSoft
40 * @license http://www.pradosoft.com/license
41 * @package System.Web.UI.ActiveControls
43 class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHandler
45 private $_container=null;
48 * Creates a new callback control, sets the adapter to
49 * TActiveControlAdapter. If you override this class, be sure to set the
50 * adapter appropriately by, for example, by calling this constructor.
52 public function __construct()
54 parent::__construct();
55 $this->setAdapter(new TActiveControlAdapter($this));
59 * @return TBaseActiveControl standard active control options.
61 public function getActiveControl()
63 return $this->getAdapter()->getBaseActiveControl();
67 * @return TCallbackClientSide client side request options.
69 public function getClientSide()
71 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
75 * Gets the Css class name that this container can accept.
78 public function getAcceptCssClass()
80 return $this->getViewState('Accepts', '');
84 * Sets the Css class name that this container can accept.
85 * @param string comma delimited css class names.
87 public function setAcceptCssClass($value)
89 $this->setViewState('Accepts', TPropertyValue::ensureArray($value), '');
93 * Sets the Css class name used when a draggble element is hovering
94 * over this container.
95 * @param string css class name during draggable hover.
97 public function setHoverCssClass($value)
99 $this->setViewState('HoverClass', $value, '');
103 * Gets the Css class name used when a draggble element is hovering
104 * over this container.
105 * @return string css class name during draggable hover.
107 public function getHoverCssClass()
109 return $this->getViewState('HoverClass', '');
114 * Raises callback event. This method is required bu {@link ICallbackEventHandler}
116 * It raises the {@link onDrop OnDrop} event, then, the {@link onCallback OnCallback} event
117 * This method is mainly used by framework and control developers.
118 * @param TCallbackEventParameter the parameter associated with the callback event
120 public function raiseCallbackEvent($param)
122 $this->onDrop($param->getCallbackParameter());
123 $this->onCallback($param);
127 * Raises the onDrop event.
128 * The drop parameters are encapsulated into a {@link TDropContainerEventParameter}
130 * @param object $dropControlId
132 public function onDrop ($dropParams)
134 $this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($dropParams));
139 * This method is invoked when a callback is requested. The method raises
140 * 'OnCallback' event to fire up the event handlers. If you override this
141 * method, be sure to call the parent implementation so that the event
142 * handler can be invoked.
143 * @param TCallbackEventParameter event parameter to be passed to the event handlers
145 public function onCallback($param)
147 $this->raiseEvent('OnCallback', $this, $param);
151 * Gets the post back options for this textbox.
154 protected function getPostBackOptions()
156 $options['ID'] = $this->getClientID();
157 $options['EventTarget'] = $this->getUniqueID();
159 $options['accept'] = $this->getAcceptCssClass();
160 $options['hoverclass'] = $this->getHoverCssClass();
165 * Gets the name of the javascript class responsible for performing postback for this control.
166 * This method overrides the parent implementation.
167 * @return string the javascript class name
169 protected function getClientClassName()
171 return 'Prado.WebUI.DropContainer';
175 * Registers clientscripts
177 * This method overrides the parent implementation and is invoked before render.
178 * @param mixed event parameter
180 public function onPreRender($param)
182 parent::onPreRender($param);
186 * Ensure that the ID attribute is rendered and registers the javascript code
187 * for initializing the active control.
189 protected function addAttributesToRender($writer)
191 parent::addAttributesToRender($writer);
192 $writer->addAttribute('id',$this->getClientID());
194 $this->getPage()->getClientScript()->registerPradoScript('dragdrop');
195 $this->getActiveControl()->registerCallbackClientScript(
196 $this->getClientClassName(), $this->getPostBackOptions());
200 * Creates child control
201 * Override parent implementation to create a container which will contain all
202 * child controls. This container will be a TActivePanel, in order to allow user
203 * to update its content on callback.
205 public function createChildControls ()
207 if ($this->_container===null)
209 $this->_container=Prado::CreateComponent('System.Web.UI.ActiveControls.TActivePanel');
210 $this->_container->setId($this->getId(false).'_content');
211 parent::getControls()->add($this->_container);
216 * Override parent implementation to return the container control collection.
218 * @return TControlCollection
220 public function getControls()
222 $this->ensureChildControls();
223 return $this->_container->getControls();
227 * Renders and replaces the panel's content on the client-side.
228 * When render() is called before the OnPreRender event, such as when render()
229 * is called during a callback event handler, the rendering
230 * is defered until OnPreRender event is raised.
231 * @param THtmlWriter html writer
233 public function render ($writer)
235 if($this->getHasPreRendered())
237 parent::render($writer);
238 if($this->getActiveControl()->canUpdateClientSide())
239 $this->getPage()->getCallbackClient()->replaceContent($this->_container,$writer);
243 $this->getPage()->getAdapter()->registerControlToRender($this->_container,$writer);
250 * TDropContainerEventParameter class
252 * TDropContainerEventParameter encapsulate the parameter
253 * data for <b>OnDrop</b> event of TDropContainer components
255 * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr)
256 * @copyright Copyright © 2008, PradoSoft
257 * @license http://www.pradosoft.com/license
258 * @package System.Web.UI.ActiveControls
260 class TDropContainerEventParameter extends TEventParameter
262 private $_dragElementId;
273 public function __construct($dropParams)
275 $this->_dragElementId = $dropParams->DragElementID;
276 $this->_screenX = $dropParams->ScreenX;
277 $this->_screenY = $dropParams->ScreenY;
278 $this->_offsetX = isset($dropParams->OffsetX) ? $dropParams->OffsetX : false;
279 $this->_offsetY = isset($dropParams->OffsetY) ? $dropParams->OffsetY : false;
280 $this->_clientX = $dropParams->ClientX;
281 $this->_clientY = $dropParams->ClientY;
282 $this->_shiftKey = TPropertyValue::ensureBoolean($dropParams->ShiftKey);
283 $this->_ctrlKey = TPropertyValue::ensureBoolean($dropParams->CtrlKey);
284 $this->_altKey = TPropertyValue::ensureBoolean($dropParams->AltKey);
287 public function getDragElementId() { return $this->_dragElementId; }
288 public function getScreenX() { return $this->_screenX; }
289 public function getScreenY() { return $this->_screenY; }
290 public function getOffsetX() { return $this->_offsetX; }
291 public function geOffsetY() { return $this->_offsetY; }
292 public function getClientX() { return $this->_clientX; }
293 public function getClientY() { return $this->_clientY; }
294 public function getShiftKey() { return $this->_shiftKey; }
295 public function getCtrlKey() { return $this->_ctrlKey; }
296 public function getAltKey() { return $this->_altKey; }
301 * Compatibility method to get the dropped control
302 * @return TControl dropped control, or null if not found
304 public function getDroppedControl ()
307 $service=prado::getApplication()->getService();
308 if ($service instanceof TPageService)
311 // Warning, this will not work if you have a '_' in your control Id !
312 $dropControlId=str_replace(TControl::CLIENT_ID_SEPARATOR,TControl::ID_SEPARATOR,$this->_dragElementId);
313 $control=$service->getRequestedPage()->findControl($dropControlId);