1: <?php   
  2:     /**
  3:      * Triggered after the user slides a handle, if the value has changed; or
  4:      * if the value is changed programmatically via the value method.
  5:      * 
  6:      *  * event Type: Event 
  7:      * 
  8:      *  * ui Type: Object 
  9:      * 
 10:      *  * handle Type: jQuery The jQuery object representing the handle that
 11:      * was changed.
 12:      *  * value Type: Number The current value of the slider.
 13:      * 
 14:      */
 15:     class QSlider_ChangeEvent extends QJqUiEvent {
 16:         const EventName = 'slidechange';
 17:     }
 18:     /**
 19:      * Triggered when the slider is created.
 20:      * 
 21:      *  * event Type: Event 
 22:      *  * ui Type: Object 
 23:      * 
 24:      * _Note: The ui object is empty but included for consistency with other
 25:      * events._  */
 26:     class QSlider_CreateEvent extends QJqUiEvent {
 27:         const EventName = 'slidecreate';
 28:     }
 29:     /**
 30:      * Triggered on every mouse move during slide. The value provided in the
 31:      * event as ui.value represents the value that the handle will have as a
 32:      * result of the current movement. Canceling the event will prevent the
 33:      * handle from moving and the handle will continue to have its previous
 34:      * value.
 35:      * 
 36:      *  * event Type: Event 
 37:      * 
 38:      *  * ui Type: Object 
 39:      * 
 40:      *  * handle Type: jQuery The jQuery object representing the handle being
 41:      * moved.
 42:      *  * value Type: Number The value that the handle will move to if the
 43:      * event is not canceled.
 44:      *  * values Type: Array An array of the current values of a
 45:      * multi-handled slider.
 46:      * 
 47:      */
 48:     class QSlider_SlideEvent extends QJqUiEvent {
 49:         const EventName = 'slide';
 50:     }
 51:     /**
 52:      * Triggered when the user starts sliding.
 53:      * 
 54:      *  * event Type: Event 
 55:      * 
 56:      *  * ui Type: Object 
 57:      * 
 58:      *  * handle Type: jQuery The jQuery object representing the handle being
 59:      * moved.
 60:      *  * value Type: Number The current value of the slider.
 61:      * 
 62:      */
 63:     class QSlider_StartEvent extends QJqUiEvent {
 64:         const EventName = 'slidestart';
 65:     }
 66:     /**
 67:      * Triggered after the user slides a handle.
 68:      * 
 69:      *  * event Type: Event 
 70:      * 
 71:      *  * ui Type: Object 
 72:      * 
 73:      *  * handle Type: jQuery The jQuery object representing the handle that
 74:      * was moved.
 75:      *  * value Type: Number The current value of the slider.
 76:      * 
 77:      */
 78:     class QSlider_StopEvent extends QJqUiEvent {
 79:         const EventName = 'slidestop';
 80:     }
 81: 
 82:     /* Custom "property" event classes for this control */
 83: 
 84:     /**
 85:      * Generated QSliderGen class.
 86:      * 
 87:      * This is the QSliderGen class which is automatically generated
 88:      * by scraping the JQuery UI documentation website. As such, it includes all the options
 89:      * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
 90:      * the QSliderBase class for any glue code to make this class more
 91:      * usable in QCubed.
 92:      * 
 93:      * @see QSliderBase
 94:      * @package Controls\Base
 95:      * @property mixed $Animate
 96:      * Whether to slide the handle smoothly when the user clicks on the
 97:      * slider track. Also accepts any valid animation duration.Multiple types
 98:      * supported:
 99:      * 
100:      *  * Boolean: When set to true, the handle will animate with the default
101:      * duration.
102:      *  * String: The name of a speed, such as "fast" or "slow".
103:      *  * Number: The duration of the animation, in milliseconds.
104:      * 
105: 
106:      *
107:      * @property boolean $Disabled
108:      * Disables the slider if set to true.
109:      *
110:      * @property integer $Max
111:      * The maximum value of the slider.
112:      *
113:      * @property integer $Min
114:      * The minimum value of the slider.
115:      *
116:      * @property string $Orientation
117:      * Determines whether the slider handles move horizontally (min on left,
118:      * max on right) or vertically (min on bottom, max on top). Possible
119:      * values: "horizontal", "vertical".
120:      *
121:      * @property mixed $Range
122:      * Whether the slider represents a range.Multiple types supported:
123:      * 
124:      *  * Boolean: If set to true, the slider will detect if you have two
125:      * handles and create a styleable range element between these two.
126:      *  * String: Either "min" or "max". A min range goes from the slider
127:      * min to one handle. A max range goes from one handle to the slider max.
128:      * 
129: 
130:      *
131:      * @property integer $Step
132:      * Determines the size or amount of each interval or step the slider
133:      * takes between the min and max. The full specified value range of the
134:      * slider (max - min) should be evenly divisible by the step.
135:      *
136:      * @property integer $Value
137:      * Determines the value of the slider, if theres only one handle. If
138:      * there is more than one handle, determines the value of the first
139:      * handle.
140:      *
141:      * @property array $Values
142:      * This option can be used to specify multiple handles. If the range
143:      * option is set to true, the length of values should be 2.
144:      *
145:      */
146: 
147:     class QSliderGen extends QPanel {
148:         protected $strJavaScripts = __JQUERY_EFFECTS__;
149:         protected $strStyleSheets = __JQUERY_CSS__;
150:         /** @var mixed */
151:         protected $mixAnimate = null;
152:         /** @var boolean */
153:         protected $blnDisabled = null;
154:         /** @var integer */
155:         protected $intMax = null;
156:         /** @var integer */
157:         protected $intMin;
158:         /** @var string */
159:         protected $strOrientation = null;
160:         /** @var mixed */
161:         protected $mixRange = null;
162:         /** @var integer */
163:         protected $intStep = null;
164:         /** @var integer */
165:         protected $intValue;
166:         /** @var array */
167:         protected $arrValues = null;
168: 
169:         /**
170:          * Builds the option array to be sent to the widget constructor.
171:          *
172:          * @return array key=>value array of options
173:          */
174:         protected function MakeJqOptions() {
175:             $jqOptions = null;
176:             if (!is_null($val = $this->Animate)) {$jqOptions['animate'] = $val;}
177:             if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
178:             if (!is_null($val = $this->Max)) {$jqOptions['max'] = $val;}
179:             if (!is_null($val = $this->Min)) {$jqOptions['min'] = $val;}
180:             if (!is_null($val = $this->Orientation)) {$jqOptions['orientation'] = $val;}
181:             if (!is_null($val = $this->Range)) {$jqOptions['range'] = $val;}
182:             if (!is_null($val = $this->Step)) {$jqOptions['step'] = $val;}
183:             if (!is_null($val = $this->Value)) {$jqOptions['value'] = $val;}
184:             if (!is_null($val = $this->Values)) {$jqOptions['values'] = $val;}
185:             return $jqOptions;
186:         }
187: 
188:         /**
189:          * Return the JavaScript function to call to associate the widget with the control.
190:          *
191:          * @return string
192:          */
193:         public function GetJqSetupFunction() {
194:             return 'slider';
195:         }
196: 
197:         /**
198:          * Returns the script that attaches the JQueryUI widget to the html object.
199:          *
200:          * @return string
201:          */
202:         public function GetEndScript() {
203:             $strId = $this->GetJqControlId();
204:             $jqOptions = $this->makeJqOptions();
205:             $strFunc = $this->getJqSetupFunction();
206: 
207:             if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
208:                 // If events are not attached to the actual object being drawn, then the old events will not get
209:                 // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
210:                 QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
211:             }
212: 
213:             // Attach the javascript widget to the html object
214:             if (empty($jqOptions)) {
215:                 QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
216:             } else {
217:                 QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
218:             }
219: 
220:             return parent::GetEndScript();
221:         }
222: 
223:         /**
224:          * Removes the slider functionality completely. This will return the
225:          * element back to its pre-init state.
226:          * 
227:          *  * This method does not accept any arguments.
228:          */
229:         public function Destroy() {
230:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
231:         }
232:         /**
233:          * Disables the slider.
234:          * 
235:          *  * This method does not accept any arguments.
236:          */
237:         public function Disable() {
238:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
239:         }
240:         /**
241:          * Enables the slider.
242:          * 
243:          *  * This method does not accept any arguments.
244:          */
245:         public function Enable() {
246:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
247:         }
248:         /**
249:          * Retrieves the sliders instance object. If the element does not have an
250:          * associated instance, undefined is returned. 
251:          * 
252:          * Unlike other widget methods, instance() is safe to call on any element
253:          * after the slider plugin has loaded.
254:          * 
255:          *  * This method does not accept any arguments.
256:          */
257:         public function Instance() {
258:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
259:         }
260:         /**
261:          * Gets the value currently associated with the specified optionName. 
262:          * 
263:          * Note: For options that have objects as their value, you can get the
264:          * value of a specific key by using dot notation. For example, "foo.bar"
265:          * would get the value of the bar property on the foo option.
266:          * 
267:          *  * optionName Type: String The name of the option to get.
268:          * @param $optionName
269:          */
270:         public function Option($optionName) {
271:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
272:         }
273:         /**
274:          * Gets an object containing key/value pairs representing the current
275:          * slider options hash.
276:          * 
277:          *  * This signature does not accept any arguments.
278:          */
279:         public function Option1() {
280:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
281:         }
282:         /**
283:          * Sets the value of the slider option associated with the specified
284:          * optionName. 
285:          * 
286:          * Note: For options that have objects as their value, you can set the
287:          * value of just one property by using dot notation for optionName. For
288:          * example, "foo.bar" would update only the bar property of the foo
289:          * option.
290:          * 
291:          *  * optionName Type: String The name of the option to set.
292:          *  * value Type: Object A value to set for the option.
293:          * @param $optionName
294:          * @param $value
295:          */
296:         public function Option2($optionName, $value) {
297:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
298:         }
299:         /**
300:          * Sets one or more options for the slider.
301:          * 
302:          *  * options Type: Object A map of option-value pairs to set.
303:          * @param $options
304:          */
305:         public function Option3($options) {
306:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
307:         }
308:         /**
309:          * Get the value of the slider.
310:          * 
311:          *  * This signature does not accept any arguments.
312:          */
313:         public function Value() {
314:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "value", QJsPriority::Low);
315:         }
316:         /**
317:          * Set the value of the slider.
318:          * 
319:          *  * value Type: Number The value to set.
320:          * @param $value
321:          */
322:         public function Value1($value) {
323:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "value", $value, QJsPriority::Low);
324:         }
325:         /**
326:          * Get the value for all handles.
327:          * 
328:          *  * This signature does not accept any arguments.
329:          */
330:         public function Values() {
331:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "values", QJsPriority::Low);
332:         }
333:         /**
334:          * Get the value for the specified handle.
335:          * 
336:          *  * index Type: Integer The zero-based index of the handle.
337:          * @param $index
338:          */
339:         public function Values1($index) {
340:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "values", $index, QJsPriority::Low);
341:         }
342:         /**
343:          * Set the value for the specified handle.
344:          * 
345:          *  * index Type: Integer The zero-based index of the handle.
346:          *  * value Type: Number The value to set.
347:          * @param $index
348:          * @param $value
349:          */
350:         public function Values2($index, $value) {
351:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "values", $index, $value, QJsPriority::Low);
352:         }
353:         /**
354:          * Set the value for all handles.
355:          * 
356:          *  * values Type: Array The values to set.
357:          * @param $values
358:          */
359:         public function Values3($values) {
360:             QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "values", $values, QJsPriority::Low);
361:         }
362: 
363: 
364:         public function __get($strName) {
365:             switch ($strName) {
366:                 case 'Animate': return $this->mixAnimate;
367:                 case 'Disabled': return $this->blnDisabled;
368:                 case 'Max': return $this->intMax;
369:                 case 'Min': return $this->intMin;
370:                 case 'Orientation': return $this->strOrientation;
371:                 case 'Range': return $this->mixRange;
372:                 case 'Step': return $this->intStep;
373:                 case 'Value': return $this->intValue;
374:                 case 'Values': return $this->arrValues;
375:                 default: 
376:                     try { 
377:                         return parent::__get($strName); 
378:                     } catch (QCallerException $objExc) { 
379:                         $objExc->IncrementOffset(); 
380:                         throw $objExc; 
381:                     }
382:             }
383:         }
384: 
385:         public function __set($strName, $mixValue) {
386:             switch ($strName) {
387:                 case 'Animate':
388:                     $this->mixAnimate = $mixValue;
389:                     $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'animate', $mixValue);
390:                     break;
391: 
392:                 case 'Disabled':
393:                     try {
394:                         $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
395:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
396:                         break;
397:                     } catch (QInvalidCastException $objExc) {
398:                         $objExc->IncrementOffset();
399:                         throw $objExc;
400:                     }
401: 
402:                 case 'Max':
403:                     try {
404:                         $this->intMax = QType::Cast($mixValue, QType::Integer);
405:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'max', $this->intMax);
406:                         break;
407:                     } catch (QInvalidCastException $objExc) {
408:                         $objExc->IncrementOffset();
409:                         throw $objExc;
410:                     }
411: 
412:                 case 'Min':
413:                     try {
414:                         $this->intMin = QType::Cast($mixValue, QType::Integer);
415:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'min', $this->intMin);
416:                         break;
417:                     } catch (QInvalidCastException $objExc) {
418:                         $objExc->IncrementOffset();
419:                         throw $objExc;
420:                     }
421: 
422:                 case 'Orientation':
423:                     try {
424:                         $this->strOrientation = QType::Cast($mixValue, QType::String);
425:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'orientation', $this->strOrientation);
426:                         break;
427:                     } catch (QInvalidCastException $objExc) {
428:                         $objExc->IncrementOffset();
429:                         throw $objExc;
430:                     }
431: 
432:                 case 'Range':
433:                     $this->mixRange = $mixValue;
434:                     $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'range', $mixValue);
435:                     break;
436: 
437:                 case 'Step':
438:                     try {
439:                         $this->intStep = QType::Cast($mixValue, QType::Integer);
440:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'step', $this->intStep);
441:                         break;
442:                     } catch (QInvalidCastException $objExc) {
443:                         $objExc->IncrementOffset();
444:                         throw $objExc;
445:                     }
446: 
447:                 case 'Value':
448:                     try {
449:                         $this->intValue = QType::Cast($mixValue, QType::Integer);
450:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'value', $this->intValue);
451:                         break;
452:                     } catch (QInvalidCastException $objExc) {
453:                         $objExc->IncrementOffset();
454:                         throw $objExc;
455:                     }
456: 
457:                 case 'Values':
458:                     try {
459:                         $this->arrValues = QType::Cast($mixValue, QType::ArrayType);
460:                         $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'values', $this->arrValues);
461:                         break;
462:                     } catch (QInvalidCastException $objExc) {
463:                         $objExc->IncrementOffset();
464:                         throw $objExc;
465:                     }
466: 
467: 
468:                 case 'Enabled':
469:                     $this->Disabled = !$mixValue;   // Tie in standard QCubed functionality
470:                     parent::__set($strName, $mixValue);
471:                     break;
472:                     
473:                 default:
474:                     try {
475:                         parent::__set($strName, $mixValue);
476:                         break;
477:                     } catch (QCallerException $objExc) {
478:                         $objExc->IncrementOffset();
479:                         throw $objExc;
480:                     }
481:             }
482:         }
483: 
484:         /**
485:         * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
486:         * used by the ModelConnector designer dialog to display a list of options for the control.
487:         * @return QModelConnectorParam[]
488:         **/
489:         public static function GetModelConnectorParams() {
490:             return array_merge(parent::GetModelConnectorParams(), array(
491:                 new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the slider if set to true.', QType::Boolean),
492:                 new QModelConnectorParam (get_called_class(), 'Max', 'The maximum value of the slider.', QType::Integer),
493:                 new QModelConnectorParam (get_called_class(), 'Min', 'The minimum value of the slider.', QType::Integer),
494:                 new QModelConnectorParam (get_called_class(), 'Orientation', 'Determines whether the slider handles move horizontally (min on left,max on right) or vertically (min on bottom, max on top). Possiblevalues: \"horizontal\", \"vertical\".', QType::String),
495:                 new QModelConnectorParam (get_called_class(), 'Step', 'Determines the size or amount of each interval or step the slidertakes between the min and max. The full specified value range of theslider (max - min) should be evenly divisible by the step.', QType::Integer),
496:                 new QModelConnectorParam (get_called_class(), 'Value', 'Determines the value of the slider, if theres only one handle. Ifthere is more than one handle, determines the value of the firsthandle.', QType::Integer),
497:                 new QModelConnectorParam (get_called_class(), 'Values', 'This option can be used to specify multiple handles. If the rangeoption is set to true, the length of values should be 2.', QType::ArrayType),
498:             ));
499:         }
500:     }