1: <?php
2: /**
3: * QDraggable Base File
4: *
5: * The QDraggableBase class defined here provides an interface between the generated
6: * QDraggableGen class, and QCubed. This file is part of the core and will be overwritten
7: * when you update QCubed. To override, make your changes to the QDraggable.class.php file instead.
8: */
9:
10: /**
11: * Implements the jQuery UI Draggable capabilities on to a control.
12: *
13: * This class is designed to work as a kind of add-on class to a QControl, giving its capabilities
14: * to the control. To make a QControl draggable, simply set $ctl->Dragable = true. You can then
15: * get to this class to further manipulate the aspects of the draggable through $ctl->DragObj.
16: *
17: * @property-read Integer $DeltaX Amount of change in left that happened on the last drag
18: * @property-read Integer $DeltaY Amount of change in top that happened on the last drag
19: * @property mixed $Handle A drag handle. Can be a control, a selector or array of controls or jQuery selectors.
20: *
21: * @link http://jqueryui.com/draggable/
22: * @package Controls\Base
23: */
24: class QDraggableBase extends QDraggableGen
25: {
26: /** Revert Modes */
27: const RevertOn = true; // always revert
28: const RevertOff = false; // never revert
29: const RevertValid = 'valid'; // revert if dropped successfully
30: const RevertInvalid = 'invalid'; // revert if not dropped successfully
31:
32: /** @var array */
33: protected $aryOriginalPosition = null;
34: /** @var array */
35: protected $aryNewPosition = null;
36:
37: // redirect all js requests to the parent control
38: public function getJqControlId() {
39: return $this->objParentControl->ControlId;
40: }
41:
42: public function Render($blnDisplayOutput = true) {}
43: protected function GetControlHtml() {}
44: public function Validate() {return true;}
45: public function ParsePostData() {}
46:
47:
48: public function GetEndScript() {
49: $strJS = parent::GetEndScript();
50: QApplication::ExecuteJsFunction('qcubed.draggable', $this->getJqControlId(), $this->ControlId, QJsPriority::High);
51: return $strJS;
52: }
53:
54:
55: public function __set($strName, $mixValue) {
56: switch ($strName) {
57: case '_DragData': // Internal only. Do not use. Used by JS above to keep track of user selection.
58: try {
59: $data = QType::Cast($mixValue, QType::ArrayType);
60: $this->aryOriginalPosition = $data['originalPosition'];
61: $this->aryNewPosition = $data['position'];
62:
63: // update parent's coordinates
64: $this->objParentControl->getWrapperStyler()->Top = $this->aryNewPosition['top'];
65: $this->objParentControl->getWrapperStyler()->Left = $this->aryNewPosition['left'];
66: break;
67:
68: } catch (QInvalidCastException $objExc) {
69: $objExc->IncrementOffset();
70: throw $objExc;
71: }
72:
73: case 'Handle':
74: // Override to let you set the handle to:
75: // a QControl, or selector, or array of QControls or selectors
76: if ($mixValue instanceof QControl) {
77: parent::__set($strName, '#' . $mixValue->ControlId);
78: } elseif (is_array($mixValue)) {
79: $aHandles = array();
80: foreach ($mixValue as $mixItem) {
81: if ($mixItem instanceof QControl) {
82: $aHandles[] = '#' . $mixItem->ControlId;
83: } elseif (is_string($mixItem)) {
84: $aHandles[] = $mixItem;
85: }
86: }
87: parent::__set($strName, join(',', $aHandles));
88: } else {
89: parent::__set($strName, $mixValue);
90: }
91: break;
92:
93: default:
94: try {
95: parent::__set($strName, $mixValue);
96: break;
97: } catch (QCallerException $objExc) {
98: $objExc->IncrementOffset();
99: throw $objExc;
100: }
101: }
102:
103: }
104:
105: public function __get($strName) {
106: switch ($strName) {
107: case 'DeltaX':
108: if ($this->aryOriginalPosition) {
109: return $this->aryNewPosition['left'] - $this->aryOriginalPosition['left'];
110: } else {
111: return 0;
112: }
113:
114: case 'DeltaY':
115: if ($this->aryOriginalPosition) {
116: return $this->aryNewPosition['top'] - $this->aryOriginalPosition['top'];
117: } else {
118: return 0;
119: }
120:
121: default:
122: try {
123: return parent::__get($strName);
124: } catch (QCallerException $objExc) {
125: $objExc->IncrementOffset();
126: throw $objExc;
127: }
128: }
129: }
130: }