]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TDraggable.php
fe2ac4cc6c2a3b37308f876322ee676589feb8e3
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TDraggable.php
1 <?php
2 /**
3  * TDraggable 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  * @package System.Web.UI.ActiveControls
9  */
10
11 /**
12  * TDraggable is a control which can be dragged
13  *
14  * This control will make "draggable" control.
15  * Properties :
16  *
17  * <b>{@link setGhosting Ghosting}</b> : If set to "Ghosting" or "True", the dragged element will be cloned, and the clone will be dragged.
18  * If set to "SuperGhosting", the element will be cloned, and attached to body, so it can be dragged outside of its parent.
19  * If set to "None" of "False" (default), the element itself is dragged
20  * <b>{@link setRevert Revert}</b>: Set to True if you want your dragged element to revert to its initial position if not dropped on a valid area.
21  * <b>{@link setConstraint Constraint}</b>: Set this to Horizontal or Vertical if you want to constraint your move in one direction.
22  * <b>{@link setHandle Handle}</b>:
23  *
24  * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
25  * @copyright Copyright &copy; 2008, PradoSoft
26  * @license http://www.pradosoft.com/license
27  * @package System.Web.UI.ActiveControls
28  */
29 class TDraggable extends TPanel
30 {
31         /**
32          * Set the handle id or css class
33          * @param string
34          */
35         public function setHandle ($value)
36         {
37                 $this->setViewState('DragHandle', TPropertyValue::ensureString($value), null);
38         }
39
40         /**
41          * Get the handle id or css class
42          * @return string
43          */
44         public function getHandle ()
45         {
46                 return $this->getViewState('DragHandle', null);
47         }
48
49         /**
50          * Determine if draggable element should revert to it orginal position
51          * upon release in an non-droppable container.
52          * Since 3.2, Revert property can be set to one of the value of {@link TDraggableRevertOption} enumeration.
53          *   o 'True' or 'Revert' : The draggable will revert to it's original position
54          *   o 'False' or 'None' : The draggable won't revert to it's original position
55          *   o 'Failure' : The draggable will only revert if it's dropped on a non droppable area
56          * @return TDraggableRevertOption true to revert
57          */
58         public function getRevert()
59         {
60                 return $this->getViewState('Revert', TDraggableRevertOptions::Revert);
61         }
62
63         /**
64          * Sets whether the draggable element should revert to it orginal position
65          * upon release in an non-droppable container.
66          * Since 3.2, Revert property can be set to one of the value of {@link TDraggableRevertOption} enumeration.
67          *   o 'True' or 'Revert' : The draggable will revert to it's original position
68          *   o 'False' or 'None' : The draggable won't revert to it's original position
69          *   o 'Failure' : The draggable will only revert if it's dropped on a non droppable area
70          * @param boolean true to revert
71          */
72         public function setRevert($value)
73         {
74                 if (strcasecmp($value,'true')==0 || $value===true)
75                         $value=TDraggableRevertOptions::Revert;
76                 elseif (strcasecmp($value,'false')==0 || $value===false)
77                         $value=TDraggableRevertOptions::None;
78                 $this->setViewState('Revert', TPropertyValue::ensureEnum($value, 'TDraggableRevertOptions'), true);
79         }
80
81         /**
82          * Determine if the element should be cloned when dragged
83          * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped.
84          * Defaults to false
85          *      Since 3.2, Ghosting can be set to one of the value of {@link TDraggableGhostingOptions} enumeration.
86          *  o "True" or "Ghosting" means standard pre-3.2 ghosting mechanism
87          *  o "SuperGhosting" use the Superghosting patch by Christopher Williams, which allow elements to be dragged from an
88          *    scrollable list
89          *  o "False" or "None" means no Ghosting options
90          *
91          * @return TDraggableGhostingOption to clone the element
92          */
93         public function getGhosting ()
94         {
95                 return $this->getViewState('Ghosting', TDraggableGhostingOptions::None);
96         }
97
98         /**
99          * Sets wether the element should be cloned when dragged
100          * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped.
101          * Defaults to false
102          *
103          * Since 3.2, Ghosting can be set to one of the value of {@link TDraggableGhostingOptions} enumeration.
104          *  o "True" or "Ghosting" means standard pre-3.2 ghosting mechanism
105          *  o "SuperGhosting" use the Superghosting patch by Christopher Williams, which allow elements to be dragged from an
106          *    scrollable list
107          *  o "False" or "None" means no Ghosting options
108          *
109          */
110         public function setGhosting ($value)
111         {
112                 if (strcasecmp($value,'true')==0 || $value===true)
113                         $value=TDraggableGhostingOptions::Ghosting;
114                 elseif (strcasecmp($value,'false')==0 || $value===false)
115                         $value=TDraggableGhostingOptions::None;
116                 $this->setViewState('Ghosting', TPropertyValue::ensureEnum($value, 'TDraggableGhostingOptions'), TDraggableGhostingOptions::None);
117         }
118
119         /**
120          * Determine if the element should be constrainted in one direction or not
121          * @return CDraggableConstraint
122          */
123         public function getConstraint()
124         {
125                 return $this->getViewState('Constraint', TDraggableConstraint::None);
126         }
127
128         /**
129          * Set wether the element should be constrainted in one direction
130          * @param CDraggableConstraint
131          */
132         public function setConstraint($value)
133         {
134                 $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None);
135         }
136
137         /**
138          * Registers clientscripts
139          *
140          * This method overrides the parent implementation and is invoked before render.
141          * @param mixed event parameter
142          */
143         public function onPreRender($param)
144         {
145                 parent::onPreRender($param);
146         }
147
148         /**
149          * Ensure that the ID attribute is rendered and registers the javascript code
150          * for initializing the active control.
151          */
152         protected function addAttributesToRender($writer)
153         {
154                 parent::addAttributesToRender($writer);
155
156                 $cs=$this->getPage()->getClientScript();
157                 if ($this->getGhosting()==TDraggableGhostingOptions::SuperGhosting)
158                         $cs->registerPradoScript('dragdropextra');
159                 else
160                         $cs->registerPradoScript('dragdrop');
161                 $writer->addAttribute('id',$this->getClientID());
162                 $options=TJavascript::encode($this->getPostBackOptions());
163                 $class=$this->getClientClassName();
164                 $code="new {$class}('{$this->getClientId()}', {$options}) ";
165                 $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
166         }
167
168         /**
169          * Gets the name of the javascript class responsible for performing postback for this control.
170          * This method overrides the parent implementation.
171          * @return string the javascript class name
172          */
173         protected function getClientClassName ()
174         {
175                 return 'Draggable';
176         }
177
178         /**
179          * Gets the post back options for this textbox.
180          * @return array
181          */
182         protected function getPostBackOptions()
183         {
184                 $options['ID'] = $this->getClientID();
185
186                 if (($handle=$this->getHandle())!== null) $options['handle']=$handle;
187                 if (($revert=$this->getRevert())===TDraggableRevertOptions::None)
188                         $options['revert']=false;
189                 elseif ($revert==TDraggableRevertOptions::Revert)
190                         $options['revert']=true;
191                 else
192                         $options['revert']=strtolower($revert);
193                 if (($constraint=$this->getConstraint())!==TDraggableConstraint::None) $options['constraint']=strtolower($constraint);
194                 switch ($this->getGhosting())
195                 {
196                         case TDraggableGhostingOptions::SuperGhosting:
197                                 $options['superghosting']=true;
198                                 break;
199                         case TDraggableGhostingOptions::Ghosting:
200                                 $options['ghosting']=true;
201                                 break;
202                 }
203
204                 return $options;
205         }
206
207 }
208
209 /**
210  * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
211  * @copyright Copyright &copy; 2008, PradoSoft
212  * @license http://www.pradosoft.com/license
213  * @package System.Web.UI.ActiveControls
214  */
215 class TDraggableConstraint extends TEnumerable
216 {
217         const None='None';
218         const Horizontal='Horizontal';
219         const Vertical='Vertical';
220 }
221
222 /**
223  * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
224  * @copyright Copyright &copy; 2008, PradoSoft
225  * @license http://www.pradosoft.com/license
226  * @package System.Web.UI.ActiveControls
227  */
228 class TDraggableGhostingOptions extends TEnumerable
229 {
230         const None='None';
231         const Ghosting='Ghosting';
232         const SuperGhosting='SuperGhosting';
233 }
234
235 /**
236  * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
237  * @copyright Copyright &copy; 2008, PradoSoft
238  * @license http://www.pradosoft.com/license
239  * @package System.Web.UI.ActiveControls
240  */
241 class TDraggableRevertOptions extends TEnumerable
242 {
243         const None='None';
244         const Revert='Revert';
245         const Failure='Failure';
246 }