AjaxHelper Class Reference

Inheritance diagram for AjaxHelper:

Helper Object

List of all members.


Public Member Functions

 _buildCallbacks ($options)
 _buildObserver ($klass, $name, $options=null)
 _buildOptions ($options, $acceptable)
 _optionsForDraggable ($options)
 _optionsForDroppable ($options)
 _optionsToString ($options, $stringOpts=array())
 afterRender ()
 autoComplete ($field, $url="", $options=array())
 div ($id, $options=array())
 divEnd ($id)
 drag ($id, $options=array())
 drop ($id, $options=array())
 dropRemote ($id, $options=array(), $ajaxOptions=array())
 editor ($id, $url, $options=array())
 form ($params=null, $type= 'post', $options=array())
 link ($title, $href=null, $options=array(), $confirm=null, $escapeTitle=true)
 linkToRemote ($title, $options=array(), $html_options=array())
 observeField ($field_id, $options=array())
 observeForm ($field_id, $options=array())
 remoteFunction ($options=null)
 remoteTimer ($options=null)
 slider ($id, $track_id, $options=array())
 sortable ($id, $options=array())
 submit ($title= 'Submit', $options=array())

Public Attributes

 $ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive', 'success', 'failure', 'onSuccess', 'onFailure', 'insertion', 'requestHeaders')
 $autoCompleteOptions = array('paramName', 'tokens', 'frequency', 'minChars', 'indicator', 'updateElement', 'afterUpdateElement', 'onShow', 'onHide')
 $callbacks = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete', 'success', 'failure')
 $dragOptions = array('handle', 'revert', 'constraint', 'change', 'ghosting')
 $dropOptions = array('accept', 'containment', 'overlap', 'greedy', 'hoverclass', 'onHover', 'onDrop')
 $editorOptions = array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'rows', 'cols', 'size', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'callback', 'ajaxOptions', 'clickToEditText')
 $helpers = array('Html', 'Javascript')
 $sliderOptions = array('axis', 'increment', 'maximum', 'minimum', 'alignX', 'alignY', 'sliderValue', 'disabled', 'handleImage', 'handleDisabled', 'values', 'onSlide', 'onChange')
 $sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverclass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange')

Detailed Description

Definition at line 37 of file ajax.php.


Member Function Documentation

AjaxHelper::_buildCallbacks ( options  ) 

Protected Method to return JavaScript text for all callbacks...

Parameters:
array $options
Returns:
array protected

Definition at line 769 of file ajax.php.

References $callbacks.

Referenced by sortable().

AjaxHelper::_buildObserver ( klass,
name,
options = null 
)

Protected Method to return JavaScript text for an observer...

Parameters:
string $klass Name of JavaScript class
string $name
array $options Ajax options
Returns:
string Formatted JavaScript protected

Definition at line 751 of file ajax.php.

References remoteFunction().

Referenced by observeField(), and observeForm().

AjaxHelper::_buildOptions ( options,
acceptable 
)

Protected Method to return a string of JavaScript with the given option data as a JavaScript options hash.

Parameters:
array $options Options in the shape of keys and values
array $acceptable Array of legal keys in this options context
Returns:
string String of Javascript array definition protected

Definition at line 725 of file ajax.php.

References $v.

Referenced by _optionsForDraggable(), _optionsForDroppable(), autoComplete(), editor(), slider(), and sortable().

AjaxHelper::_optionsForDraggable ( options  ) 

Protectd helper method to return an array of options for draggable.

Parameters:
array $options
Returns:
array protected

Definition at line 507 of file ajax.php.

References _buildOptions(), and _optionsToString().

Referenced by drag().

AjaxHelper::_optionsForDroppable ( options  ) 

Protected helper method to return an array of options for droppable.

Parameters:
string $options
Returns:
string String of Javascript array definition protected

Definition at line 532 of file ajax.php.

References _buildOptions(), and _optionsToString().

Referenced by drop(), and dropRemote().

AjaxHelper::_optionsToString ( options,
stringOpts = array() 
)

Protected Method to return a string of JavaScript with a string representation of given options array.

Parameters:
array $options Ajax options array
array $stringOpts Options as strings in an array private
Returns:
array protected

Definition at line 791 of file ajax.php.

Referenced by _optionsForDraggable(), _optionsForDroppable(), autoComplete(), editor(), slider(), and sortable().

AjaxHelper::afterRender (  ) 

afterRender callback

Returns:
array public

Reimplemented from Helper.

Definition at line 811 of file ajax.php.

References $data.

AjaxHelper::autoComplete ( field,
url = "",
options = array() 
)

Create a text field with Autocomplete.

Creates an autocomplete field with the given ID and options.

options['with'] defaults to "Form.Element.serialize('$field_id')", but can be any valid javascript expression defining the

string $field_id DOM ID of field to observe string $url URL for the autocomplete action array $options Ajax options string Ajax script public

Definition at line 411 of file ajax.php.

References _buildOptions(), _optionsToString(), Inflector::camelize(), and div().

AjaxHelper::div ( id,
options = array() 
)

Creates an Ajax-updateable DIV element

Parameters:
string $id options for javascript
array $options a set of options
Returns:
string HTML code public

Definition at line 470 of file ajax.php.

References Helper::output().

Referenced by autoComplete().

AjaxHelper::divEnd ( id  ) 

Closes an Ajax-updateable DIV element

Parameters:
string $id The DOM ID of the element
Returns:
string HTML code public

Definition at line 489 of file ajax.php.

References Helper::output().

AjaxHelper::drag ( id,
options = array() 
)

Setup a Draggable Element. For a reference on the options for this function, check out

sting $id the DOM id to enable array $options a set of options string Javascript::codeBlock(); public

Definition at line 459 of file ajax.php.

References _optionsForDraggable().

AjaxHelper::drop ( id,
options = array() 
)

Setup a droppable element For a reference on the options for this function, check out

string $id array $options array public

Definition at line 521 of file ajax.php.

References _optionsForDroppable().

AjaxHelper::dropRemote ( id,
options = array(),
ajaxOptions = array() 
)

AjaxHelper::form ( params = null,
type = 'post',
options = array() 
)

Returns form tag that will submit using Ajax.

Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission will work just like a regular submission as viewed by the receiving side (all elements available in params). The options for defining callbacks is the same as link().

Parameters:
array $params Form target
array $type How form data is posted: 'get' or 'post'
array $options Callback/HTML options
Returns:
string JavaScript/HTML code public

Definition at line 284 of file ajax.php.

References remoteFunction().

Referenced by editor(), and sortable().

AjaxHelper::link ( title,
href = null,
options = array(),
confirm = null,
escapeTitle = true 
)

Returns link to remote action

Returns a link to a remote action defined by options[url] (using the urlFor format) that's called in the background using XMLHttpRequest. The result of that request can then be inserted into a DOM object whose id can be specified with options[update].

Examples: $ajax->link("Delete this post", "/posts/delete/{$post['Post']['id']}" array("update" => "posts", "loading"=>"Element.show('loading');", "complete"=>"Element.hide('loading');"), "Are you sure you want to delte this post?"); $ajax->link($html->img("refresh"), '/emails/refresh', array("update" => "posts", "loading"=>"Element.show('loading');", "complete"=>"Element.hide('loading');"), null, false);

By default, these remote requests are processed asynchronous during which various callbacks can be triggered (for progress indicators and the likes).

The callbacks that may be specified are:

  • loading:: Called when the remote document is being loaded with data by the browser.
  • loaded:: Called when the browser has finished loading the remote document.
  • interactive:: Called when the user can interact with the remote document, even though it has not finished loading.
  • complete:: Called when the request is complete.

If you for some reason or another need synchronous processing (that'll block the browser while the request is happening), you can specify $options['type'] = synchronous.

You can customize further browser side call logic by passing in Javascript code snippets via some optional parameters. In their order of use these are:

  • confirm :: Adds confirmation dialog.
  • condition :: Perform remote request conditionally by this expression. Use this to describe browser-side conditions when request should not be initiated.
  • before :: Called before request is initiated.
  • after :: Called immediately after request was initiated and before loading.

string $title Title of link string $href href string "/products/view/12" array $options Options for JavaScript function string $confirm Confirmation message. Calls up a JavaScript confirm() message. boolean $escapeTitle Escaping the title string to HTML entities HTML code for link to remote action public

Definition at line 167 of file ajax.php.

References remoteFunction().

Referenced by linkToRemote().

AjaxHelper::linkToRemote ( title,
options = array(),
html_options = array() 
)

Replaced by AjaxHelper::link()

Deprecated:
will not be avialable after 1.1.x.x

Definition at line 835 of file ajax.php.

References link(), and remoteFunction().

AjaxHelper::observeField ( field_id,
options = array() 
)

Observe field and call ajax on change.

Observes the field with the DOM ID specified by field_id and makes an Ajax when its contents have changed.

Required +options+ are:

  • frequency:: The frequency (in seconds) at which changes to this field will be detected.
  • url::
    See also:
    urlFor() -style options for the action to call when the field has changed.
    Additional options are:
  • update:: Specifies the DOM ID of the element whose innerHTML should be updated with the XMLHttpRequest response text.
  • with:: A Javascript expression specifying the parameters for the XMLHttpRequest. This defaults to Form.Element.serialize('$field_id'), which can be accessed from params['form']['field_id'].

See also:
link().
Parameters:
string $field_id DOM ID of field to observe
array $options ajax options
Returns:
string ajax script public

Definition at line 371 of file ajax.php.

References _buildObserver().

AjaxHelper::observeForm ( field_id,
options = array() 
)

Observe entire form and call ajax on change.

Like

See also:
observeField(), but operates on an entire form identified by the DOM ID form_id. options are the same as observe_field, except the default value of the with option evaluates to the serialized (request string) value of the form.
Parameters:
string $field_id DOM ID of field to observe
array $options ajax options
Returns:
string ajax script public

Definition at line 390 of file ajax.php.

References _buildObserver().

AjaxHelper::remoteFunction ( options = null  ) 

Creates JavaScript function for remote AJAX call

This function creates the javascript needed to make a remote call it is primarily used as a helper for link.

link() for docs on options parameter. array $options options for javascript string html code for link to remote action public

Definition at line 214 of file ajax.php.

Referenced by _buildObserver(), dropRemote(), form(), link(), linkToRemote(), remoteTimer(), sortable(), and submit().

AjaxHelper::remoteTimer ( options = null  ) 

Periodically call remote url via AJAX.

Periodically calls the specified url (options['url']) every options['frequency'] seconds (default is 10). Usually used to update a specified div (options['update']) with the results of the remote call. The options for specifying the target with url and defining callbacks is the same as link.

array $options Callback options string Javascript codeblock public

Definition at line 265 of file ajax.php.

References remoteFunction().

AjaxHelper::slider ( id,
track_id,
options = array() 
)

AjaxHelper::sortable ( id,
options = array() 
)

AjaxHelper::submit ( title = 'Submit',
options = array() 
)

Returns a button input tag that will submit using Ajax

Returns a button input tag that will submit form using XMLHttpRequest in the background instead of regular reloading POST arrangement. options argument is the same as in form_remote_tag

Parameters:
string $title Input button title
array $options Callback options
Returns:
string Ajaxed input button public

Definition at line 329 of file ajax.php.

References remoteFunction().


Member Data Documentation

AjaxHelper::$ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive', 'success', 'failure', 'onSuccess', 'onFailure', 'insertion', 'requestHeaders')

Definition at line 58 of file ajax.php.

Referenced by dropRemote().

AjaxHelper::$autoCompleteOptions = array('paramName', 'tokens', 'frequency', 'minChars', 'indicator', 'updateElement', 'afterUpdateElement', 'onShow', 'onHide')

Definition at line 100 of file ajax.php.

AjaxHelper::$callbacks = array('uninitialized', 'loading', 'loaded', 'interactive', 'complete', 'success', 'failure')

Definition at line 51 of file ajax.php.

Referenced by _buildCallbacks().

AjaxHelper::$dragOptions = array('handle', 'revert', 'constraint', 'change', 'ghosting')

Definition at line 65 of file ajax.php.

AjaxHelper::$dropOptions = array('accept', 'containment', 'overlap', 'greedy', 'hoverclass', 'onHover', 'onDrop')

Definition at line 72 of file ajax.php.

AjaxHelper::$editorOptions = array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'rows', 'cols', 'size', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'callback', 'ajaxOptions', 'clickToEditText')

Definition at line 93 of file ajax.php.

AjaxHelper::$helpers = array('Html', 'Javascript')

Definition at line 44 of file ajax.php.

AjaxHelper::$sliderOptions = array('axis', 'increment', 'maximum', 'minimum', 'alignX', 'alignY', 'sliderValue', 'disabled', 'handleImage', 'handleDisabled', 'values', 'onSlide', 'onChange')

Definition at line 86 of file ajax.php.

AjaxHelper::$sortOptions = array('tag', 'only', 'overlap', 'constraint', 'containment', 'handle', 'hoverclass', 'ghosting', 'dropOnEmpty', 'onUpdate', 'onChange')

Definition at line 79 of file ajax.php.


The documentation for this class was generated from the following file: