1: <?php
2: /**
3: * Triggered after a panel has been activated (after animation
4: * completes). If the accordion was previously collapsed, ui.oldHeader
5: * and ui.oldPanel will be empty jQuery objects. If the accordion is
6: * collapsing, ui.newHeader and ui.newPanel will be empty jQuery objects.
7: * Note: Since the activate event is only fired on panel activation, it
8: * is not fired for the initial panel when the accordion widget is
9: * created. If you need a hook for widget creation use the create event.
10: *
11: * * event Type: Event
12: *
13: * * ui Type: Object
14: *
15: * * newHeader Type: jQuery The header that was just activated.
16: * * oldHeader Type: jQuery The header 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 QAccordion_ActivateEvent extends QJqUiEvent {
22: const EventName = 'accordionactivate';
23: }
24: /**
25: * Triggered directly before a panel is activated. Can be canceled to
26: * prevent the panel from activating. If the accordion is currently
27: * collapsed, ui.oldHeader and ui.oldPanel will be empty jQuery objects.
28: * If the accordion is collapsing, ui.newHeader and ui.newPanel will be
29: * empty jQuery objects.
30: *
31: * * event Type: Event
32: *
33: * * ui Type: Object
34: *
35: * * newHeader Type: jQuery The header that is about to be activated.
36: * * oldHeader Type: jQuery The header 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 QAccordion_BeforeActivateEvent extends QJqUiEvent {
42: const EventName = 'accordionbeforeactivate';
43: }
44: /**
45: * Triggered when the accordion is created. If the accordion is
46: * collapsed, ui.header and ui.panel will be empty jQuery objects.
47: *
48: * * event Type: Event
49: *
50: * * ui Type: Object
51: *
52: * * header Type: jQuery The active header.
53: * * panel Type: jQuery The active panel.
54: *
55: */
56: class QAccordion_CreateEvent extends QJqUiEvent {
57: const EventName = 'accordioncreate';
58: }
59:
60: /* Custom "property" event classes for this control */
61:
62: /**
63: * Generated QAccordionGen class.
64: *
65: * This is the QAccordionGen class which is automatically generated
66: * by scraping the JQuery UI documentation website. As such, it includes all the options
67: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
68: * the QAccordionBase class for any glue code to make this class more
69: * usable in QCubed.
70: *
71: * @see QAccordionBase
72: * @package Controls\Base
73: * @property mixed $Active
74: * Which panel is currently open.Multiple types supported:
75: *
76: * * Boolean: Setting active to false will collapse all panels. This
77: * requires the collapsible option to be true.
78: * * Integer: The zero-based index of the panel that is active (open).
79: * A negative value selects panels going backward from the last panel.
80: *
81:
82: *
83: * @property mixed $Animate
84: * If and how to animate changing panels.Multiple types supported:
85: *
86: * * Boolean: A value of false will disable animations.
87: * * Number: Duration in milliseconds with default easing.
88: * * String: Name of easing to use with default duration.
89: *
90: * * Object: An object containing easing and duration properties to
91: * configure animations.
92: *
93: * * Can also contain a down property with any of the above options.
94: * * "Down" animations occur when the panel being activated has a lower
95: * index than the currently active panel.
96: *
97:
98: *
99: * @property boolean $Collapsible
100: * Whether all the sections can be closed at once. Allows collapsing the
101: * active section.
102: *
103: * @property boolean $Disabled
104: * Disables the accordion if set to true.
105: *
106: * @property string $Event
107: * The event that accordion headers will react to in order to activate
108: * the associated panel. Multiple events can be specified, separated by a
109: * space.
110: *
111: * @property mixed $Header
112: * Selector for the header element, applied via .find() on the main
113: * accordion element. Content panels must be the sibling immediately
114: * after their associated headers.
115: *
116: * @property string $HeightStyle
117: * Controls the height of the accordion and each panel. Possible values:
118: *
119: * * "auto": All panels will be set to the height of the tallest panel.
120: * * "fill": Expand to the available height based on the accordions
121: * parent height.
122: * * "content": Each panel will be only as tall as its content.
123: *
124:
125: *
126: * @property mixed $Icons
127: * Icons to use for headers, matching an icon provided by the jQuery UI
128: * CSS Framework. Set to false to have no icons displayed.
129: *
130: * * header (string, default: "ui-icon-triangle-1-e")
131: * * activeHeader (string, default: "ui-icon-triangle-1-s")
132: *
133:
134: *
135: */
136:
137: class QAccordionGen extends QPanel {
138: protected $strJavaScripts = __JQUERY_EFFECTS__;
139: protected $strStyleSheets = __JQUERY_CSS__;
140: /** @var mixed */
141: protected $mixActive;
142: /** @var mixed */
143: protected $mixAnimate = null;
144: /** @var boolean */
145: protected $blnCollapsible = null;
146: /** @var boolean */
147: protected $blnDisabled = null;
148: /** @var string */
149: protected $strEvent = null;
150: /** @var mixed */
151: protected $mixHeader = null;
152: /** @var string */
153: protected $strHeightStyle = null;
154: /** @var mixed */
155: protected $mixIcons = null;
156:
157: /**
158: * Builds the option array to be sent to the widget constructor.
159: *
160: * @return array key=>value array of options
161: */
162: protected function MakeJqOptions() {
163: $jqOptions = null;
164: if (!is_null($val = $this->Active)) {$jqOptions['active'] = $val;}
165: if (!is_null($val = $this->Animate)) {$jqOptions['animate'] = $val;}
166: if (!is_null($val = $this->Collapsible)) {$jqOptions['collapsible'] = $val;}
167: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
168: if (!is_null($val = $this->Event)) {$jqOptions['event'] = $val;}
169: if (!is_null($val = $this->Header)) {$jqOptions['header'] = $val;}
170: if (!is_null($val = $this->HeightStyle)) {$jqOptions['heightStyle'] = $val;}
171: if (!is_null($val = $this->Icons)) {$jqOptions['icons'] = $val;}
172: return $jqOptions;
173: }
174:
175: /**
176: * Return the JavaScript function to call to associate the widget with the control.
177: *
178: * @return string
179: */
180: public function GetJqSetupFunction() {
181: return 'accordion';
182: }
183:
184: /**
185: * Returns the script that attaches the JQueryUI widget to the html object.
186: *
187: * @return string
188: */
189: public function GetEndScript() {
190: $strId = $this->GetJqControlId();
191: $jqOptions = $this->makeJqOptions();
192: $strFunc = $this->getJqSetupFunction();
193:
194: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
195: // If events are not attached to the actual object being drawn, then the old events will not get
196: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
197: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
198: }
199:
200: // Attach the javascript widget to the html object
201: if (empty($jqOptions)) {
202: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
203: } else {
204: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
205: }
206:
207: return parent::GetEndScript();
208: }
209:
210: /**
211: * Removes the accordion functionality completely. This will return the
212: * element back to its pre-init state.
213: *
214: * * This method does not accept any arguments.
215: */
216: public function Destroy() {
217: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
218: }
219: /**
220: * Disables the accordion.
221: *
222: * * This method does not accept any arguments.
223: */
224: public function Disable() {
225: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
226: }
227: /**
228: * Enables the accordion.
229: *
230: * * This method does not accept any arguments.
231: */
232: public function Enable() {
233: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
234: }
235: /**
236: * Retrieves the accordions instance object. If the element does not have
237: * an associated instance, undefined is returned.
238: *
239: * Unlike other widget methods, instance() is safe to call on any element
240: * after the accordion plugin has loaded.
241: *
242: * * This method does not accept any arguments.
243: */
244: public function Instance() {
245: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
246: }
247: /**
248: * Gets the value currently associated with the specified optionName.
249: *
250: * Note: For options that have objects as their value, you can get the
251: * value of a specific key by using dot notation. For example, "foo.bar"
252: * would get the value of the bar property on the foo option.
253: *
254: * * optionName Type: String The name of the option to get.
255: * @param $optionName
256: */
257: public function Option($optionName) {
258: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
259: }
260: /**
261: * Gets an object containing key/value pairs representing the current
262: * accordion options hash.
263: *
264: * * This signature does not accept any arguments.
265: */
266: public function Option1() {
267: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
268: }
269: /**
270: * Sets the value of the accordion option associated with the specified
271: * optionName.
272: *
273: * Note: For options that have objects as their value, you can set the
274: * value of just one property by using dot notation for optionName. For
275: * example, "foo.bar" would update only the bar property of the foo
276: * option.
277: *
278: * * optionName Type: String The name of the option to set.
279: * * value Type: Object A value to set for the option.
280: * @param $optionName
281: * @param $value
282: */
283: public function Option2($optionName, $value) {
284: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
285: }
286: /**
287: * Sets one or more options for the accordion.
288: *
289: * * options Type: Object A map of option-value pairs to set.
290: * @param $options
291: */
292: public function Option3($options) {
293: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
294: }
295: /**
296: * Process any headers and panels that were added or removed directly in
297: * the DOM and recompute the height of the accordion panels. Results
298: * depend on the content and the heightStyle option.
299: *
300: * * This method does not accept any arguments.
301: */
302: public function Refresh() {
303: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
304: }
305:
306:
307: public function __get($strName) {
308: switch ($strName) {
309: case 'Active': return $this->mixActive;
310: case 'Animate': return $this->mixAnimate;
311: case 'Collapsible': return $this->blnCollapsible;
312: case 'Disabled': return $this->blnDisabled;
313: case 'Event': return $this->strEvent;
314: case 'Header': return $this->mixHeader;
315: case 'HeightStyle': return $this->strHeightStyle;
316: case 'Icons': return $this->mixIcons;
317: default:
318: try {
319: return parent::__get($strName);
320: } catch (QCallerException $objExc) {
321: $objExc->IncrementOffset();
322: throw $objExc;
323: }
324: }
325: }
326:
327: public function __set($strName, $mixValue) {
328: switch ($strName) {
329: case 'Active':
330: $this->mixActive = $mixValue;
331: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'active', $mixValue);
332: break;
333:
334: case 'Animate':
335: $this->mixAnimate = $mixValue;
336: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'animate', $mixValue);
337: break;
338:
339: case 'Collapsible':
340: try {
341: $this->blnCollapsible = QType::Cast($mixValue, QType::Boolean);
342: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'collapsible', $this->blnCollapsible);
343: break;
344: } catch (QInvalidCastException $objExc) {
345: $objExc->IncrementOffset();
346: throw $objExc;
347: }
348:
349: case 'Disabled':
350: try {
351: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
352: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
353: break;
354: } catch (QInvalidCastException $objExc) {
355: $objExc->IncrementOffset();
356: throw $objExc;
357: }
358:
359: case 'Event':
360: try {
361: $this->strEvent = QType::Cast($mixValue, QType::String);
362: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'event', $this->strEvent);
363: break;
364: } catch (QInvalidCastException $objExc) {
365: $objExc->IncrementOffset();
366: throw $objExc;
367: }
368:
369: case 'Header':
370: $this->mixHeader = $mixValue;
371: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'header', $mixValue);
372: break;
373:
374: case 'HeightStyle':
375: try {
376: $this->strHeightStyle = QType::Cast($mixValue, QType::String);
377: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'heightStyle', $this->strHeightStyle);
378: break;
379: } catch (QInvalidCastException $objExc) {
380: $objExc->IncrementOffset();
381: throw $objExc;
382: }
383:
384: case 'Icons':
385: $this->mixIcons = $mixValue;
386: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'icons', $mixValue);
387: break;
388:
389:
390: case 'Enabled':
391: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
392: parent::__set($strName, $mixValue);
393: break;
394:
395: default:
396: try {
397: parent::__set($strName, $mixValue);
398: break;
399: } catch (QCallerException $objExc) {
400: $objExc->IncrementOffset();
401: throw $objExc;
402: }
403: }
404: }
405:
406: /**
407: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
408: * used by the ModelConnector designer dialog to display a list of options for the control.
409: * @return QModelConnectorParam[]
410: **/
411: public static function GetModelConnectorParams() {
412: return array_merge(parent::GetModelConnectorParams(), array(
413: new QModelConnectorParam (get_called_class(), 'Collapsible', 'Whether all the sections can be closed at once. Allows collapsing theactive section.', QType::Boolean),
414: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the accordion if set to true.', QType::Boolean),
415: new QModelConnectorParam (get_called_class(), 'Event', 'The event that accordion headers will react to in order to activatethe associated panel. Multiple events can be specified, separated by aspace.', QType::String),
416: new QModelConnectorParam (get_called_class(), 'HeightStyle', 'Controls the height of the accordion and each panel. Possible values: * \"auto\": All panels will be set to the height of the tallest panel. * \"fill\": Expand to the available height based on the accordionsparent height. * \"content\": Each panel will be only as tall as its content.', QType::String),
417: ));
418: }
419: }