1: <?php
2: /**
3: * Triggered when the value of the spinner has changed and the input is
4: * no longer focused.
5: *
6: * * event Type: Event
7: * * ui Type: Object
8: *
9: * _Note: The ui object is empty but included for consistency with other
10: * events._ */
11: class QSpinner_ChangeEvent extends QJqUiEvent {
12: const EventName = 'spinchange';
13: }
14: /**
15: * Triggered when the spinner is created.
16: *
17: * * event Type: Event
18: * * ui Type: Object
19: *
20: * _Note: The ui object is empty but included for consistency with other
21: * events._ */
22: class QSpinner_CreateEvent extends QJqUiEvent {
23: const EventName = 'spincreate';
24: }
25: /**
26: * Triggered during increment/decrement (to determine direction of spin
27: * compare current value with ui.value).
28: *
29: * Can be canceled, preventing the value from being updated.
30: *
31: * * event Type: Event
32: *
33: * * ui Type: Object
34: *
35: * * value Type: Number The new value to be set, unless the event is
36: * cancelled.
37: *
38: */
39: class QSpinner_SpinEvent extends QJqUiEvent {
40: const EventName = 'spin';
41: }
42: /**
43: * Triggered before a spin. Can be canceled, preventing the spin from
44: * occurring.
45: *
46: * * event Type: Event
47: * * ui Type: Object
48: *
49: * _Note: The ui object is empty but included for consistency with other
50: * events._ */
51: class QSpinner_StartEvent extends QJqUiEvent {
52: const EventName = 'spinstart';
53: }
54: /**
55: * Triggered after a spin.
56: *
57: * * event Type: Event
58: * * ui Type: Object
59: *
60: * _Note: The ui object is empty but included for consistency with other
61: * events._ */
62: class QSpinner_StopEvent extends QJqUiEvent {
63: const EventName = 'spinstop';
64: }
65:
66: /* Custom "property" event classes for this control */
67:
68: /**
69: * Generated QSpinnerGen class.
70: *
71: * This is the QSpinnerGen class which is automatically generated
72: * by scraping the JQuery UI documentation website. As such, it includes all the options
73: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
74: * the QSpinnerBase class for any glue code to make this class more
75: * usable in QCubed.
76: *
77: * @see QSpinnerBase
78: * @package Controls\Base
79: * @property string $Culture
80: * Sets the culture to use for parsing and formatting the value. If null,
81: * the currently set culture in Globalize is used, see Globalize docs for
82: * available cultures. Only relevant if the numberFormat option is set.
83: * Requires Globalize to be included.
84: *
85: * @property boolean $Disabled
86: * Disables the spinner if set to true.
87: *
88: * @property mixed $Icons
89: * Icons to use for buttons, matching an icon provided by the jQuery UI
90: * CSS Framework.
91: *
92: * * up (string, default: "ui-icon-triangle-1-n")
93: * * down (string, default: "ui-icon-triangle-1-s")
94: *
95:
96: *
97: * @property mixed $Incremental
98: * Controls the number of steps taken when holding down a spin
99: * button.Multiple types supported:
100: *
101: * * Boolean: When set to true, the stepping delta will increase when
102: * spun incessantly. When set to false, all steps are equal (as defined
103: * by the step option).
104: * * Function: Receives one parameter: the number of spins that have
105: * occurred. Must return the number of steps that should occur for the
106: * current spin.
107: *
108:
109: *
110: * @property mixed $Max
111: * The maximum allowed value. The elements max attribute is used if it
112: * exists and the option is not explicitly set. If null, there is no
113: * maximum enforced.Multiple types supported:
114: *
115: * * Number: The maximum value.
116: * * String: If Globalize is included, the max option can be passed as
117: * a string which will be parsed based on the numberFormat and culture
118: * options; otherwise it will fall back to the native parseFloat()
119: * method.
120: *
121:
122: *
123: * @property mixed $Min
124: * The minimum allowed value. The elements min attribute is used if it
125: * exists and the option is not explicitly set. If null, there is no
126: * minimum enforced.Multiple types supported:
127: *
128: * * Number: The minimum value.
129: * * String: If Globalize is included, the min option can be passed as
130: * a string which will be parsed based on the numberFormat and culture
131: * options; otherwise it will fall back to the native parseFloat()
132: * method.
133: *
134:
135: *
136: * @property string $NumberFormat
137: * Format of numbers passed to Globalize, if available. Most common are
138: * "n" for a decimal number and "C" for a currency value. Also see the
139: * culture option.
140: *
141: * @property integer $Page
142: * The number of steps to take when paging via the pageUp/pageDown
143: * methods.
144: *
145: * @property mixed $Step
146: * The size of the step to take when spinning via buttons or via the
147: * stepUp()/stepDown() methods. The elements step attribute is used if it
148: * exists and the option is not explicitly set.Multiple types supported:
149: *
150: * * Number: The size of the step.
151: * * String: If Globalize is included, the step option can be passed as
152: * a string which will be parsed based on the numberFormat and culture
153: * options, otherwise it will fall back to the native parseFloat.
154: *
155:
156: *
157: */
158:
159: class QSpinnerGen extends QTextBox {
160: protected $strJavaScripts = __JQUERY_EFFECTS__;
161: protected $strStyleSheets = __JQUERY_CSS__;
162: /** @var string */
163: protected $strCulture = null;
164: /** @var boolean */
165: protected $blnDisabled = null;
166: /** @var mixed */
167: protected $mixIcons = null;
168: /** @var mixed */
169: protected $mixIncremental = null;
170: /** @var mixed */
171: protected $mixMax = null;
172: /** @var mixed */
173: protected $mixMin = null;
174: /** @var string */
175: protected $strNumberFormat = null;
176: /** @var integer */
177: protected $intPage = null;
178: /** @var mixed */
179: protected $mixStep = null;
180:
181: /**
182: * Builds the option array to be sent to the widget constructor.
183: *
184: * @return array key=>value array of options
185: */
186: protected function MakeJqOptions() {
187: $jqOptions = null;
188: if (!is_null($val = $this->Culture)) {$jqOptions['culture'] = $val;}
189: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
190: if (!is_null($val = $this->Icons)) {$jqOptions['icons'] = $val;}
191: if (!is_null($val = $this->Incremental)) {$jqOptions['incremental'] = $val;}
192: if (!is_null($val = $this->Max)) {$jqOptions['max'] = $val;}
193: if (!is_null($val = $this->Min)) {$jqOptions['min'] = $val;}
194: if (!is_null($val = $this->NumberFormat)) {$jqOptions['numberFormat'] = $val;}
195: if (!is_null($val = $this->Page)) {$jqOptions['page'] = $val;}
196: if (!is_null($val = $this->Step)) {$jqOptions['step'] = $val;}
197: return $jqOptions;
198: }
199:
200: /**
201: * Return the JavaScript function to call to associate the widget with the control.
202: *
203: * @return string
204: */
205: public function GetJqSetupFunction() {
206: return 'spinner';
207: }
208:
209: /**
210: * Returns the script that attaches the JQueryUI widget to the html object.
211: *
212: * @return string
213: */
214: public function GetEndScript() {
215: $strId = $this->GetJqControlId();
216: $jqOptions = $this->makeJqOptions();
217: $strFunc = $this->getJqSetupFunction();
218:
219: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
220: // If events are not attached to the actual object being drawn, then the old events will not get
221: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
222: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
223: }
224:
225: // Attach the javascript widget to the html object
226: if (empty($jqOptions)) {
227: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
228: } else {
229: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
230: }
231:
232: return parent::GetEndScript();
233: }
234:
235: /**
236: * Removes the spinner functionality completely. This will return the
237: * element back to its pre-init state.
238: *
239: * * This method does not accept any arguments.
240: */
241: public function Destroy() {
242: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
243: }
244: /**
245: * Disables the spinner.
246: *
247: * * This method does not accept any arguments.
248: */
249: public function Disable() {
250: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
251: }
252: /**
253: * Enables the spinner.
254: *
255: * * This method does not accept any arguments.
256: */
257: public function Enable() {
258: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
259: }
260: /**
261: * Retrieves the spinners instance object. If the element does not have
262: * an associated instance, undefined is returned.
263: *
264: * Unlike other widget methods, instance() is safe to call on any element
265: * after the spinner plugin has loaded.
266: *
267: * * This method does not accept any arguments.
268: */
269: public function Instance() {
270: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
271: }
272: /**
273: * Returns whether the Spinners value is valid given its min, max, and
274: * step.
275: *
276: * * This method does not accept any arguments.
277: */
278: public function IsValid() {
279: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "isValid", QJsPriority::Low);
280: }
281: /**
282: * Gets the value currently associated with the specified optionName.
283: *
284: * Note: For options that have objects as their value, you can get the
285: * value of a specific key by using dot notation. For example, "foo.bar"
286: * would get the value of the bar property on the foo option.
287: *
288: * * optionName Type: String The name of the option to get.
289: * @param $optionName
290: */
291: public function Option($optionName) {
292: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
293: }
294: /**
295: * Gets an object containing key/value pairs representing the current
296: * spinner options hash.
297: *
298: * * This signature does not accept any arguments.
299: */
300: public function Option1() {
301: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
302: }
303: /**
304: * Sets the value of the spinner option associated with the specified
305: * optionName.
306: *
307: * Note: For options that have objects as their value, you can set the
308: * value of just one property by using dot notation for optionName. For
309: * example, "foo.bar" would update only the bar property of the foo
310: * option.
311: *
312: * * optionName Type: String The name of the option to set.
313: * * value Type: Object A value to set for the option.
314: * @param $optionName
315: * @param $value
316: */
317: public function Option2($optionName, $value) {
318: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
319: }
320: /**
321: * Sets one or more options for the spinner.
322: *
323: * * options Type: Object A map of option-value pairs to set.
324: * @param $options
325: */
326: public function Option3($options) {
327: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
328: }
329: /**
330: * Decrements the value by the specified number of pages, as defined by
331: * the page option. Without the parameter, a single page is decremented.
332: *
333: * If the resulting value is above the max, below the min, or results in
334: * a step mismatch, the value will be adjusted to the closest valid
335: * value.
336: *
337: * Invoking pageDown() will cause start, spin, and stop events to be
338: * triggered.
339: *
340: * * pages Type: Number Number of pages to decrement, defaults to 1.
341: * @param $pages
342: */
343: public function PageDown($pages = null) {
344: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "pageDown", $pages, QJsPriority::Low);
345: }
346: /**
347: * Increments the value by the specified number of pages, as defined by
348: * the page option. Without the parameter, a single page is incremented.
349: *
350: * If the resulting value is above the max, below the min, or results in
351: * a step mismatch, the value will be adjusted to the closest valid
352: * value.
353: *
354: * Invoking pageUp() will cause start, spin, and stop events to be
355: * triggered.
356: *
357: * * pages Type: Number Number of pages to increment, defaults to 1.
358: * @param $pages
359: */
360: public function PageUp($pages = null) {
361: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "pageUp", $pages, QJsPriority::Low);
362: }
363: /**
364: * Decrements the value by the specified number of steps. Without the
365: * parameter, a single step is decremented.
366: *
367: * If the resulting value is above the max, below the min, or results in
368: * a step mismatch, the value will be adjusted to the closest valid
369: * value.
370: *
371: * Invoking stepDown() will cause start, spin, and stop events to be
372: * triggered.
373: *
374: * * steps Type: Number Number of steps to decrement, defaults to 1.
375: * @param $steps
376: */
377: public function StepDown($steps = null) {
378: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "stepDown", $steps, QJsPriority::Low);
379: }
380: /**
381: * Increments the value by the specified number of steps. Without the
382: * parameter, a single step is incremented.
383: *
384: * If the resulting value is above the max, below the min, or results in
385: * a step mismatch, the value will be adjusted to the closest valid
386: * value.
387: *
388: * Invoking stepUp() will cause start, spin, and stop events to be
389: * triggered.
390: *
391: * * steps Type: Number Number of steps to increment, defaults to 1.
392: * @param $steps
393: */
394: public function StepUp($steps = null) {
395: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "stepUp", $steps, QJsPriority::Low);
396: }
397: /**
398: * Gets the current value as a number. The value is parsed based on the
399: * numberFormat and culture options.
400: *
401: * * This signature does not accept any arguments.
402: */
403: public function Value() {
404: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "value", QJsPriority::Low);
405: }
406: /**
407: * * value Type: Number or String The value to set. If passed as a
408: * string, the value is parsed based on the numberFormat and culture
409: * options.
410: * @param $value
411: */
412: public function Value1($value) {
413: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "value", $value, QJsPriority::Low);
414: }
415:
416:
417: public function __get($strName) {
418: switch ($strName) {
419: case 'Culture': return $this->strCulture;
420: case 'Disabled': return $this->blnDisabled;
421: case 'Icons': return $this->mixIcons;
422: case 'Incremental': return $this->mixIncremental;
423: case 'Max': return $this->mixMax;
424: case 'Min': return $this->mixMin;
425: case 'NumberFormat': return $this->strNumberFormat;
426: case 'Page': return $this->intPage;
427: case 'Step': return $this->mixStep;
428: default:
429: try {
430: return parent::__get($strName);
431: } catch (QCallerException $objExc) {
432: $objExc->IncrementOffset();
433: throw $objExc;
434: }
435: }
436: }
437:
438: public function __set($strName, $mixValue) {
439: switch ($strName) {
440: case 'Culture':
441: try {
442: $this->strCulture = QType::Cast($mixValue, QType::String);
443: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'culture', $this->strCulture);
444: break;
445: } catch (QInvalidCastException $objExc) {
446: $objExc->IncrementOffset();
447: throw $objExc;
448: }
449:
450: case 'Disabled':
451: try {
452: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
453: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
454: break;
455: } catch (QInvalidCastException $objExc) {
456: $objExc->IncrementOffset();
457: throw $objExc;
458: }
459:
460: case 'Icons':
461: $this->mixIcons = $mixValue;
462: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'icons', $mixValue);
463: break;
464:
465: case 'Incremental':
466: $this->mixIncremental = $mixValue;
467: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'incremental', $mixValue);
468: break;
469:
470: case 'Max':
471: $this->mixMax = $mixValue;
472: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'max', $mixValue);
473: break;
474:
475: case 'Min':
476: $this->mixMin = $mixValue;
477: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'min', $mixValue);
478: break;
479:
480: case 'NumberFormat':
481: try {
482: $this->strNumberFormat = QType::Cast($mixValue, QType::String);
483: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'numberFormat', $this->strNumberFormat);
484: break;
485: } catch (QInvalidCastException $objExc) {
486: $objExc->IncrementOffset();
487: throw $objExc;
488: }
489:
490: case 'Page':
491: try {
492: $this->intPage = QType::Cast($mixValue, QType::Integer);
493: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'page', $this->intPage);
494: break;
495: } catch (QInvalidCastException $objExc) {
496: $objExc->IncrementOffset();
497: throw $objExc;
498: }
499:
500: case 'Step':
501: $this->mixStep = $mixValue;
502: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'step', $mixValue);
503: break;
504:
505:
506: case 'Enabled':
507: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
508: parent::__set($strName, $mixValue);
509: break;
510:
511: default:
512: try {
513: parent::__set($strName, $mixValue);
514: break;
515: } catch (QCallerException $objExc) {
516: $objExc->IncrementOffset();
517: throw $objExc;
518: }
519: }
520: }
521:
522: /**
523: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
524: * used by the ModelConnector designer dialog to display a list of options for the control.
525: * @return QModelConnectorParam[]
526: **/
527: public static function GetModelConnectorParams() {
528: return array_merge(parent::GetModelConnectorParams(), array(
529: new QModelConnectorParam (get_called_class(), 'Culture', 'Sets the culture to use for parsing and formatting the value. If null,the currently set culture in Globalize is used, see Globalize docs foravailable cultures. Only relevant if the numberFormat option is set.Requires Globalize to be included.', QType::String),
530: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the spinner if set to true.', QType::Boolean),
531: new QModelConnectorParam (get_called_class(), 'NumberFormat', 'Format of numbers passed to Globalize, if available. Most common are\"n\" for a decimal number and \"C\" for a currency value. Also see theculture option.', QType::String),
532: new QModelConnectorParam (get_called_class(), 'Page', 'The number of steps to take when paging via the pageUp/pageDownmethods.', QType::Integer),
533: ));
534: }
535: }