]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TDropContainer.php
baculum: Unset execute permission from framework files
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TDropContainer.php
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  * @license http://www.pradosoft.com/license
9  * @package System.Web.UI.ActiveControls
10  */
11
12 /**
13  * Load active control adapter.
14  */
15 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
16 /**
17  * Load active panel.
18  */
19 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
20
21
22 /**
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. 
26  * 
27  * Properties :
28  * 
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.
31  * 
32  * Events:
33  * 
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
36  *
37  * 
38  * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
39  * @copyright Copyright &copy; 2008, PradoSoft
40  * @license http://www.pradosoft.com/license
41  * @package System.Web.UI.ActiveControls
42  */
43 class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHandler 
44 {       
45         private $_container=null;
46         
47         /**
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.
51          */
52         public function __construct()
53         {
54                 parent::__construct();
55                 $this->setAdapter(new TActiveControlAdapter($this));
56         }
57
58         /**
59          * @return TBaseActiveControl standard active control options.
60          */
61         public function getActiveControl()
62         {
63                 return $this->getAdapter()->getBaseActiveControl();
64         }
65
66         /**
67          * @return TCallbackClientSide client side request options.
68          */
69         public function getClientSide()
70         {
71                 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
72         }
73
74         /**
75          * Gets the Css class name that this container can accept.
76          * @return string
77          */
78         public function getAcceptCssClass()
79         {
80                 return $this->getViewState('Accepts', '');
81         }
82
83         /**
84          * Sets the Css class name that this container can accept.
85          * @param string comma delimited css class names.
86          */
87         public function setAcceptCssClass($value)
88         {
89                 $this->setViewState('Accepts', TPropertyValue::ensureArray($value), '');
90         }
91         
92         /**
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.
96          */
97         public function setHoverCssClass($value)
98         {
99                 $this->setViewState('HoverClass', $value, '');
100         }
101
102         /**
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.
106          */
107         public function getHoverCssClass()
108         {
109                 return $this->getViewState('HoverClass', '');
110         }
111         
112         
113         /**
114          * Raises callback event. This method is required bu {@link ICallbackEventHandler}
115          * interface.
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
119          */
120         public function raiseCallbackEvent($param)
121         {
122                 $this->onDrop($param->getCallbackParameter());
123                 $this->onCallback($param);
124         }
125         
126         /**
127          * Raises the onDrop event. 
128          * The drop parameters are encapsulated into a {@link TDropContainerEventParameter}
129          * 
130          * @param object $dropControlId
131          */
132         public function onDrop ($dropParams)
133         {
134                 $this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($dropParams));
135                 
136         }
137         
138         /**
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
144          */
145         public function onCallback($param)
146         {
147                 $this->raiseEvent('OnCallback', $this, $param);
148         }
149         
150         /**
151          * Gets the post back options for this textbox.
152          * @return array
153          */
154         protected function getPostBackOptions()
155         {
156                 $options['ID'] = $this->getClientID();
157                 $options['EventTarget'] = $this->getUniqueID();
158
159                 $options['accept'] = $this->getAcceptCssClass();
160                 $options['hoverclass'] = $this->getHoverCssClass();
161                 return $options;
162         }
163         
164         /**
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
168          */
169         protected function getClientClassName()
170         {
171                 return 'Prado.WebUI.DropContainer';
172         }       
173
174         /**
175          * Registers clientscripts
176          *
177          * This method overrides the parent implementation and is invoked before render.
178          * @param mixed event parameter
179          */
180         public function onPreRender($param)
181         {
182                 parent::onPreRender($param);
183         }
184
185         /**
186          * Ensure that the ID attribute is rendered and registers the javascript code
187          * for initializing the active control.
188          */
189         protected function addAttributesToRender($writer)
190         {
191                 parent::addAttributesToRender($writer);
192                 $writer->addAttribute('id',$this->getClientID());
193
194                 $this->getPage()->getClientScript()->registerPradoScript('dragdrop');
195                 $this->getActiveControl()->registerCallbackClientScript(
196                         $this->getClientClassName(), $this->getPostBackOptions());
197         }
198         
199         /**
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.
204          */
205         public function createChildControls ()
206         {
207                 if ($this->_container===null)
208                 {
209                         $this->_container=Prado::CreateComponent('System.Web.UI.ActiveControls.TActivePanel');
210                         $this->_container->setId($this->getId(false).'_content');
211                         parent::getControls()->add($this->_container);
212                 }
213         }
214         
215         /**
216          * Override parent implementation to return the container control collection.
217          *
218          * @return TControlCollection
219          */
220         public function getControls()
221         {
222                 $this->ensureChildControls();
223                 return $this->_container->getControls();
224         }
225         
226         /**
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
232          */
233         public function render ($writer)
234         {
235                 if($this->getHasPreRendered())
236                 {
237                         parent::render($writer);
238                         if($this->getActiveControl()->canUpdateClientSide())
239                                 $this->getPage()->getCallbackClient()->replaceContent($this->_container,$writer);
240                 }
241                 else
242                 {
243                         $this->getPage()->getAdapter()->registerControlToRender($this->_container,$writer);
244                 }
245         }
246                         
247 }
248
249 /**
250  * TDropContainerEventParameter class
251  * 
252  * TDropContainerEventParameter encapsulate the parameter
253  * data for <b>OnDrop</b> event of TDropContainer components
254  * 
255  * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr)
256  * @copyright Copyright &copy; 2008, PradoSoft
257  * @license http://www.pradosoft.com/license
258  * @package System.Web.UI.ActiveControls
259  */
260 class TDropContainerEventParameter extends TEventParameter
261 {
262         private $_dragElementId;
263         private $_screenX;
264         private $_screenY;
265         private $_offsetX;
266         private $_offsetY;
267         private $_clientX;
268         private $_clientY;
269         private $_shiftKey;
270         private $_ctrlKey;
271         private $_altKey;
272
273         public function __construct($dropParams)
274         {
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);
285         }
286
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; }
297
298         /**
299          * GetDroppedControl
300          *
301          * Compatibility method to get the dropped control
302          * @return TControl dropped control, or null if not found
303          */
304          public function getDroppedControl ()
305          {
306                  $control=null;
307                  $service=prado::getApplication()->getService();
308                  if ($service instanceof TPageService)
309                  {
310                         // Find the control
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);
314                  }
315                  return $control;
316          }
317 }