1: <?php
2: /**
3: * Triggered after a tab has been activated (after animation completes).
4: * If the tabs were previously collapsed, ui.oldTab and ui.oldPanel will
5: * be empty jQuery objects. If the tabs are collapsing, ui.newTab and
6: * ui.newPanel will be empty jQuery objects. Note: Since the activate
7: * event is only fired on tab activation, it is not fired for the initial
8: * tab when the tabs widget is created. If you need a hook for widget
9: * creation use the create event.
10: *
11: * * event Type: Event
12: *
13: * * ui Type: Object
14: *
15: * * newTab Type: jQuery The tab that was just activated.
16: * * oldTab Type: jQuery The tab that was just deactivated.
17: * * newPanel Type: jQuery The panel that was just activated.
18: * * oldPanel Type: jQuery The panel that was just deactivated.
19: *
20: */
21: class QTabs_ActivateEvent extends QJqUiEvent {
22: const EventName = 'tabsactivate';
23: }
24: /**
25: * Triggered immediately before a tab is activated. Can be canceled to
26: * prevent the tab from activating. If the tabs are currently collapsed,
27: * ui.oldTab and ui.oldPanel will be empty jQuery objects. If the tabs
28: * are collapsing, ui.newTab and ui.newPanel will be empty jQuery
29: * objects.
30: *
31: * * event Type: Event
32: *
33: * * ui Type: Object
34: *
35: * * newTab Type: jQuery The tab that is about to be activated.
36: * * oldTab Type: jQuery The tab that is about to be deactivated.
37: * * newPanel Type: jQuery The panel that is about to be activated.
38: * * oldPanel Type: jQuery The panel that is about to be deactivated.
39: *
40: */
41: class QTabs_BeforeActivateEvent extends QJqUiEvent {
42: const EventName = 'tabsbeforeactivate';
43: }
44: /**
45: * Triggered when a remote tab is about to be loaded, after the
46: * beforeActivate event. Can be canceled to prevent the tab panel from
47: * loading content; though the panel will still be activated. This event
48: * is triggered just before the Ajax request is made, so modifications
49: * can be made to ui.jqXHR and ui.ajaxSettings.
50: *
51: * _Note: Although ui.ajaxSettings is provided and can be modified, some
52: * of these properties have already been processed by jQuery. For
53: * example, prefilters have been applied, data has been processed, and
54: * type has been determined. The beforeLoad event occurs at the same
55: * time, and therefore has the same restrictions, as the beforeSend
56: * callback from jQuery.ajax()._
57: *
58: * * event Type: Event
59: *
60: * * ui Type: Object
61: *
62: * * tab Type: jQuery The tab that is being loaded.
63: * * panel Type: jQuery The panel which will be populated by the Ajax
64: * response.
65: * * jqXHR Type: jqXHR The jqXHR object that is requesting the content.
66: * * ajaxSettings Type: Object The properties that will be used by
67: * jQuery.ajax to request the content.
68: *
69: */
70: class QTabs_BeforeLoadEvent extends QJqUiEvent {
71: const EventName = 'tabsbeforeload';
72: }
73: /**
74: * Triggered when the tabs are created. If the tabs are collapsed, ui.tab
75: * and ui.panel will be empty jQuery objects.
76: *
77: * * event Type: Event
78: *
79: * * ui Type: Object
80: *
81: * * tab Type: jQuery The active tab.
82: * * panel Type: jQuery The active panel.
83: *
84: */
85: class QTabs_CreateEvent extends QJqUiEvent {
86: const EventName = 'tabscreate';
87: }
88: /**
89: * Triggered after a remote tab has been loaded.
90: *
91: * * event Type: Event
92: *
93: * * ui Type: Object
94: *
95: * * tab Type: jQuery The tab that was just loaded.
96: * * panel Type: jQuery The panel which was just populated by the Ajax
97: * response.
98: *
99: */
100: class QTabs_LoadEvent extends QJqUiEvent {
101: const EventName = 'tabsload';
102: }
103:
104: /* Custom "property" event classes for this control */
105:
106: /**
107: * Generated QTabsGen class.
108: *
109: * This is the QTabsGen class which is automatically generated
110: * by scraping the JQuery UI documentation website. As such, it includes all the options
111: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
112: * the QTabsBase class for any glue code to make this class more
113: * usable in QCubed.
114: *
115: * @see QTabsBase
116: * @package Controls\Base
117: * @property mixed $Active
118: * Which panel is currently open.Multiple types supported:
119: *
120: * * Boolean: Setting active to false will collapse all panels. This
121: * requires the collapsible option to be true.
122: * * Integer: The zero-based index of the panel that is active (open).
123: * A negative value selects panels going backward from the last panel.
124: *
125:
126: *
127: * @property boolean $Collapsible
128: * When set to true, the active panel can be closed.
129: *
130: * @property mixed $Disabled
131: * Which tabs are disabled.Multiple types supported:
132: *
133: * * Boolean: Enable or disable all tabs.
134: * * Array: An array containing the zero-based indexes of the tabs that
135: * should be disabled, e.g., [ 0, 2 ] would disable the first and third
136: * tab.
137: *
138:
139: *
140: * @property string $Event
141: * The type of event that the tabs should react to in order to activate
142: * the tab. To activate on hover, use "mouseover".
143: *
144: * @property string $HeightStyle
145: * Controls the height of the tabs widget and each panel. Possible
146: * values:
147: *
148: * * "auto": All panels will be set to the height of the tallest panel.
149: * * "fill": Expand to the available height based on the tabs parent
150: * height.
151: * * "content": Each panel will be only as tall as its content.
152: *
153:
154: *
155: * @property mixed $Hide
156: * If and how to animate the hiding of the panel.Multiple types
157: * supported:
158: *
159: * * Boolean: When set to false, no animation will be used and the panel
160: * will be hidden immediately. When set to true, the panel will fade out
161: * with the default duration and the default easing.
162: * * Number: The panel will fade out with the specified duration and
163: * the default easing.
164: * * String: The panel will be hidden using the specified effect. The
165: * value can either be the name of a built-in jQuery animation method,
166: * such as "slideUp", or the name of a jQuery UI effect, such as "fold".
167: * In either case the effect will be used with the default duration and
168: * the default easing.
169: * * Object: If the value is an object, then effect, delay, duration,
170: * and easing properties may be provided. If the effect property contains
171: * the name of a jQuery method, then that method will be used; otherwise
172: * it is assumed to be the name of a jQuery UI effect. When using a
173: * jQuery UI effect that supports additional settings, you may include
174: * those settings in the object and they will be passed to the effect. If
175: * duration or easing is omitted, then the default values will be used.
176: * If effect is omitted, then "fadeOut" will be used. If delay is
177: * omitted, then no delay is used.
178: *
179:
180: *
181: * @property mixed $Show
182: * If and how to animate the showing of the panel.Multiple types
183: * supported:
184: *
185: * * Boolean: When set to false, no animation will be used and the panel
186: * will be shown immediately. When set to true, the panel will fade in
187: * with the default duration and the default easing.
188: * * Number: The panel will fade in with the specified duration and the
189: * default easing.
190: * * String: The panel will be shown using the specified effect. The
191: * value can either be the name of a built-in jQuery animation method,
192: * such as "slideDown", or the name of a jQuery UI effect, such as
193: * "fold". In either case the effect will be used with the default
194: * duration and the default easing.
195: * * Object: If the value is an object, then effect, delay, duration,
196: * and easing properties may be provided. If the effect property contains
197: * the name of a jQuery method, then that method will be used; otherwise
198: * it is assumed to be the name of a jQuery UI effect. When using a
199: * jQuery UI effect that supports additional settings, you may include
200: * those settings in the object and they will be passed to the effect. If
201: * duration or easing is omitted, then the default values will be used.
202: * If effect is omitted, then "fadeIn" will be used. If delay is omitted,
203: * then no delay is used.
204: *
205:
206: *
207: */
208:
209: class QTabsGen extends QPanel {
210: protected $strJavaScripts = __JQUERY_EFFECTS__;
211: protected $strStyleSheets = __JQUERY_CSS__;
212: /** @var mixed */
213: protected $mixActive;
214: /** @var boolean */
215: protected $blnCollapsible = null;
216: /** @var mixed */
217: protected $mixDisabled = null;
218: /** @var string */
219: protected $strEvent = null;
220: /** @var string */
221: protected $strHeightStyle = null;
222: /** @var mixed */
223: protected $mixHide = null;
224: /** @var mixed */
225: protected $mixShow = null;
226:
227: /**
228: * Builds the option array to be sent to the widget constructor.
229: *
230: * @return array key=>value array of options
231: */
232: protected function MakeJqOptions() {
233: $jqOptions = null;
234: if (!is_null($val = $this->Active)) {$jqOptions['active'] = $val;}
235: if (!is_null($val = $this->Collapsible)) {$jqOptions['collapsible'] = $val;}
236: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
237: if (!is_null($val = $this->Event)) {$jqOptions['event'] = $val;}
238: if (!is_null($val = $this->HeightStyle)) {$jqOptions['heightStyle'] = $val;}
239: if (!is_null($val = $this->Hide)) {$jqOptions['hide'] = $val;}
240: if (!is_null($val = $this->Show)) {$jqOptions['show'] = $val;}
241: return $jqOptions;
242: }
243:
244: /**
245: * Return the JavaScript function to call to associate the widget with the control.
246: *
247: * @return string
248: */
249: public function GetJqSetupFunction() {
250: return 'tabs';
251: }
252:
253: /**
254: * Returns the script that attaches the JQueryUI widget to the html object.
255: *
256: * @return string
257: */
258: public function GetEndScript() {
259: $strId = $this->GetJqControlId();
260: $jqOptions = $this->makeJqOptions();
261: $strFunc = $this->getJqSetupFunction();
262:
263: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
264: // If events are not attached to the actual object being drawn, then the old events will not get
265: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
266: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
267: }
268:
269: // Attach the javascript widget to the html object
270: if (empty($jqOptions)) {
271: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
272: } else {
273: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
274: }
275:
276: return parent::GetEndScript();
277: }
278:
279: /**
280: * Removes the tabs functionality completely. This will return the
281: * element back to its pre-init state.
282: *
283: * * This method does not accept any arguments.
284: */
285: public function Destroy() {
286: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
287: }
288: /**
289: * Disables all tabs.
290: *
291: * * This signature does not accept any arguments.
292: */
293: public function Disable() {
294: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
295: }
296: /**
297: * Disables a tab. The selected tab cannot be disabled. To disable more
298: * than one tab at once, set the disabled option: $( "#tabs" ).tabs(
299: * "option", "disabled", [ 1, 2, 3 ] ).
300: *
301: * * index Type: Number The zero-based index of the tab to disable.
302: * @param $index
303: */
304: public function Disable1($index) {
305: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", $index, QJsPriority::Low);
306: }
307: /**
308: * Disables a tab. The selected tab cannot be disabled.
309: *
310: * * href Type: String The href of the tab to disable.
311: * @param $href
312: */
313: public function Disable2($href) {
314: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", $href, QJsPriority::Low);
315: }
316: /**
317: * Enables all tabs.
318: *
319: * * This signature does not accept any arguments.
320: */
321: public function Enable() {
322: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
323: }
324: /**
325: * Enables a tab. To enable more than one tab at once reset the disabled
326: * property like: $( "#example" ).tabs( "option", "disabled", [] );.
327: *
328: * * index Type: Number The zero-based index of the tab to enable.
329: * @param $index
330: */
331: public function Enable1($index) {
332: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", $index, QJsPriority::Low);
333: }
334: /**
335: * Enables a tab.
336: *
337: * * href Type: String The href of the tab to enable.
338: * @param $href
339: */
340: public function Enable2($href) {
341: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", $href, QJsPriority::Low);
342: }
343: /**
344: * Retrieves the tabss instance object. If the element does not have an
345: * associated instance, undefined is returned.
346: *
347: * Unlike other widget methods, instance() is safe to call on any element
348: * after the tabs plugin has loaded.
349: *
350: * * This method does not accept any arguments.
351: */
352: public function Instance() {
353: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
354: }
355: /**
356: * Loads the panel content of a remote tab.
357: *
358: * * index Type: Number The zero-based index of the tab to load.
359: * @param $index
360: */
361: public function Load($index) {
362: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "load", $index, QJsPriority::Low);
363: }
364: /**
365: * Loads the panel content of a remote tab.
366: *
367: * * href Type: String The href of the tab to load.
368: * @param $href
369: */
370: public function Load1($href) {
371: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "load", $href, QJsPriority::Low);
372: }
373: /**
374: * Gets the value currently associated with the specified optionName.
375: *
376: * Note: For options that have objects as their value, you can get the
377: * value of a specific key by using dot notation. For example, "foo.bar"
378: * would get the value of the bar property on the foo option.
379: *
380: * * optionName Type: String The name of the option to get.
381: * @param $optionName
382: */
383: public function Option($optionName) {
384: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
385: }
386: /**
387: * Gets an object containing key/value pairs representing the current
388: * tabs options hash.
389: *
390: * * This signature does not accept any arguments.
391: */
392: public function Option1() {
393: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
394: }
395: /**
396: * Sets the value of the tabs option associated with the specified
397: * optionName.
398: *
399: * Note: For options that have objects as their value, you can set the
400: * value of just one property by using dot notation for optionName. For
401: * example, "foo.bar" would update only the bar property of the foo
402: * option.
403: *
404: * * optionName Type: String The name of the option to set.
405: * * value Type: Object A value to set for the option.
406: * @param $optionName
407: * @param $value
408: */
409: public function Option2($optionName, $value) {
410: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
411: }
412: /**
413: * Sets one or more options for the tabs.
414: *
415: * * options Type: Object A map of option-value pairs to set.
416: * @param $options
417: */
418: public function Option3($options) {
419: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
420: }
421: /**
422: * Process any tabs that were added or removed directly in the DOM and
423: * recompute the height of the tab panels. Results depend on the content
424: * and the heightStyle option.
425: *
426: * * This method does not accept any arguments.
427: */
428: public function Refresh() {
429: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
430: }
431:
432:
433: public function __get($strName) {
434: switch ($strName) {
435: case 'Active': return $this->mixActive;
436: case 'Collapsible': return $this->blnCollapsible;
437: case 'Disabled': return $this->mixDisabled;
438: case 'Event': return $this->strEvent;
439: case 'HeightStyle': return $this->strHeightStyle;
440: case 'Hide': return $this->mixHide;
441: case 'Show': return $this->mixShow;
442: default:
443: try {
444: return parent::__get($strName);
445: } catch (QCallerException $objExc) {
446: $objExc->IncrementOffset();
447: throw $objExc;
448: }
449: }
450: }
451:
452: public function __set($strName, $mixValue) {
453: switch ($strName) {
454: case 'Active':
455: $this->mixActive = $mixValue;
456: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'active', $mixValue);
457: break;
458:
459: case 'Collapsible':
460: try {
461: $this->blnCollapsible = QType::Cast($mixValue, QType::Boolean);
462: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'collapsible', $this->blnCollapsible);
463: break;
464: } catch (QInvalidCastException $objExc) {
465: $objExc->IncrementOffset();
466: throw $objExc;
467: }
468:
469: case 'Disabled':
470: $this->mixDisabled = $mixValue;
471: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $mixValue);
472: break;
473:
474: case 'Event':
475: try {
476: $this->strEvent = QType::Cast($mixValue, QType::String);
477: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'event', $this->strEvent);
478: break;
479: } catch (QInvalidCastException $objExc) {
480: $objExc->IncrementOffset();
481: throw $objExc;
482: }
483:
484: case 'HeightStyle':
485: try {
486: $this->strHeightStyle = QType::Cast($mixValue, QType::String);
487: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'heightStyle', $this->strHeightStyle);
488: break;
489: } catch (QInvalidCastException $objExc) {
490: $objExc->IncrementOffset();
491: throw $objExc;
492: }
493:
494: case 'Hide':
495: $this->mixHide = $mixValue;
496: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'hide', $mixValue);
497: break;
498:
499: case 'Show':
500: $this->mixShow = $mixValue;
501: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'show', $mixValue);
502: break;
503:
504:
505: case 'Enabled':
506: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
507: parent::__set($strName, $mixValue);
508: break;
509:
510: default:
511: try {
512: parent::__set($strName, $mixValue);
513: break;
514: } catch (QCallerException $objExc) {
515: $objExc->IncrementOffset();
516: throw $objExc;
517: }
518: }
519: }
520:
521: /**
522: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
523: * used by the ModelConnector designer dialog to display a list of options for the control.
524: * @return QModelConnectorParam[]
525: **/
526: public static function GetModelConnectorParams() {
527: return array_merge(parent::GetModelConnectorParams(), array(
528: new QModelConnectorParam (get_called_class(), 'Collapsible', 'When set to true, the active panel can be closed.', QType::Boolean),
529: new QModelConnectorParam (get_called_class(), 'Event', 'The type of event that the tabs should react to in order to activatethe tab. To activate on hover, use \"mouseover\".', QType::String),
530: new QModelConnectorParam (get_called_class(), 'HeightStyle', 'Controls the height of the tabs widget and each panel. Possiblevalues: * \"auto\": All panels will be set to the height of the tallest panel. * \"fill\": Expand to the available height based on the tabs parentheight. * \"content\": Each panel will be only as tall as its content.', QType::String),
531: ));
532: }
533: }