3 * TDraggable class file
5 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
6 * @copyright Copyright © 2008, PradoSoft
7 * @license http://www.pradosoft.com/license
8 * @package System.Web.UI.ActiveControls
12 * TDraggable is a control which can be dragged
14 * This control will make "draggable" control.
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>:
24 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
25 * @copyright Copyright © 2008, PradoSoft
26 * @license http://www.pradosoft.com/license
27 * @package System.Web.UI.ActiveControls
29 class TDraggable extends TPanel
32 * Set the handle id or css class
35 public function setHandle ($value)
37 $this->setViewState('DragHandle', TPropertyValue::ensureString($value), null);
41 * Get the handle id or css class
44 public function getHandle ()
46 return $this->getViewState('DragHandle', null);
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
58 public function getRevert()
60 return $this->getViewState('Revert', TDraggableRevertOptions::Revert);
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
72 public function setRevert($value)
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);
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.
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
89 * o "False" or "None" means no Ghosting options
91 * @return TDraggableGhostingOption to clone the element
93 public function getGhosting ()
95 return $this->getViewState('Ghosting', TDraggableGhostingOptions::None);
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.
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
107 * o "False" or "None" means no Ghosting options
110 public function setGhosting ($value)
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);
120 * Determine if the element should be constrainted in one direction or not
121 * @return CDraggableConstraint
123 public function getConstraint()
125 return $this->getViewState('Constraint', TDraggableConstraint::None);
129 * Set wether the element should be constrainted in one direction
130 * @param CDraggableConstraint
132 public function setConstraint($value)
134 $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None);
138 * Registers clientscripts
140 * This method overrides the parent implementation and is invoked before render.
141 * @param mixed event parameter
143 public function onPreRender($param)
145 parent::onPreRender($param);
149 * Ensure that the ID attribute is rendered and registers the javascript code
150 * for initializing the active control.
152 protected function addAttributesToRender($writer)
154 parent::addAttributesToRender($writer);
156 $cs=$this->getPage()->getClientScript();
157 if ($this->getGhosting()==TDraggableGhostingOptions::SuperGhosting)
158 $cs->registerPradoScript('dragdropextra');
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);
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
173 protected function getClientClassName ()
179 * Gets the post back options for this textbox.
182 protected function getPostBackOptions()
184 $options['ID'] = $this->getClientID();
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;
192 $options['revert']=strtolower($revert);
193 if (($constraint=$this->getConstraint())!==TDraggableConstraint::None) $options['constraint']=strtolower($constraint);
194 switch ($this->getGhosting())
196 case TDraggableGhostingOptions::SuperGhosting:
197 $options['superghosting']=true;
199 case TDraggableGhostingOptions::Ghosting:
200 $options['ghosting']=true;
210 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
211 * @copyright Copyright © 2008, PradoSoft
212 * @license http://www.pradosoft.com/license
213 * @package System.Web.UI.ActiveControls
215 class TDraggableConstraint extends TEnumerable
218 const Horizontal='Horizontal';
219 const Vertical='Vertical';
223 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
224 * @copyright Copyright © 2008, PradoSoft
225 * @license http://www.pradosoft.com/license
226 * @package System.Web.UI.ActiveControls
228 class TDraggableGhostingOptions extends TEnumerable
231 const Ghosting='Ghosting';
232 const SuperGhosting='SuperGhosting';
236 * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
237 * @copyright Copyright © 2008, PradoSoft
238 * @license http://www.pradosoft.com/license
239 * @package System.Web.UI.ActiveControls
241 class TDraggableRevertOptions extends TEnumerable
244 const Revert='Revert';
245 const Failure='Failure';