1: <?php
2: /**
3: * Triggered when the selectable is created.
4: *
5: * * event Type: Event
6: * * ui Type: Object
7: *
8: * _Note: The ui object is empty but included for consistency with other
9: * events._ */
10: class QSelectable_CreateEvent extends QJqUiEvent {
11: const EventName = 'selectablecreate';
12: }
13: /**
14: * Triggered at the end of the select operation, on each element added to
15: * the selection.
16: *
17: * * event Type: Event
18: *
19: * * ui Type: Object
20: *
21: * * selected Type: Element The selectable item that has been selected.
22: *
23: */
24: class QSelectable_SelectedEvent extends QJqUiEvent {
25: const EventName = 'selectableselected';
26: }
27: /**
28: * Triggered during the select operation, on each element added to the
29: * selection.
30: *
31: * * event Type: Event
32: *
33: * * ui Type: Object
34: *
35: * * selecting Type: Element The current selectable item being selected.
36: *
37: */
38: class QSelectable_SelectingEvent extends QJqUiEvent {
39: const EventName = 'selectableselecting';
40: }
41: /**
42: * Triggered at the beginning of the select operation.
43: *
44: * * event Type: Event
45: * * ui Type: Object
46: *
47: * _Note: The ui object is empty but included for consistency with other
48: * events._ */
49: class QSelectable_StartEvent extends QJqUiEvent {
50: const EventName = 'selectablestart';
51: }
52: /**
53: * Triggered at the end of the select operation.
54: *
55: * * event Type: Event
56: * * ui Type: Object
57: *
58: * _Note: The ui object is empty but included for consistency with other
59: * events._ */
60: class QSelectable_StopEvent extends QJqUiEvent {
61: const EventName = 'selectablestop';
62: }
63: /**
64: * Triggered at the end of the select operation, on each element removed
65: * from the selection.
66: *
67: * * event Type: Event
68: *
69: * * ui Type: Object
70: *
71: * * unselected Type: Element The selectable item that has been
72: * unselected.
73: *
74: */
75: class QSelectable_UnselectedEvent extends QJqUiEvent {
76: const EventName = 'selectableunselected';
77: }
78: /**
79: * Triggered during the select operation, on each element removed from
80: * the selection.
81: *
82: * * event Type: Event
83: *
84: * * ui Type: Object
85: *
86: * * unselecting Type: Element The current selectable item being
87: * unselected.
88: *
89: */
90: class QSelectable_UnselectingEvent extends QJqUiEvent {
91: const EventName = 'selectableunselecting';
92: }
93:
94: /* Custom "property" event classes for this control */
95:
96: /**
97: * Generated QSelectableGen class.
98: *
99: * This is the QSelectableGen class which is automatically generated
100: * by scraping the JQuery UI documentation website. As such, it includes all the options
101: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
102: * the QSelectableBase class for any glue code to make this class more
103: * usable in QCubed.
104: *
105: * @see QSelectableBase
106: * @package Controls\Base
107: * @property mixed $AppendTo
108: * Which element the selection helper (the lasso) should be appended to.
109: *
110: * @property boolean $AutoRefresh
111: * This determines whether to refresh (recalculate) the position and size
112: * of each selectee at the beginning of each select operation. If you
113: * have many items, you may want to set this to false and call the
114: * refresh() method manually.
115: *
116: * @property mixed $Cancel
117: * Prevents selecting if you start on elements matching the selector.
118: *
119: * @property integer $Delay
120: * Time in milliseconds to define when the selecting should start. This
121: * helps prevent unwanted selections when clicking on an element.
122: *
123: * @property boolean $Disabled
124: * Disables the selectable if set to true.
125: *
126: * @property integer $Distance
127: * Tolerance, in pixels, for when selecting should start. If specified,
128: * selecting will not start until the mouse has been dragged beyond the
129: * specified distance.
130: *
131: * @property mixed $Filter
132: * The matching child elements will be made selectees (able to be
133: * selected).
134: *
135: * @property string $Tolerance
136: * Specifies which mode to use for testing whether the lasso should
137: * select an item. Possible values:
138: *
139: * * "fit": Lasso overlaps the item entirely.
140: * * "touch": Lasso overlaps the item by any amount.
141: *
142:
143: *
144: */
145:
146: class QSelectableGen extends QPanel {
147: protected $strJavaScripts = __JQUERY_EFFECTS__;
148: protected $strStyleSheets = __JQUERY_CSS__;
149: /** @var mixed */
150: protected $mixAppendTo = null;
151: /** @var boolean */
152: protected $blnAutoRefresh = null;
153: /** @var mixed */
154: protected $mixCancel = null;
155: /** @var integer */
156: protected $intDelay;
157: /** @var boolean */
158: protected $blnDisabled = null;
159: /** @var integer */
160: protected $intDistance;
161: /** @var mixed */
162: protected $mixFilter = null;
163: /** @var string */
164: protected $strTolerance = null;
165:
166: /**
167: * Builds the option array to be sent to the widget constructor.
168: *
169: * @return array key=>value array of options
170: */
171: protected function MakeJqOptions() {
172: $jqOptions = null;
173: if (!is_null($val = $this->AppendTo)) {$jqOptions['appendTo'] = $val;}
174: if (!is_null($val = $this->AutoRefresh)) {$jqOptions['autoRefresh'] = $val;}
175: if (!is_null($val = $this->Cancel)) {$jqOptions['cancel'] = $val;}
176: if (!is_null($val = $this->Delay)) {$jqOptions['delay'] = $val;}
177: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
178: if (!is_null($val = $this->Distance)) {$jqOptions['distance'] = $val;}
179: if (!is_null($val = $this->Filter)) {$jqOptions['filter'] = $val;}
180: if (!is_null($val = $this->Tolerance)) {$jqOptions['tolerance'] = $val;}
181: return $jqOptions;
182: }
183:
184: /**
185: * Return the JavaScript function to call to associate the widget with the control.
186: *
187: * @return string
188: */
189: public function GetJqSetupFunction() {
190: return 'selectable';
191: }
192:
193: /**
194: * Returns the script that attaches the JQueryUI widget to the html object.
195: *
196: * @return string
197: */
198: public function GetEndScript() {
199: $strId = $this->GetJqControlId();
200: $jqOptions = $this->makeJqOptions();
201: $strFunc = $this->getJqSetupFunction();
202:
203: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
204: // If events are not attached to the actual object being drawn, then the old events will not get
205: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
206: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
207: }
208:
209: // Attach the javascript widget to the html object
210: if (empty($jqOptions)) {
211: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
212: } else {
213: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
214: }
215:
216: return parent::GetEndScript();
217: }
218:
219: /**
220: * Removes the selectable functionality completely. This will return the
221: * element back to its pre-init state.
222: *
223: * * This method does not accept any arguments.
224: */
225: public function Destroy() {
226: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
227: }
228: /**
229: * Disables the selectable.
230: *
231: * * This method does not accept any arguments.
232: */
233: public function Disable() {
234: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
235: }
236: /**
237: * Enables the selectable.
238: *
239: * * This method does not accept any arguments.
240: */
241: public function Enable() {
242: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
243: }
244: /**
245: * Retrieves the selectables instance object. If the element does not
246: * have an associated instance, undefined is returned.
247: *
248: * Unlike other widget methods, instance() is safe to call on any element
249: * after the selectable plugin has loaded.
250: *
251: * * This method does not accept any arguments.
252: */
253: public function Instance() {
254: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
255: }
256: /**
257: * Gets the value currently associated with the specified optionName.
258: *
259: * Note: For options that have objects as their value, you can get the
260: * value of a specific key by using dot notation. For example, "foo.bar"
261: * would get the value of the bar property on the foo option.
262: *
263: * * optionName Type: String The name of the option to get.
264: * @param $optionName
265: */
266: public function Option($optionName) {
267: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
268: }
269: /**
270: * Gets an object containing key/value pairs representing the current
271: * selectable options hash.
272: *
273: * * This signature does not accept any arguments.
274: */
275: public function Option1() {
276: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
277: }
278: /**
279: * Sets the value of the selectable option associated with the specified
280: * optionName.
281: *
282: * Note: For options that have objects as their value, you can set the
283: * value of just one property by using dot notation for optionName. For
284: * example, "foo.bar" would update only the bar property of the foo
285: * option.
286: *
287: * * optionName Type: String The name of the option to set.
288: * * value Type: Object A value to set for the option.
289: * @param $optionName
290: * @param $value
291: */
292: public function Option2($optionName, $value) {
293: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
294: }
295: /**
296: * Sets one or more options for the selectable.
297: *
298: * * options Type: Object A map of option-value pairs to set.
299: * @param $options
300: */
301: public function Option3($options) {
302: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
303: }
304: /**
305: * Refresh the position and size of each selectee element. This method
306: * can be used to manually recalculate the position and size of each
307: * selectee when the autoRefresh option is set to false.
308: *
309: * * This method does not accept any arguments.
310: */
311: public function Refresh() {
312: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
313: }
314:
315:
316: public function __get($strName) {
317: switch ($strName) {
318: case 'AppendTo': return $this->mixAppendTo;
319: case 'AutoRefresh': return $this->blnAutoRefresh;
320: case 'Cancel': return $this->mixCancel;
321: case 'Delay': return $this->intDelay;
322: case 'Disabled': return $this->blnDisabled;
323: case 'Distance': return $this->intDistance;
324: case 'Filter': return $this->mixFilter;
325: case 'Tolerance': return $this->strTolerance;
326: default:
327: try {
328: return parent::__get($strName);
329: } catch (QCallerException $objExc) {
330: $objExc->IncrementOffset();
331: throw $objExc;
332: }
333: }
334: }
335:
336: public function __set($strName, $mixValue) {
337: switch ($strName) {
338: case 'AppendTo':
339: $this->mixAppendTo = $mixValue;
340: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'appendTo', $mixValue);
341: break;
342:
343: case 'AutoRefresh':
344: try {
345: $this->blnAutoRefresh = QType::Cast($mixValue, QType::Boolean);
346: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'autoRefresh', $this->blnAutoRefresh);
347: break;
348: } catch (QInvalidCastException $objExc) {
349: $objExc->IncrementOffset();
350: throw $objExc;
351: }
352:
353: case 'Cancel':
354: $this->mixCancel = $mixValue;
355: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'cancel', $mixValue);
356: break;
357:
358: case 'Delay':
359: try {
360: $this->intDelay = QType::Cast($mixValue, QType::Integer);
361: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'delay', $this->intDelay);
362: break;
363: } catch (QInvalidCastException $objExc) {
364: $objExc->IncrementOffset();
365: throw $objExc;
366: }
367:
368: case 'Disabled':
369: try {
370: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
371: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
372: break;
373: } catch (QInvalidCastException $objExc) {
374: $objExc->IncrementOffset();
375: throw $objExc;
376: }
377:
378: case 'Distance':
379: try {
380: $this->intDistance = QType::Cast($mixValue, QType::Integer);
381: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'distance', $this->intDistance);
382: break;
383: } catch (QInvalidCastException $objExc) {
384: $objExc->IncrementOffset();
385: throw $objExc;
386: }
387:
388: case 'Filter':
389: $this->mixFilter = $mixValue;
390: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'filter', $mixValue);
391: break;
392:
393: case 'Tolerance':
394: try {
395: $this->strTolerance = QType::Cast($mixValue, QType::String);
396: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'tolerance', $this->strTolerance);
397: break;
398: } catch (QInvalidCastException $objExc) {
399: $objExc->IncrementOffset();
400: throw $objExc;
401: }
402:
403:
404: case 'Enabled':
405: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
406: parent::__set($strName, $mixValue);
407: break;
408:
409: default:
410: try {
411: parent::__set($strName, $mixValue);
412: break;
413: } catch (QCallerException $objExc) {
414: $objExc->IncrementOffset();
415: throw $objExc;
416: }
417: }
418: }
419:
420: /**
421: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
422: * used by the ModelConnector designer dialog to display a list of options for the control.
423: * @return QModelConnectorParam[]
424: **/
425: public static function GetModelConnectorParams() {
426: return array_merge(parent::GetModelConnectorParams(), array(
427: new QModelConnectorParam (get_called_class(), 'AutoRefresh', 'This determines whether to refresh (recalculate) the position and sizeof each selectee at the beginning of each select operation. If youhave many items, you may want to set this to false and call therefresh() method manually.', QType::Boolean),
428: new QModelConnectorParam (get_called_class(), 'Delay', 'Time in milliseconds to define when the selecting should start. Thishelps prevent unwanted selections when clicking on an element.', QType::Integer),
429: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the selectable if set to true.', QType::Boolean),
430: new QModelConnectorParam (get_called_class(), 'Distance', 'Tolerance, in pixels, for when selecting should start. If specified,selecting will not start until the mouse has been dragged beyond thespecified distance.', QType::Integer),
431: new QModelConnectorParam (get_called_class(), 'Tolerance', 'Specifies which mode to use for testing whether the lasso shouldselect an item. Possible values: * \"fit\": Lasso overlaps the item entirely. * \"touch\": Lasso overlaps the item by any amount.', QType::String),
432: ));
433: }
434: }