| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * The abstract QAutocompleteGen class defined here is |
|---|
| 4 | * code-generated and contains options, events and methods scraped from the |
|---|
| 5 | * JQuery UI documentation Web site. It is not generated by the typical |
|---|
| 6 | * codegen process, but rather is generated periodically by the core QCubed |
|---|
| 7 | * team and checked in. However, the code to generate this file is |
|---|
| 8 | * in the assets/_core/php/_devetools/jquery_ui_gen/jq_control_gen.php file |
|---|
| 9 | * and you can regenerate the files if you need to. |
|---|
| 10 | * |
|---|
| 11 | * The comments in this file are taken from the JQuery UI site, so they do |
|---|
| 12 | * not always make sense with regard to QCubed. They are simply provided |
|---|
| 13 | * as reference. Note that this is very low-level code, and does not always |
|---|
| 14 | * update QCubed state variables. See the QAutocompleteBase |
|---|
| 15 | * file, which contains code to interface between this generated file and QCubed. |
|---|
| 16 | * |
|---|
| 17 | * Because subsequent re-code generations will overwrite any changes to this |
|---|
| 18 | * file, you should leave this file unaltered to prevent yourself from losing |
|---|
| 19 | * any information or code changes. All customizations should be done by |
|---|
| 20 | * overriding existing or implementing new methods, properties and variables |
|---|
| 21 | * in the QAutocomplete class file. |
|---|
| 22 | * |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | /* Custom event classes for this control */ |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | /** |
|---|
| 29 | * This event is triggered when autocomplete is created. |
|---|
| 30 | */ |
|---|
| 31 | class QAutocomplete_CreateEvent extends QJqUiEvent { |
|---|
| 32 | const EventName = 'autocompletecreate'; |
|---|
| 33 | } |
|---|
| 34 | /** |
|---|
| 35 | * Before a request (source-option) is started, after minLength and delay are |
|---|
| 36 | * met. Can be canceled (return false), then no request will be started and no |
|---|
| 37 | * items suggested. |
|---|
| 38 | */ |
|---|
| 39 | class QAutocomplete_SearchEvent extends QJqUiEvent { |
|---|
| 40 | const EventName = 'autocompletesearch'; |
|---|
| 41 | } |
|---|
| 42 | /** |
|---|
| 43 | * Triggered when the suggestion menu is opened. |
|---|
| 44 | */ |
|---|
| 45 | class QAutocomplete_OpenEvent extends QJqUiEvent { |
|---|
| 46 | const EventName = 'autocompleteopen'; |
|---|
| 47 | } |
|---|
| 48 | /** |
|---|
| 49 | * Before focus is moved to an item (not selecting), ui.item refers to the |
|---|
| 50 | * focused item. The default action of focus is to replace the text field's |
|---|
| 51 | * value with the value of the focused item, though only if the focus event |
|---|
| 52 | * was triggered by a keyboard interaction. Canceling this event prevents the |
|---|
| 53 | * value from being updated, but does not prevent the menu item from being |
|---|
| 54 | * focused. |
|---|
| 55 | */ |
|---|
| 56 | class QAutocomplete_FocusEvent extends QJqUiEvent { |
|---|
| 57 | const EventName = 'autocompletefocus'; |
|---|
| 58 | } |
|---|
| 59 | /** |
|---|
| 60 | * Triggered when an item is selected from the menu; ui.item refers to the |
|---|
| 61 | * selected item. The default action of select is to replace the text field's |
|---|
| 62 | * value with the value of the selected item. Canceling this event prevents |
|---|
| 63 | * the value from being updated, but does not prevent the menu from closing. |
|---|
| 64 | */ |
|---|
| 65 | class QAutocomplete_SelectEvent extends QJqUiEvent { |
|---|
| 66 | const EventName = 'autocompleteselect'; |
|---|
| 67 | } |
|---|
| 68 | /** |
|---|
| 69 | * When the list is hidden - doesn't have to occur together with a change. |
|---|
| 70 | */ |
|---|
| 71 | class QAutocomplete_CloseEvent extends QJqUiEvent { |
|---|
| 72 | const EventName = 'autocompleteclose'; |
|---|
| 73 | } |
|---|
| 74 | /** |
|---|
| 75 | * Triggered when the field is blurred, if the value has changed; ui.item |
|---|
| 76 | * refers to the selected item. |
|---|
| 77 | */ |
|---|
| 78 | class QAutocomplete_ChangeEvent extends QJqUiEvent { |
|---|
| 79 | const EventName = 'autocompletechange'; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | /* Custom "property" event classes for this control */ |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * @property boolean $Disabled Disables (true) or enables (false) the autocomplete. Can be set when |
|---|
| 86 | * initialising (first creating) the autocomplete. |
|---|
| 87 | * @property mixed $AppendTo Which element the menu should be appended to. |
|---|
| 88 | * @property boolean $AutoFocus If set to true the first item will be automatically focused. |
|---|
| 89 | * @property integer $Delay The delay in milliseconds the Autocomplete waits after a keystroke to |
|---|
| 90 | * activate itself. A zero-delay makes sense for local data (more responsive), |
|---|
| 91 | * but can produce a lot of load for remote data, while being less responsive. |
|---|
| 92 | * @property integer $MinLength The minimum number of characters a user has to type before the Autocomplete |
|---|
| 93 | * activates. Zero is useful for local data with just a few items. Should be |
|---|
| 94 | * increased when there are a lot of items, where a single character would |
|---|
| 95 | * match a few thousand items. |
|---|
| 96 | * @property mixed $Position Identifies the position of the Autocomplete widget in relation to the |
|---|
| 97 | * associated input element. The "of" option defaults to the input element, |
|---|
| 98 | * but you can specify another element to position against. You can refer to |
|---|
| 99 | * the jQuery UI Position utility for more details about the various options. |
|---|
| 100 | * @property mixed $Source Defines the data to use, must be specified. See Overview section for more |
|---|
| 101 | * details, and look at the various demos. |
|---|
| 102 | */ |
|---|
| 103 | |
|---|
| 104 | class QAutocompleteGen extends QTextBox { |
|---|
| 105 | protected $strJavaScripts = __JQUERY_EFFECTS__; |
|---|
| 106 | protected $strStyleSheets = __JQUERY_CSS__; |
|---|
| 107 | /** @var boolean */ |
|---|
| 108 | protected $blnDisabled = null; |
|---|
| 109 | /** @var mixed */ |
|---|
| 110 | protected $mixAppendTo = null; |
|---|
| 111 | /** @var boolean */ |
|---|
| 112 | protected $blnAutoFocus = null; |
|---|
| 113 | /** @var integer */ |
|---|
| 114 | protected $intDelay = null; |
|---|
| 115 | /** @var integer */ |
|---|
| 116 | protected $intMinLength = null; |
|---|
| 117 | /** @var mixed */ |
|---|
| 118 | protected $mixPosition = null; |
|---|
| 119 | /** @var mixed */ |
|---|
| 120 | protected $mixSource; |
|---|
| 121 | |
|---|
| 122 | protected function makeJsProperty($strProp, $strKey) { |
|---|
| 123 | $objValue = $this->$strProp; |
|---|
| 124 | if (null === $objValue) { |
|---|
| 125 | return ''; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | return $strKey . ': ' . JavaScriptHelper::toJsObject($objValue) . ', '; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | protected function makeJqOptions() { |
|---|
| 132 | $strJqOptions = ''; |
|---|
| 133 | $strJqOptions .= $this->makeJsProperty('Disabled', 'disabled'); |
|---|
| 134 | $strJqOptions .= $this->makeJsProperty('AppendTo', 'appendTo'); |
|---|
| 135 | $strJqOptions .= $this->makeJsProperty('AutoFocus', 'autoFocus'); |
|---|
| 136 | $strJqOptions .= $this->makeJsProperty('Delay', 'delay'); |
|---|
| 137 | $strJqOptions .= $this->makeJsProperty('MinLength', 'minLength'); |
|---|
| 138 | $strJqOptions .= $this->makeJsProperty('Position', 'position'); |
|---|
| 139 | $strJqOptions .= $this->makeJsProperty('Source', 'source'); |
|---|
| 140 | if ($strJqOptions) $strJqOptions = substr($strJqOptions, 0, -2); |
|---|
| 141 | return $strJqOptions; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | public function getJqControlId() { |
|---|
| 145 | return $this->ControlId; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | public function getJqSetupFunction() { |
|---|
| 149 | return 'autocomplete'; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | public function GetControlJavaScript() { |
|---|
| 153 | return sprintf('jQuery("#%s").%s({%s})', $this->getJqControlId(), $this->getJqSetupFunction(), $this->makeJqOptions()); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | public function GetEndScript() { |
|---|
| 157 | return $this->GetControlJavaScript() . '; ' . parent::GetEndScript(); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | /** |
|---|
| 161 | * Call a JQuery UI Method on the object. Takes variable number of arguments. |
|---|
| 162 | * |
|---|
| 163 | * @param string $strMethodName the method name to call |
|---|
| 164 | * @internal param $mixed [optional] $mixParam1 |
|---|
| 165 | * @internal param $mixed [optional] $mixParam2 |
|---|
| 166 | */ |
|---|
| 167 | protected function CallJqUiMethod($strMethodName /*, ... */) { |
|---|
| 168 | $args = array(); |
|---|
| 169 | $args = func_get_args(); |
|---|
| 170 | |
|---|
| 171 | $strArgs = JavaScriptHelper::toJsObject($args); |
|---|
| 172 | $strJs = sprintf('jQuery("#%s").%s(%s)', |
|---|
| 173 | $this->getJqControlId(), |
|---|
| 174 | $this->getJqSetupFunction(), |
|---|
| 175 | substr($strArgs, 1, strlen($strArgs)-2)); // params without brackets |
|---|
| 176 | QApplication::ExecuteJavaScript($strJs); |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | /** |
|---|
| 181 | * Remove the autocomplete functionality completely. This will return the |
|---|
| 182 | * element back to its pre-init state. |
|---|
| 183 | */ |
|---|
| 184 | public function Destroy() { |
|---|
| 185 | $this->CallJqUiMethod("destroy"); |
|---|
| 186 | } |
|---|
| 187 | /** |
|---|
| 188 | * Disable the autocomplete. |
|---|
| 189 | */ |
|---|
| 190 | public function Disable() { |
|---|
| 191 | $this->CallJqUiMethod("disable"); |
|---|
| 192 | } |
|---|
| 193 | /** |
|---|
| 194 | * Enable the autocomplete. |
|---|
| 195 | */ |
|---|
| 196 | public function Enable() { |
|---|
| 197 | $this->CallJqUiMethod("enable"); |
|---|
| 198 | } |
|---|
| 199 | /** |
|---|
| 200 | * Get or set any autocomplete option. If no value is specified, will act as a |
|---|
| 201 | * getter. |
|---|
| 202 | * @param $optionName |
|---|
| 203 | * @param $value |
|---|
| 204 | */ |
|---|
| 205 | public function Option($optionName, $value = null) { |
|---|
| 206 | $this->CallJqUiMethod("option", $optionName, $value); |
|---|
| 207 | } |
|---|
| 208 | /** |
|---|
| 209 | * Set multiple autocomplete options at once by providing an options object. |
|---|
| 210 | * @param $options |
|---|
| 211 | */ |
|---|
| 212 | public function Option1($options) { |
|---|
| 213 | $this->CallJqUiMethod("option", $options); |
|---|
| 214 | } |
|---|
| 215 | /** |
|---|
| 216 | * Triggers a search event, which, when data is available, then will display |
|---|
| 217 | * the suggestions; can be used by a selectbox-like button to open the |
|---|
| 218 | * suggestions when clicked. If no value argument is specified, the current |
|---|
| 219 | * input's value is used. Can be called with an empty string and minLength: 0 |
|---|
| 220 | * to display all items. |
|---|
| 221 | * @param $value |
|---|
| 222 | */ |
|---|
| 223 | public function Search($value = null) { |
|---|
| 224 | $this->CallJqUiMethod("search", $value); |
|---|
| 225 | } |
|---|
| 226 | /** |
|---|
| 227 | * Close the Autocomplete menu. Useful in combination with the search method, |
|---|
| 228 | * to close the open menu. |
|---|
| 229 | */ |
|---|
| 230 | public function Close() { |
|---|
| 231 | $this->CallJqUiMethod("close"); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | public function __get($strName) { |
|---|
| 236 | switch ($strName) { |
|---|
| 237 | case 'Disabled': return $this->blnDisabled; |
|---|
| 238 | case 'AppendTo': return $this->mixAppendTo; |
|---|
| 239 | case 'AutoFocus': return $this->blnAutoFocus; |
|---|
| 240 | case 'Delay': return $this->intDelay; |
|---|
| 241 | case 'MinLength': return $this->intMinLength; |
|---|
| 242 | case 'Position': return $this->mixPosition; |
|---|
| 243 | case 'Source': return $this->mixSource; |
|---|
| 244 | default: |
|---|
| 245 | try { |
|---|
| 246 | return parent::__get($strName); |
|---|
| 247 | } catch (QCallerException $objExc) { |
|---|
| 248 | $objExc->IncrementOffset(); |
|---|
| 249 | throw $objExc; |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | public function __set($strName, $mixValue) { |
|---|
| 255 | $this->blnModified = true; |
|---|
| 256 | |
|---|
| 257 | switch ($strName) { |
|---|
| 258 | case 'Disabled': |
|---|
| 259 | try { |
|---|
| 260 | $this->blnDisabled = QType::Cast($mixValue, QType::Boolean); |
|---|
| 261 | if ($this->Rendered) { |
|---|
| 262 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 263 | } |
|---|
| 264 | break; |
|---|
| 265 | } catch (QInvalidCastException $objExc) { |
|---|
| 266 | $objExc->IncrementOffset(); |
|---|
| 267 | throw $objExc; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | case 'AppendTo': |
|---|
| 271 | $this->mixAppendTo = $mixValue; |
|---|
| 272 | |
|---|
| 273 | if ($this->Rendered) { |
|---|
| 274 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 275 | } |
|---|
| 276 | break; |
|---|
| 277 | |
|---|
| 278 | case 'AutoFocus': |
|---|
| 279 | try { |
|---|
| 280 | $this->blnAutoFocus = QType::Cast($mixValue, QType::Boolean); |
|---|
| 281 | if ($this->Rendered) { |
|---|
| 282 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 283 | } |
|---|
| 284 | break; |
|---|
| 285 | } catch (QInvalidCastException $objExc) { |
|---|
| 286 | $objExc->IncrementOffset(); |
|---|
| 287 | throw $objExc; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | case 'Delay': |
|---|
| 291 | try { |
|---|
| 292 | $this->intDelay = QType::Cast($mixValue, QType::Integer); |
|---|
| 293 | if ($this->Rendered) { |
|---|
| 294 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 295 | } |
|---|
| 296 | break; |
|---|
| 297 | } catch (QInvalidCastException $objExc) { |
|---|
| 298 | $objExc->IncrementOffset(); |
|---|
| 299 | throw $objExc; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | case 'MinLength': |
|---|
| 303 | try { |
|---|
| 304 | $this->intMinLength = QType::Cast($mixValue, QType::Integer); |
|---|
| 305 | if ($this->Rendered) { |
|---|
| 306 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 307 | } |
|---|
| 308 | break; |
|---|
| 309 | } catch (QInvalidCastException $objExc) { |
|---|
| 310 | $objExc->IncrementOffset(); |
|---|
| 311 | throw $objExc; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | case 'Position': |
|---|
| 315 | $this->mixPosition = $mixValue; |
|---|
| 316 | |
|---|
| 317 | if ($this->Rendered) { |
|---|
| 318 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 319 | } |
|---|
| 320 | break; |
|---|
| 321 | |
|---|
| 322 | case 'Source': |
|---|
| 323 | $this->mixSource = $mixValue; |
|---|
| 324 | |
|---|
| 325 | if ($this->Rendered) { |
|---|
| 326 | $this->CallJqUiMethod("option", $strName, $mixValue); |
|---|
| 327 | } |
|---|
| 328 | break; |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | case 'Enabled': |
|---|
| 332 | $this->Disabled = !$mixValue; // Tie in standard QCubed functionality |
|---|
| 333 | parent::__set($strName, $mixValue); |
|---|
| 334 | break; |
|---|
| 335 | |
|---|
| 336 | default: |
|---|
| 337 | try { |
|---|
| 338 | parent::__set($strName, $mixValue); |
|---|
| 339 | break; |
|---|
| 340 | } catch (QCallerException $objExc) { |
|---|
| 341 | $objExc->IncrementOffset(); |
|---|
| 342 | throw $objExc; |
|---|
| 343 | } |
|---|
| 344 | } |
|---|
| 345 | } |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | ?> |
|---|