1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
27: abstract class QBlockControl extends QControl {
28:
29:
30:
31:
32:
33:
34: protected $strText = null;
35:
36: protected $strFormat = null;
37:
38: protected $strTemplate = null;
39:
40: protected $blnAutoRenderChildren = false;
41:
42: protected $strTagName = null;
43:
44: protected $blnHtmlEntities = true;
45:
46:
47:
48: protected $blnDropTarget = false;
49:
50:
51: protected $objMovesControlsArray = array();
52: protected $objDropsControlsArray = array();
53: protected $objDropsGroupingsArray = array();
54: protected $objIsDropZoneFor = array();
55:
56: public function AddControlToMove($objTargetControl = null) {
57: $this->strJavaScripts = __JQUERY_EFFECTS__;
58: if($objTargetControl && $objTargetControl->ControlId != $this->ControlId) {
59: QApplication::ExecuteJavascript(sprintf('var pos_%s = $j("#%s").offset()', $objTargetControl->ControlId, $objTargetControl->ControlId));
60: QApplication::ExecuteJavascript(sprintf('$j("#%s").on("drag", function (ev, ui) { p = $j("#%s").offset(); p.left = pos_%s.left + ui.position.left; p.top = pos_%s.top + ui.position.top; $j("#%s").offset(p); } );', $this->strControlId, $objTargetControl->ControlId, $objTargetControl->ControlId, $objTargetControl->ControlId, $objTargetControl->ControlId ));
61: $this->objMovesControlsArray[$objTargetControl->ControlId] = true;
62:
63:
64:
65:
66: }
67: return;
68: }
69:
70: public function RemoveControlToMove(QControl $objTargetControl) {
71: unset($this->objMovesControlsArray[$objTargetControl->ControlId]);
72: }
73:
74: public function RemoveAllControlsToMove() {
75: $this->objMovesControlsArray = array();
76: $this->RemoveAllDropZones();
77: }
78:
79: public function AddDropZone($objParentObject) {
80: $this->strJavaScripts = __JQUERY_EFFECTS__;
81: $this->objDropsControlsArray[$objParentObject->ControlId] = true;
82: $objParentObject->DropTarget = true;
83: $objParentObject->objIsDropZoneFor[$this->ControlId] = true;
84: }
85:
86: public function RemoveDropZone($objParentObject) {
87: if ($objParentObject instanceof QForm) {
88: $this->objDropsControlsArray[$objParentObject->FormId] = false;
89: } else if ($objParentObject instanceof QBlockControl) {
90: $this->objDropsControlsArray[$objParentObject->ControlId] = false;
91: $objParentObject->objIsDropZoneFor[$this->ControlId] = false;
92: } else
93: throw new QCallerException('ParentObject must be either a QForm or QBlockControl object');
94: }
95:
96: public function RemoveAllDropZones() {
97: QApplication::ExecuteControlCommand($this->strControlId, 'draggable', "option", "revert", "invalid");
98:
99: foreach ($this->objDropsControlsArray as $strControlId => $blnValue) {
100: if ($blnValue) {
101: $objControl = $this->objForm->GetControl($strControlId);
102: if ($objControl)
103: $objControl->objIsDropZoneFor[$this->ControlId] = false;
104: }
105: }
106: $this->objDropsControlsArray = array();
107: }
108:
109: 110: 111: 112:
113: public function GetEndScript() {
114: $strToReturn = parent::GetEndScript();
115:
116:
117: foreach ($this->objDropsControlsArray as $strKey => $blnIsDropZone) {
118: if ($blnIsDropZone) {
119: QApplication::ExecuteControlCommand($strKey, 'droppable');
120: }
121: }
122:
123: foreach ($this->objIsDropZoneFor as $strKey => $blnIsDropZone) {
124: if ($blnIsDropZone) {
125: $objControl = $this->objForm->GetControl($strKey);
126: if ($objControl && ($objControl->strRenderMethod)) {
127: QApplication::ExecuteControlCommand($this->strControlId, 'droppable', 'option', 'accept', '#' . $strKey);
128: }
129: }
130: }
131:
132: return $strToReturn;
133: }
134:
135:
136:
137:
138: 139: 140:
141: public function ParsePostData() {}
142:
143:
144: 145: 146: 147:
148: protected function GetControlHtml() {
149:
150: $strToReturn = $this->RenderTag($this->strTagName,
151: null,
152: null,
153: $this->GetInnerHtml());
154:
155:
156:
157:
158: return $strToReturn;
159: }
160:
161: 162: 163: 164: 165:
166: protected function GetInnerHtml() {
167: if ($this->strFormat) {
168: $strText = sprintf($this->strFormat, $this->strText);
169: }
170: else {
171: $strText = $this->strText;
172: }
173:
174: if ($this->blnHtmlEntities) {
175: $strText = QApplication::HtmlEntities($strText);
176: }
177:
178: $strTemplateEvaluated = '';
179: if ($this->strTemplate) {
180: global $_CONTROL;
181: $objCurrentControl = $_CONTROL;
182: $_CONTROL = $this;
183: $strTemplateEvaluated = $this->EvaluateTemplate($this->strTemplate);
184: $_CONTROL = $objCurrentControl;
185: }
186:
187: $strText .= $strTemplateEvaluated;
188:
189: if ($this->blnAutoRenderChildren) {
190: $strText .= $this->RenderChildren(false);
191: }
192: return $strText;
193: }
194:
195: 196: 197: 198: 199: 200: 201: 202:
203: public function Validate() {return true;}
204:
205:
206:
207:
208: 209: 210: 211: 212: 213: 214:
215: public function __get($strName) {
216: switch ($strName) {
217:
218: case "Text": return $this->strText;
219: case "Format": return $this->strFormat;
220: case "Template": return $this->strTemplate;
221: case "AutoRenderChildren": return $this->blnAutoRenderChildren;
222: case "TagName": return $this->strTagName;
223: case "HtmlEntities": return $this->blnHtmlEntities;
224:
225:
226: case "DropTarget": return $this->blnDropTarget;
227:
228: default:
229: try {
230: return parent::__get($strName);
231: } catch (QCallerException $objExc) {
232: $objExc->IncrementOffset();
233: throw $objExc;
234: }
235: }
236: }
237:
238:
239:
240:
241: 242: 243: 244: 245: 246: 247: 248:
249: public function __set($strName, $mixValue) {
250: switch ($strName) {
251:
252: case "Text":
253: try {
254: if ($this->strText !== ($mixValue = QType::Cast($mixValue, QType::String))) {
255: $this->blnModified = true;
256: $this->strText = $mixValue;
257: }
258: break;
259: } catch (QInvalidCastException $objExc) {
260: $objExc->IncrementOffset();
261: throw $objExc;
262: }
263:
264: case "Format":
265: try {
266: if ($this->strFormat !== ($mixValue = QType::Cast($mixValue, QType::String))) {
267: $this->blnModified = true;
268: $this->strFormat = $mixValue;
269: }
270: break;
271: } catch (QInvalidCastException $objExc) {
272: $objExc->IncrementOffset();
273: throw $objExc;
274: }
275:
276: case "Template":
277: try {
278: $this->blnModified = true;
279: if ($mixValue) {
280: if (file_exists($strPath = $this->GetTemplatePath($mixValue))) {
281: $this->strTemplate = QType::Cast($strPath, QType::String);
282: } else {
283: throw new QCallerException('Could not find template file: ' . $mixValue);
284: }
285: } else {
286: $this->strTemplate = null;
287: }
288: break;
289: } catch (QInvalidCastException $objExc) {
290: $objExc->IncrementOffset();
291: throw $objExc;
292: }
293:
294: case "AutoRenderChildren":
295: try {
296: if ($this->blnAutoRenderChildren !== ($mixValue = QType::Cast($mixValue, QType::Boolean))) {
297: $this->blnModified = true;
298: $this->blnAutoRenderChildren = $mixValue;
299: }
300: break;
301: } catch (QInvalidCastException $objExc) {
302: $objExc->IncrementOffset();
303: throw $objExc;
304: }
305:
306: case "TagName":
307: try {
308: if ($this->strTagName !== ($mixValue = QType::Cast($mixValue, QType::String))) {
309: $this->blnModified = true;
310: $this->strTagName = $mixValue;
311: }
312: break;
313: } catch (QInvalidCastException $objExc) {
314: $objExc->IncrementOffset();
315: throw $objExc;
316: }
317:
318: case "HtmlEntities":
319: try {
320: if ($this->blnHtmlEntities !== ($mixValue = QType::Cast($mixValue, QType::Boolean))) {
321: $this->blnModified = true;
322: $this->blnHtmlEntities = $mixValue;
323: }
324: break;
325: } catch (QInvalidCastException $objExc) {
326: $objExc->IncrementOffset();
327: throw $objExc;
328: }
329:
330: case "DropTarget":
331: try {
332: if ($this->blnDropTarget !== ($mixValue = QType::Cast($mixValue, QType::Boolean))) {
333: $this->blnModified = true;
334: $this->blnDropTarget = $mixValue;
335: }
336: break;
337: } catch (QInvalidCastException $objExc) {
338: $objExc->IncrementOffset();
339: throw $objExc;
340: }
341:
342:
343: default:
344: try {
345: parent::__set($strName, $mixValue);
346: } catch (QCallerException $objExc) {
347: $objExc->IncrementOffset();
348: throw $objExc;
349: }
350: break;
351: }
352: }
353:
354: }
355:
356: $_CONTROL = null;