diff options
author | Christophe.Boulain <> | 2009-10-02 13:02:23 +0000 |
---|---|---|
committer | Christophe.Boulain <> | 2009-10-02 13:02:23 +0000 |
commit | 4fdf0be9fec3ace5a1789a155d4f7a331bb089ce (patch) | |
tree | 15bcf6693ae53e59cdbe62ed98e522eeaafa58f4 /framework/Web/UI/ActiveControls | |
parent | 8206257a146a93722ef5251e057866c8d4d5505c (diff) |
Enhancement on drag & drop controls.
Diffstat (limited to 'framework/Web/UI/ActiveControls')
-rwxr-xr-x | framework/Web/UI/ActiveControls/TDraggable.php | 56 | ||||
-rwxr-xr-x | framework/Web/UI/ActiveControls/TDropContainer.php | 86 |
2 files changed, 107 insertions, 35 deletions
diff --git a/framework/Web/UI/ActiveControls/TDraggable.php b/framework/Web/UI/ActiveControls/TDraggable.php index e4e4c4c4..4c7803a7 100755 --- a/framework/Web/UI/ActiveControls/TDraggable.php +++ b/framework/Web/UI/ActiveControls/TDraggable.php @@ -11,7 +11,15 @@ /** * TDraggable is a control which can be dragged * - * This control will make "draggable" control. + * This control will make "draggable" control. + * Properties : + * + * <b>{@link setGhosting Ghosting}</b> : If set to "Ghosting" or "True", the dragged element will be cloned, and the clone will be dragged. + * If set to "SuperGhosting", the element will be cloned, and attached to body, so it can be dragged outside of its parent. + * If set to "None" of "False" (default), the element itself is dragged + * <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. + * <b>{@link setConstraint Constraint}</b>: Set this to Horizontal or Vertical if you want to constraint your move in one direction. + * <b>{@link setHandle Handle}</b>: * * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) * @copyright Copyright © 2008, PradoSoft @@ -62,22 +70,38 @@ class TDraggable extends TPanel * Determine if the element should be cloned when dragged * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped. * Defaults to false - * @return boolean true to clone the element + * Since 3.2, Ghosting can be set to one of the value of {@link TDraggableGhostingOptions} enumeration. + * o "True" or "Ghosting" means standard pre-3.2 ghosting mechanism + * o "SuperGhosting" use the Superghosting patch by Christopher Williams, which allow elements to be dragged from an + * scrollable list + * o "False" or "None" means no Ghosting options + * + * @return TDraggableGhostingOption to clone the element */ public function getGhosting () { - return $this->getViewState('Ghosting', false); + return $this->getViewState('Ghosting', TDraggableGhostingOptions::None); } /** * Sets wether the element should be cloned when dragged * If true, Clones the element and drags the clone, leaving the original in place until the clone is dropped. * Defaults to false - * @return boolean true to clone the element + * + * Since 3.2, Ghosting can be set to one of the value of {@link TDraggableGhostingOptions} enumeration. + * o "True" or "Ghosting" means standard pre-3.2 ghosting mechanism + * o "SuperGhosting" use the Superghosting patch by Christopher Williams, which allow elements to be dragged from an + * scrollable list + * o "False" or "None" means no Ghosting options + * */ public function setGhosting ($value) { - $this->setViewState('Ghosting', TPropertyValue::ensureBoolean($value), false); + if (strcasecmp($value,'true')==0 || $value===true) + $value=TDraggableGhostingOptions::Ghosting; + elseif (strcasecmp($value,'false')==0 || $value===false) + $value=TDraggableGhostingOptions::None; + $this->setViewState('Ghosting', TPropertyValue::ensureEnum($value, 'TDraggableGhostingOptions'), TDraggableGhostingOptions::None); } /** @@ -108,7 +132,10 @@ class TDraggable extends TPanel parent::addAttributesToRender($writer); $writer->addAttribute('id',$this->getClientID()); $cs=$this->getPage()->getClientScript(); - $cs->registerPradoScript('dragdrop'); + if ($this->getGhosting()==TDraggableGhostingOptions::SuperGhosting) + $cs->registerPradoScript('dragdropextra'); + else + $cs->registerPradoScript('dragdrop'); $options=TJavascript::encode($this->getPostBackOptions()); $class=$this->getClientClassName(); $code="new {$class}('{$this->getClientId()}', {$options}) "; @@ -136,7 +163,15 @@ class TDraggable extends TPanel if (($handle=$this->getHandle())!== null) $options['handle']=$handle; $options['revert']=$this->getRevert(); if (($constraint=$this->getConstraint())!==TDraggableConstraint::None) $options['constraint']=strtolower($constraint); - $options['ghosting']=$this->getGhosting(); + switch ($this->getGhosting()) + { + case TDraggableGhostingOptions::SuperGhosting: + $options['superghosting']=true; + break; + case TDraggableGhostingOptions::Ghosting: + $options['ghosting']=true; + break; + } return $options; } @@ -149,4 +184,11 @@ class TDraggableConstraint extends TEnumerable const Horizontal='Horizontal'; const Vertical='Vertical'; } + +class TDraggableGhostingOptions extends TEnumerable +{ + const None='None'; + const Ghosting='Ghosting'; + const SuperGhosting='SuperGhosting'; +} ?>
\ No newline at end of file diff --git a/framework/Web/UI/ActiveControls/TDropContainer.php b/framework/Web/UI/ActiveControls/TDropContainer.php index 75a80625..8f7792f3 100755 --- a/framework/Web/UI/ActiveControls/TDropContainer.php +++ b/framework/Web/UI/ActiveControls/TDropContainer.php @@ -30,7 +30,9 @@ Prado::using('System.Web.UI.ActiveControls.TActivePanel'); * * Events: * - * <b>{@link OnDrop OnDrop} : raised when a TDraggable control is dropped. The dropped control is encapsulated in the event parameter + * <b>{@link OnDrop OnDrop} : raised when a TDraggable control is dropped. The dropped control id is encapsulated in the event parameter, + * as well as mouse coordinates and key modifiers status + * * * @author Christophe BOULAIN (Christophe.Boulain@gmail.com) * @copyright Copyright © 2008, PradoSoft @@ -115,17 +117,13 @@ class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHan /** * Raises the onDrop event. - * The dropped control is encapsulated into a {@link TDropContainerEventParameter} + * The dropp parameters are encapsulated into a {@link TDropContainerEventParameter} * - * @param string $dropControlId + * @param object $dropControlId */ - public function onDrop ($dropControlId) + public function onDrop ($dropParams) { - // Find the control - // Warning, this will not work if you have a '_' in your control Id ! - $dropControlId=str_replace(TControl::CLIENT_ID_SEPARATOR,TControl::ID_SEPARATOR,$dropControlId); - $control=$this->getPage()->findControl($dropControlId); - $this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($control)); + $this->raiseEvent('OnDrop', $this, new TDropContainerEventParameter ($dropParams)); } @@ -244,28 +242,60 @@ class TDropContainer extends TPanel implements IActiveControl, ICallbackEventHan */ class TDropContainerEventParameter extends TEventParameter { - /* - * the id of control which has been dropped - * @var string - */ - private $_droppedControl; - - /** - * constructor - * - * @param string the id of control which been dropped - */ - public function __construct ($control) + private $_dragElementId; + private $_screenX; + private $_screenY; + private $_offsetX; + private $_offsetY; + private $_clientX; + private $_clientY; + private $_shiftKey; + private $_ctrlKey; + private $_altKey; + + public function __construct($dropParams) { - $this->_droppedControl=$control; + $this->_dragElementId = $dropParams->DragElementID; + $this->_screenX = $dropParams->ScreenX; + $this->_screenY = $dropParams->ScreenY; + $this->_offsetX = isset($dropParams->OffsetX) ? $dropParams->OffsetX : false; + $this->_offsetY = isset($dropParams->OffsetY) ? $dropParams->OffsetY : false; + $this->_clientX = $dropParams->ClientX; + $this->_clientY = $dropParams->ClientY; + $this->_shiftKey = TPropertyValue::ensureBoolean($dropParams->ShiftKey); + $this->_ctrlKey = TPropertyValue::ensureBoolean($dropParams->CtrlKey); + $this->_altKey = TPropertyValue::ensureBoolean($dropParams->AltKey); } - + + public function getDragElementId() { return $this->_dragElementId; } + public function getScreenX() { return $this->_screenX; } + public function getScreenY() { return $this->_screenY; } + public function getOffsetX() { return $this->_offsetX; } + public function geOffsetY() { return $this->_offsetY; } + public function getClientX() { return $this->_clientX; } + public function getClientY() { return $this->_clientY; } + public function getShiftKey() { return $this->_shiftKey; } + public function getCtrlKey() { return $this->_ctrlKey; } + public function getAltKey() { return $this->_altKey; } + /** - * @return TDraggable + * GetDroppedControl + * + * Compatibility method to get the dropped control + * @return TControl dropped control, or null if not found */ - public function getDroppedControl () - { - return $this->_droppedControl; - } + public function getDroppedControl () + { + $control=null; + $service=prado::getApplication()->getService(); + if ($service instanceof TPageService) + { + // Find the control + // Warning, this will not work if you have a '_' in your control Id ! + $dropControlId=str_replace(TControl::CLIENT_ID_SEPARATOR,TControl::ID_SEPARATOR,$this->_dragElementId); + $control=$service->getRequestedPage()->findControl($dropControlId); + } + return $control; + } } ?>
\ No newline at end of file |