1: <?php
2: /**
3: * Triggered when an accepted draggable starts dragging. This can be
4: * useful if you want to make the droppable "light up" when it can be
5: * dropped on.
6: *
7: * * event Type: Event
8: *
9: * * ui Type: Object
10: *
11: * * draggable Type: jQuery A jQuery object representing the draggable
12: * element.
13: * * helper Type: jQuery A jQuery object representing the helper that
14: * is being dragged.
15: * * position Type: Object Current CSS position of the draggable helper
16: * as { top, left } object.
17: * * offset Type: Object Current offset position of the draggable
18: * helper as { top, left } object.
19: *
20: */
21: class QDroppable_ActivateEvent extends QJqUiEvent {
22: const EventName = 'dropactivate';
23: }
24: /**
25: * Triggered when the droppable is created.
26: *
27: * * event Type: Event
28: * * ui Type: Object
29: *
30: * _Note: The ui object is empty but included for consistency with other
31: * events._ */
32: class QDroppable_CreateEvent extends QJqUiEvent {
33: const EventName = 'dropcreate';
34: }
35: /**
36: * Triggered when an accepted draggable stops dragging.
37: *
38: * * event Type: Event
39: *
40: * * ui Type: Object
41: *
42: * * draggable Type: jQuery A jQuery object representing the draggable
43: * element.
44: * * helper Type: jQuery A jQuery object representing the helper that
45: * is being dragged.
46: * * position Type: Object Current CSS position of the draggable helper
47: * as { top, left } object.
48: * * offset Type: Object Current offset position of the draggable
49: * helper as { top, left } object.
50: *
51: */
52: class QDroppable_DeactivateEvent extends QJqUiEvent {
53: const EventName = 'dropdeactivate';
54: }
55: /**
56: * Triggered when an accepted draggable is dropped on the droppable
57: * (based on thetolerance option).
58: *
59: * * event Type: Event
60: *
61: * * ui Type: Object
62: *
63: * * draggable Type: jQuery A jQuery object representing the draggable
64: * element.
65: * * helper Type: jQuery A jQuery object representing the helper that
66: * is being dragged.
67: * * position Type: Object Current CSS position of the draggable helper
68: * as { top, left } object.
69: * * offset Type: Object Current offset position of the draggable
70: * helper as { top, left } object.
71: *
72: */
73: class QDroppable_DropEvent extends QJqUiEvent {
74: const EventName = 'drop';
75: }
76: /**
77: * Triggered when an accepted draggable is dragged out of the droppable
78: * (based on thetolerance option).
79: *
80: * * event Type: Event
81: * * ui Type: Object
82: *
83: * _Note: The ui object is empty but included for consistency with other
84: * events._ */
85: class QDroppable_OutEvent extends QJqUiEvent {
86: const EventName = 'dropout';
87: }
88: /**
89: * Triggered when an accepted draggable is dragged over the droppable
90: * (based on thetolerance option).
91: *
92: * * event Type: Event
93: *
94: * * ui Type: Object
95: *
96: * * draggable Type: jQuery A jQuery object representing the draggable
97: * element.
98: * * helper Type: jQuery A jQuery object representing the helper that
99: * is being dragged.
100: * * position Type: Object Current CSS position of the draggable helper
101: * as { top, left } object.
102: * * offset Type: Object Current offset position of the draggable
103: * helper as { top, left } object.
104: *
105: */
106: class QDroppable_OverEvent extends QJqUiEvent {
107: const EventName = 'dropover';
108: }
109:
110: /* Custom "property" event classes for this control */
111:
112: /**
113: * Generated QDroppableGen class.
114: *
115: * This is the QDroppableGen class which is automatically generated
116: * by scraping the JQuery UI documentation website. As such, it includes all the options
117: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
118: * the QDroppableBase class for any glue code to make this class more
119: * usable in QCubed.
120: *
121: * @see QDroppableBase
122: * @package Controls\Base
123: * @property mixed $Accept
124: * Controls which draggable elements are accepted by the
125: * droppable.Multiple types supported:
126: *
127: * * Selector: A selector indicating which draggable elements are
128: * accepted.
129: * * Function: A function that will be called for each draggable on the
130: * page (passed as the first argument to the function). The function must
131: * return true if the draggable should be accepted.
132: *
133:
134: *
135: * @property string $ActiveClass
136: * If specified, the class will be added to the droppable while an
137: * acceptable draggable is being dragged.
138: *
139: * @property boolean $AddClasses
140: * If set to false, will prevent the ui-droppable class from being added.
141: * This may be desired as a performance optimization when calling
142: * .droppable() init on hundreds of elements.
143: *
144: * @property boolean $Disabled
145: * Disables the droppable if set to true.
146: *
147: * @property boolean $Greedy
148: * By default, when an element is dropped on nested droppables, each
149: * droppable will receive the element. However, by setting this option to
150: * true, any parent droppables will not receive the element. The drop
151: * event will still bubble normally, but the event.target can be checked
152: * to see which droppable received the draggable element.
153: *
154: * @property string $HoverClass
155: * If specified, the class will be added to the droppable while an
156: * acceptable draggable is being hovered over the droppable.
157: *
158: * @property string $Scope
159: * Used to group sets of draggable and droppable items, in addition to
160: * the accept option. A draggable with the same scope value as a
161: * droppable will be accepted.
162: *
163: * @property string $Tolerance
164: * Specifies which mode to use for testing whether a draggable is
165: * hovering over a droppable. Possible values:
166: *
167: * * "fit": Draggable overlaps the droppable entirely.
168: * * "intersect": Draggable overlaps the droppable at least 50% in both
169: * directions.
170: * * "pointer": Mouse pointer overlaps the droppable.
171: * * "touch": Draggable overlaps the droppable any amount.
172: *
173:
174: *
175: */
176:
177: abstract class QDroppableGen extends QControl {
178: protected $strJavaScripts = __JQUERY_EFFECTS__;
179: protected $strStyleSheets = __JQUERY_CSS__;
180: /** @var mixed */
181: protected $mixAccept = null;
182: /** @var string */
183: protected $strActiveClass = null;
184: /** @var boolean */
185: protected $blnAddClasses = null;
186: /** @var boolean */
187: protected $blnDisabled = null;
188: /** @var boolean */
189: protected $blnGreedy = null;
190: /** @var string */
191: protected $strHoverClass = null;
192: /** @var string */
193: protected $strScope = null;
194: /** @var string */
195: protected $strTolerance = null;
196:
197: /**
198: * Builds the option array to be sent to the widget constructor.
199: *
200: * @return array key=>value array of options
201: */
202: protected function MakeJqOptions() {
203: $jqOptions = null;
204: if (!is_null($val = $this->Accept)) {$jqOptions['accept'] = $val;}
205: if (!is_null($val = $this->ActiveClass)) {$jqOptions['activeClass'] = $val;}
206: if (!is_null($val = $this->AddClasses)) {$jqOptions['addClasses'] = $val;}
207: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
208: if (!is_null($val = $this->Greedy)) {$jqOptions['greedy'] = $val;}
209: if (!is_null($val = $this->HoverClass)) {$jqOptions['hoverClass'] = $val;}
210: if (!is_null($val = $this->Scope)) {$jqOptions['scope'] = $val;}
211: if (!is_null($val = $this->Tolerance)) {$jqOptions['tolerance'] = $val;}
212: return $jqOptions;
213: }
214:
215: /**
216: * Return the JavaScript function to call to associate the widget with the control.
217: *
218: * @return string
219: */
220: public function GetJqSetupFunction() {
221: return 'droppable';
222: }
223:
224: /**
225: * Returns the script that attaches the JQueryUI widget to the html object.
226: *
227: * @return string
228: */
229: public function GetEndScript() {
230: $strId = $this->GetJqControlId();
231: $jqOptions = $this->makeJqOptions();
232: $strFunc = $this->getJqSetupFunction();
233:
234: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
235: // If events are not attached to the actual object being drawn, then the old events will not get
236: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
237: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
238: }
239:
240: // Attach the javascript widget to the html object
241: if (empty($jqOptions)) {
242: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
243: } else {
244: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
245: }
246:
247: return parent::GetEndScript();
248: }
249:
250: /**
251: * Removes the droppable functionality completely. This will return the
252: * element back to its pre-init state.
253: *
254: * * This method does not accept any arguments.
255: */
256: public function Destroy() {
257: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
258: }
259: /**
260: * Disables the droppable.
261: *
262: * * This method does not accept any arguments.
263: */
264: public function Disable() {
265: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
266: }
267: /**
268: * Enables the droppable.
269: *
270: * * This method does not accept any arguments.
271: */
272: public function Enable() {
273: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
274: }
275: /**
276: * Retrieves the droppables instance object. If the element does not have
277: * an associated instance, undefined is returned.
278: *
279: * Unlike other widget methods, instance() is safe to call on any element
280: * after the droppable plugin has loaded.
281: *
282: * * This method does not accept any arguments.
283: */
284: public function Instance() {
285: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
286: }
287: /**
288: * Gets the value currently associated with the specified optionName.
289: *
290: * Note: For options that have objects as their value, you can get the
291: * value of a specific key by using dot notation. For example, "foo.bar"
292: * would get the value of the bar property on the foo option.
293: *
294: * * optionName Type: String The name of the option to get.
295: * @param $optionName
296: */
297: public function Option($optionName) {
298: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
299: }
300: /**
301: * Gets an object containing key/value pairs representing the current
302: * droppable options hash.
303: *
304: * * This signature does not accept any arguments.
305: */
306: public function Option1() {
307: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
308: }
309: /**
310: * Sets the value of the droppable option associated with the specified
311: * optionName.
312: *
313: * Note: For options that have objects as their value, you can set the
314: * value of just one property by using dot notation for optionName. For
315: * example, "foo.bar" would update only the bar property of the foo
316: * option.
317: *
318: * * optionName Type: String The name of the option to set.
319: * * value Type: Object A value to set for the option.
320: * @param $optionName
321: * @param $value
322: */
323: public function Option2($optionName, $value) {
324: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
325: }
326: /**
327: * Sets one or more options for the droppable.
328: *
329: * * options Type: Object A map of option-value pairs to set.
330: * @param $options
331: */
332: public function Option3($options) {
333: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
334: }
335:
336:
337: public function __get($strName) {
338: switch ($strName) {
339: case 'Accept': return $this->mixAccept;
340: case 'ActiveClass': return $this->strActiveClass;
341: case 'AddClasses': return $this->blnAddClasses;
342: case 'Disabled': return $this->blnDisabled;
343: case 'Greedy': return $this->blnGreedy;
344: case 'HoverClass': return $this->strHoverClass;
345: case 'Scope': return $this->strScope;
346: case 'Tolerance': return $this->strTolerance;
347: default:
348: try {
349: return parent::__get($strName);
350: } catch (QCallerException $objExc) {
351: $objExc->IncrementOffset();
352: throw $objExc;
353: }
354: }
355: }
356:
357: public function __set($strName, $mixValue) {
358: switch ($strName) {
359: case 'Accept':
360: $this->mixAccept = $mixValue;
361: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'accept', $mixValue);
362: break;
363:
364: case 'ActiveClass':
365: try {
366: $this->strActiveClass = QType::Cast($mixValue, QType::String);
367: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'activeClass', $this->strActiveClass);
368: break;
369: } catch (QInvalidCastException $objExc) {
370: $objExc->IncrementOffset();
371: throw $objExc;
372: }
373:
374: case 'AddClasses':
375: try {
376: $this->blnAddClasses = QType::Cast($mixValue, QType::Boolean);
377: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'addClasses', $this->blnAddClasses);
378: break;
379: } catch (QInvalidCastException $objExc) {
380: $objExc->IncrementOffset();
381: throw $objExc;
382: }
383:
384: case 'Disabled':
385: try {
386: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
387: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
388: break;
389: } catch (QInvalidCastException $objExc) {
390: $objExc->IncrementOffset();
391: throw $objExc;
392: }
393:
394: case 'Greedy':
395: try {
396: $this->blnGreedy = QType::Cast($mixValue, QType::Boolean);
397: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'greedy', $this->blnGreedy);
398: break;
399: } catch (QInvalidCastException $objExc) {
400: $objExc->IncrementOffset();
401: throw $objExc;
402: }
403:
404: case 'HoverClass':
405: try {
406: $this->strHoverClass = QType::Cast($mixValue, QType::String);
407: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'hoverClass', $this->strHoverClass);
408: break;
409: } catch (QInvalidCastException $objExc) {
410: $objExc->IncrementOffset();
411: throw $objExc;
412: }
413:
414: case 'Scope':
415: try {
416: $this->strScope = QType::Cast($mixValue, QType::String);
417: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'scope', $this->strScope);
418: break;
419: } catch (QInvalidCastException $objExc) {
420: $objExc->IncrementOffset();
421: throw $objExc;
422: }
423:
424: case 'Tolerance':
425: try {
426: $this->strTolerance = QType::Cast($mixValue, QType::String);
427: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'tolerance', $this->strTolerance);
428: break;
429: } catch (QInvalidCastException $objExc) {
430: $objExc->IncrementOffset();
431: throw $objExc;
432: }
433:
434:
435: case 'Enabled':
436: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
437: parent::__set($strName, $mixValue);
438: break;
439:
440: default:
441: try {
442: parent::__set($strName, $mixValue);
443: break;
444: } catch (QCallerException $objExc) {
445: $objExc->IncrementOffset();
446: throw $objExc;
447: }
448: }
449: }
450:
451: /**
452: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
453: * used by the ModelConnector designer dialog to display a list of options for the control.
454: * @return QModelConnectorParam[]
455: **/
456: public static function GetModelConnectorParams() {
457: return array_merge(parent::GetModelConnectorParams(), array(
458: new QModelConnectorParam (get_called_class(), 'ActiveClass', 'If specified, the class will be added to the droppable while anacceptable draggable is being dragged.', QType::String),
459: new QModelConnectorParam (get_called_class(), 'AddClasses', 'If set to false, will prevent the ui-droppable class from being added.This may be desired as a performance optimization when calling.droppable() init on hundreds of elements.', QType::Boolean),
460: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the droppable if set to true.', QType::Boolean),
461: new QModelConnectorParam (get_called_class(), 'Greedy', 'By default, when an element is dropped on nested droppables, eachdroppable will receive the element. However, by setting this option totrue, any parent droppables will not receive the element. The dropevent will still bubble normally, but the event.target can be checkedto see which droppable received the draggable element.', QType::Boolean),
462: new QModelConnectorParam (get_called_class(), 'HoverClass', 'If specified, the class will be added to the droppable while anacceptable draggable is being hovered over the droppable.', QType::String),
463: new QModelConnectorParam (get_called_class(), 'Scope', 'Used to group sets of draggable and droppable items, in addition tothe accept option. A draggable with the same scope value as adroppable will be accepted.', QType::String),
464: new QModelConnectorParam (get_called_class(), 'Tolerance', 'Specifies which mode to use for testing whether a draggable ishovering over a droppable. Possible values: * \"fit\": Draggable overlaps the droppable entirely. * \"intersect\": Draggable overlaps the droppable at least 50% in bothdirections. * \"pointer\": Mouse pointer overlaps the droppable. * \"touch\": Draggable overlaps the droppable any amount.', QType::String),
465: ));
466: }
467: }