1: <?php
2: /**
3: * Triggered when the button 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 QJqButton_CreateEvent extends QJqUiEvent {
11: const EventName = 'buttoncreate';
12: }
13:
14: /* Custom "property" event classes for this control */
15:
16: /**
17: * Generated QJqButtonGen class.
18: *
19: * This is the QJqButtonGen class which is automatically generated
20: * by scraping the JQuery UI documentation website. As such, it includes all the options
21: * as listed by the JQuery UI website, which may or may not be appropriate for QCubed. See
22: * the QJqButtonBase class for any glue code to make this class more
23: * usable in QCubed.
24: *
25: * @see QJqButtonBase
26: * @package Controls\Base
27: * @property boolean $Disabled
28: * Disables the button if set to true.
29: *
30: * @property mixed $Icons
31: * Icons to display, with or without text (see text option). By default,
32: * the primary icon is displayed on the left of the label text and the
33: * secondary is displayed on the right. The positioning can be controlled
34: * via CSS.
35: *
36: * The value for the primary and secondary properties must match an icon
37: * class name, e.g., "ui-icon-gear". For using only one icon: icons: {
38: * primary: "ui-icon-locked" }. For using two icons: icons: { primary:
39: * "ui-icon-gear", secondary: "ui-icon-triangle-1-s" }.
40: *
41: * @property string $Label
42: * Text to show in the button. When not specified (null), the elements
43: * HTML content is used, or its value attribute if the element is an
44: * input element of type submit or reset, or the HTML content of the
45: * associated label element if the element is an input of type radio or
46: * checkbox.
47: *
48: * @property boolean $JqText
49: * Whether to show the label. When set to false no text will be
50: * displayed, but the icons option must be enabled, otherwise the text
51: * option will be ignored.
52: *
53: */
54:
55: class QJqButtonGen extends QButton {
56: protected $strJavaScripts = __JQUERY_EFFECTS__;
57: protected $strStyleSheets = __JQUERY_CSS__;
58: /** @var boolean */
59: protected $blnDisabled = null;
60: /** @var mixed */
61: protected $mixIcons = null;
62: /** @var string */
63: protected $strLabel = null;
64: /** @var boolean */
65: protected $blnJqText = null;
66:
67: /**
68: * Builds the option array to be sent to the widget constructor.
69: *
70: * @return array key=>value array of options
71: */
72: protected function MakeJqOptions() {
73: $jqOptions = null;
74: if (!is_null($val = $this->Disabled)) {$jqOptions['disabled'] = $val;}
75: if (!is_null($val = $this->Icons)) {$jqOptions['icons'] = $val;}
76: if (!is_null($val = $this->Label)) {$jqOptions['label'] = $val;}
77: if (!is_null($val = $this->JqText)) {$jqOptions['text'] = $val;}
78: return $jqOptions;
79: }
80:
81: /**
82: * Return the JavaScript function to call to associate the widget with the control.
83: *
84: * @return string
85: */
86: public function GetJqSetupFunction() {
87: return 'button';
88: }
89:
90: /**
91: * Returns the script that attaches the JQueryUI widget to the html object.
92: *
93: * @return string
94: */
95: public function GetEndScript() {
96: $strId = $this->GetJqControlId();
97: $jqOptions = $this->makeJqOptions();
98: $strFunc = $this->getJqSetupFunction();
99:
100: if ($strId !== $this->ControlId && QApplication::$RequestMode == QRequestMode::Ajax) {
101: // If events are not attached to the actual object being drawn, then the old events will not get
102: // deleted during redraw. We delete the old events here. This must happen before any other event processing code.
103: QApplication::ExecuteControlCommand($strId, 'off', QJsPriority::High);
104: }
105:
106: // Attach the javascript widget to the html object
107: if (empty($jqOptions)) {
108: QApplication::ExecuteControlCommand($strId, $strFunc, QJsPriority::High);
109: } else {
110: QApplication::ExecuteControlCommand($strId, $strFunc, $jqOptions, QJsPriority::High);
111: }
112:
113: return parent::GetEndScript();
114: }
115:
116: /**
117: * Removes the button functionality completely. This will return the
118: * element back to its pre-init state.
119: *
120: * * This method does not accept any arguments.
121: */
122: public function Destroy() {
123: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "destroy", QJsPriority::Low);
124: }
125: /**
126: * Disables the button.
127: *
128: * * This method does not accept any arguments.
129: */
130: public function Disable() {
131: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "disable", QJsPriority::Low);
132: }
133: /**
134: * Enables the button.
135: *
136: * * This method does not accept any arguments.
137: */
138: public function Enable() {
139: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "enable", QJsPriority::Low);
140: }
141: /**
142: * Retrieves the buttons instance object. If the element does not have an
143: * associated instance, undefined is returned.
144: *
145: * Unlike other widget methods, instance() is safe to call on any element
146: * after the button plugin has loaded.
147: *
148: * * This method does not accept any arguments.
149: */
150: public function Instance() {
151: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "instance", QJsPriority::Low);
152: }
153: /**
154: * Gets the value currently associated with the specified optionName.
155: *
156: * Note: For options that have objects as their value, you can get the
157: * value of a specific key by using dot notation. For example, "foo.bar"
158: * would get the value of the bar property on the foo option.
159: *
160: * * optionName Type: String The name of the option to get.
161: * @param $optionName
162: */
163: public function Option($optionName) {
164: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, QJsPriority::Low);
165: }
166: /**
167: * Gets an object containing key/value pairs representing the current
168: * button options hash.
169: *
170: * * This signature does not accept any arguments.
171: */
172: public function Option1() {
173: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", QJsPriority::Low);
174: }
175: /**
176: * Sets the value of the button option associated with the specified
177: * optionName.
178: *
179: * Note: For options that have objects as their value, you can set the
180: * value of just one property by using dot notation for optionName. For
181: * example, "foo.bar" would update only the bar property of the foo
182: * option.
183: *
184: * * optionName Type: String The name of the option to set.
185: * * value Type: Object A value to set for the option.
186: * @param $optionName
187: * @param $value
188: */
189: public function Option2($optionName, $value) {
190: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $optionName, $value, QJsPriority::Low);
191: }
192: /**
193: * Sets one or more options for the button.
194: *
195: * * options Type: Object A map of option-value pairs to set.
196: * @param $options
197: */
198: public function Option3($options) {
199: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "option", $options, QJsPriority::Low);
200: }
201: /**
202: * Refreshes the visual state of the button. Useful for updating button
203: * state after the native elements checked or disabled state is changed
204: * programmatically.
205: *
206: * * This method does not accept any arguments.
207: */
208: public function Refresh() {
209: QApplication::ExecuteControlCommand($this->getJqControlId(), $this->getJqSetupFunction(), "refresh", QJsPriority::Low);
210: }
211:
212:
213: public function __get($strName) {
214: switch ($strName) {
215: case 'Disabled': return $this->blnDisabled;
216: case 'Icons': return $this->mixIcons;
217: case 'Label': return $this->strLabel;
218: case 'JqText': return $this->blnJqText;
219: default:
220: try {
221: return parent::__get($strName);
222: } catch (QCallerException $objExc) {
223: $objExc->IncrementOffset();
224: throw $objExc;
225: }
226: }
227: }
228:
229: public function __set($strName, $mixValue) {
230: switch ($strName) {
231: case 'Disabled':
232: try {
233: $this->blnDisabled = QType::Cast($mixValue, QType::Boolean);
234: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'disabled', $this->blnDisabled);
235: break;
236: } catch (QInvalidCastException $objExc) {
237: $objExc->IncrementOffset();
238: throw $objExc;
239: }
240:
241: case 'Icons':
242: $this->mixIcons = $mixValue;
243: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'icons', $mixValue);
244: break;
245:
246: case 'Label':
247: try {
248: $this->strLabel = QType::Cast($mixValue, QType::String);
249: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'label', $this->strLabel);
250: break;
251: } catch (QInvalidCastException $objExc) {
252: $objExc->IncrementOffset();
253: throw $objExc;
254: }
255:
256: case 'JqText':
257: try {
258: $this->blnJqText = QType::Cast($mixValue, QType::Boolean);
259: $this->AddAttributeScript($this->getJqSetupFunction(), 'option', 'text', $this->blnJqText);
260: break;
261: } catch (QInvalidCastException $objExc) {
262: $objExc->IncrementOffset();
263: throw $objExc;
264: }
265:
266:
267: case 'Enabled':
268: $this->Disabled = !$mixValue; // Tie in standard QCubed functionality
269: parent::__set($strName, $mixValue);
270: break;
271:
272: default:
273: try {
274: parent::__set($strName, $mixValue);
275: break;
276: } catch (QCallerException $objExc) {
277: $objExc->IncrementOffset();
278: throw $objExc;
279: }
280: }
281: }
282:
283: /**
284: * If this control is attachable to a codegenerated control in a ModelConnector, this function will be
285: * used by the ModelConnector designer dialog to display a list of options for the control.
286: * @return QModelConnectorParam[]
287: **/
288: public static function GetModelConnectorParams() {
289: return array_merge(parent::GetModelConnectorParams(), array(
290: new QModelConnectorParam (get_called_class(), 'Disabled', 'Disables the button if set to true.', QType::Boolean),
291: new QModelConnectorParam (get_called_class(), 'Label', 'Text to show in the button. When not specified (null), the elementsHTML content is used, or its value attribute if the element is aninput element of type submit or reset, or the HTML content of theassociated label element if the element is an input of type radio orcheckbox.', QType::String),
292: new QModelConnectorParam (get_called_class(), 'JqText', 'Whether to show the label. When set to false no text will bedisplayed, but the icons option must be enabled, otherwise the textoption will be ignored.', QType::Boolean),
293: ));
294: }
295: }