summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TDraggable.php
diff options
context:
space:
mode:
authortof <>2008-10-13 13:40:34 +0000
committertof <>2008-10-13 13:40:34 +0000
commit303edb1dd308d3812102fbe25438e56413cd79a3 (patch)
tree8c64c73f98b4bb76ecf23df0f952d195b4924026 /framework/Web/UI/ActiveControls/TDraggable.php
parent886386efc0ca4b72d1567946061c0eff7cbe45c6 (diff)
Added drag and drop components
Diffstat (limited to 'framework/Web/UI/ActiveControls/TDraggable.php')
-rwxr-xr-xframework/Web/UI/ActiveControls/TDraggable.php152
1 files changed, 152 insertions, 0 deletions
diff --git a/framework/Web/UI/ActiveControls/TDraggable.php b/framework/Web/UI/ActiveControls/TDraggable.php
new file mode 100755
index 00000000..e4e4c4c4
--- /dev/null
+++ b/framework/Web/UI/ActiveControls/TDraggable.php
@@ -0,0 +1,152 @@
+<?php
+/**
+ * TDraggable class file
+ *
+ * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
+ * @copyright Copyright &copy; 2008, PradoSoft
+ * @license http://www.pradosoft.com/license
+ * @version $Id$
+ */
+
+/**
+ * TDraggable is a control which can be dragged
+ *
+ * This control will make "draggable" control.
+ *
+ * @author Christophe BOULAIN (Christophe.Boulain@gmail.com)
+ * @copyright Copyright &copy; 2008, PradoSoft
+ * @license http://www.pradosoft.com/license
+ * @version $Id$
+ */
+class TDraggable extends TPanel
+{
+ /**
+ * Set the handle id or css class
+ * @param string
+ */
+ public function setHandle ($value)
+ {
+ $this->setViewState('DragHandle', TPropertyValue::ensureString($value), null);
+ }
+
+ /**
+ * Get the handle id or css class
+ * @return string
+ */
+ public function getHandle ()
+ {
+ return $this->getViewState('DragHandle', null);
+ }
+
+ /**
+ * Determine if draggable element should revert to it orginal position
+ * upon release in an non-droppable container.
+ * @return boolean true to revert
+ */
+ public function getRevert()
+ {
+ return $this->getViewState('Revert', true);
+ }
+
+ /**
+ * Sets whether the draggable element should revert to it orginal position
+ * upon release in an non-droppable container.
+ * @param boolean true to revert
+ */
+ public function setRevert($value)
+ {
+ $this->setViewState('Revert', TPropertyValue::ensureBoolean($value), true);
+ }
+
+ /**
+ * 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
+ */
+ public function getGhosting ()
+ {
+ return $this->getViewState('Ghosting', false);
+ }
+
+ /**
+ * 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
+ */
+ public function setGhosting ($value)
+ {
+ $this->setViewState('Ghosting', TPropertyValue::ensureBoolean($value), false);
+ }
+
+ /**
+ * Determine if the element should be constrainted in one direction or not
+ * @return CDraggableConstraint
+ */
+ public function getConstraint()
+ {
+ return $this->getViewState('Constraint', TDraggableConstraint::None);
+ }
+
+ /**
+ * Set wether the element should be constrainted in one direction
+ * @param CDraggableConstraint
+ */
+ public function setConstraint($value)
+ {
+ $this->setViewState('Constraint', TPropertyValue::ensureEnum($value, 'TDraggableConstraint'), TDraggableConstraint::None);
+ }
+
+
+ /**
+ * Ensure that the ID attribute is rendered and registers the javascript code
+ * for initializing the active control.
+ */
+ protected function addAttributesToRender($writer)
+ {
+ parent::addAttributesToRender($writer);
+ $writer->addAttribute('id',$this->getClientID());
+ $cs=$this->getPage()->getClientScript();
+ $cs->registerPradoScript('dragdrop');
+ $options=TJavascript::encode($this->getPostBackOptions());
+ $class=$this->getClientClassName();
+ $code="new {$class}('{$this->getClientId()}', {$options}) ";
+ $cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
+ }
+
+ /**
+ * Gets the name of the javascript class responsible for performing postback for this control.
+ * This method overrides the parent implementation.
+ * @return string the javascript class name
+ */
+ protected function getClientClassName ()
+ {
+ return 'Draggable';
+ }
+
+ /**
+ * Gets the post back options for this textbox.
+ * @return array
+ */
+ protected function getPostBackOptions()
+ {
+ $options['ID'] = $this->getClientID();
+
+ 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();
+
+ return $options;
+ }
+
+}
+
+class TDraggableConstraint extends TEnumerable
+{
+ const None='None';
+ const Horizontal='Horizontal';
+ const Vertical='Vertical';
+}
+?> \ No newline at end of file