tpAJAX Class Reference

Inherits Plugin.

Collaboration diagram for tpAJAX:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tpAJAX ()
 dialog ($dlg_id, $target, $buttons=array(), $overlay=false, $modal=false, $opts=array())
 popup_bind ($div_id, $targets=array(), $buttons=array())
 buttons ($buttons, $context, $retjs=false)
 autocomplete ($name, $value_id, $value_name, $search_url, $form_id)
 autocomplete_multisel ($name, $values, $search_url, $form_id, $max_sel=0)
 _attribs ($attribs)

Public Attributes

 $guid

Detailed Description

PRONTO WEB FRAMEWORK Copyright (C) 2006, Judd Vinet

Author:
Judd Vinet <jvinet@zeroflux.org>

Description: Template plugin for AJAX-y widgets/controls.

Definition at line 10 of file ajax.php.


Member Function Documentation

tpAJAX::_attribs ( attribs  ) 

Definition at line 412 of file ajax.php.

tpAJAX::autocomplete ( name,
value_id,
value_name,
search_url,
form_id 
)

Generate an autocomplete textbox widget for a single selection.

This widget requires an AJAX controller to handle the search requests. The controller should return the results in plain text, with each result on a new line. Separate fields with a pipe (|).

Here's an example of a simple AJAX search controller that does both searches and lookups:

         function GET_search() {
                 $this->set_ajax(true);
                 if($id = $this->param('id')) {
                         $user = $this->models->user->get($id);
                         if($user) echo $user['name']."\n";
                 } else {
                   $matches = $this->models->user->search($this->param('q'), $this->param('limit'));
                   foreach($matches as $id=>$name) echo "$id|$name\n";
                 }
         }
Parameters:
string $name Name of the form field (usually type="hidden") that will contain the selections. This field will be generated for you automatically.
string $value_id The "ID" of the current selection. This is the variable that will populate the value="" field of the hidden form variable.
string $value_name The display vlue of the current selection. This is the variable that will be shown in the browser. If this is set to TRUE, then the widget will request the value name through the $search_url by passing the "id" query var.
string $search_url Full URL to the AJAX search URL
string $form_id DOM ID of the form that contains the selections
Returns:
string

Definition at line 264 of file ajax.php.

References $guid, __(), Plugin_Base::depend(), and html.

Referenced by autocomplete_multisel().

tpAJAX::autocomplete_multisel ( name,
values,
search_url,
form_id,
max_sel = 0 
)

Generate an autocomplete textbox widget and "container" div to hold the multiple selections.

This widget requires an AJAX controller to handle the search requests. The controller should return the results in plain text, with each result on a new line. Separate fields with a pipe (|).

Here's an example of a simple AJAX search controller:

         function GET_search() {
           $this->set_ajax(true);
           $matches = $this->models->user->search($this->param('q'), $this->param('limit'));
           foreach($matches as $id=>$name) echo "$id|$name\n";
         }
Parameters:
string $name Name of the form field (usually type="hidden") that will contain the selections. Don't include the trailing '[]' as it will be appended automatically.
array $values Currently selected values
string $search_url Full URL to the AJAX search URL
string $form_id DOM ID of the form that contains the selections
int $max_sel The maximum number of selections allowed, or zero for unlimited
Returns:
string

Definition at line 354 of file ajax.php.

References $guid, __(), autocomplete(), and Plugin_Base::depend().

tpAJAX::buttons ( buttons,
context,
retjs = false 
)

Return the HTML/JS to create a series of buttons destined for a popup or a dialog.

Action can be one of the following:

  • "ajax_load": Fetch the "url" variable via GET and populate the popup div with the resulting HTML. The AJAX action should return a JSON packet.
  • "submit_form": Submit the form specified by the "form_id" variable.
  • "close": Close/hide the popup div.
  • "function": Call the JavaScript function specified by the "function" variable. The function should take a single argument, which is the jQuery element for the content container of the dialog or popup.
  • "custom": Run a custom snippet of JavaScript as specified in the "js" variable.

Example:

         $ajax->buttons(array(
                 __('OK')     => array('action'=>'submit_form', 'form_id'=>'myform'),
                 __('Thingy') => array('action'=>'ajax_load', 'url'=>url('/ajax/thingy')),
                 __('Cancel') => array('action'=>'close')
         ));
Parameters:
array $buttons Button configuration
string $context Either 'popup' or 'dialog', depending on what the buttons will be used in.
boolean $retjs Return JavaScript code for event handlers as well. If false, the returned HTML will include JavaScript to install the event handlers.
Returns:
string

Definition at line 170 of file ajax.php.

Referenced by dialog(), and popup_bind().

tpAJAX::dialog ( dlg_id,
target,
buttons = array(),
overlay = false,
modal = false,
opts = array() 
)

Create a modal dialog window and bind it to a trigger element/event.

Example:

         <div id="mydlg" title="My Dialog">Hello World!</div>
         <a href="#" id="clickme">Click Me</a>
         <?php $ajax->dialog('mydlg', '#clickme') ?>
Parameters:
string $dlg_id The DOM ID of the content that will be converted into a dialog window.
mixed $target The jQuery selector of the DOM element used to trigger the dialog window, or an array of the event and selector, eg, array('click','a.trig'). This field can be blank if you want to handle the event yourself.
boolean $overlay Grey out the background before showing the new window.
boolean $modal Make the window modal, so the user can't interface with other parts of the window until the dialog is closed.
array $opts Additional options to pass to jqModal. Options should be contained in the values only (don't use an associative array) and separated with colons, just as you would build them in Javascript. Options can be found on the jqModal website: http://dev.iceburg.net/jquery/jqModal/

Definition at line 53 of file ajax.php.

References $opts, and buttons().

tpAJAX::popup_bind ( div_id,
targets = array(),
buttons = array() 
)

Connect an existing div to one or more targets that, when clicked, will make the div visible. Also include zero or more buttons along the bottom of the popup div.

Parameters:
$div_id string The DOM ID of the div element serving as the popup
$targets array jQuery selector(s) for target elements (eg, "a.new-row" or "#btn")
$buttons array Button configuration (see tpAJAX::buttons() for example)
Returns:
none

Definition at line 117 of file ajax.php.

References buttons().

tpAJAX::tpAJAX (  ) 

Constructor

Definition at line 17 of file ajax.php.

References Plugin_Base::depend(), and Plugin::Plugin().


Member Data Documentation

tpAJAX::$guid

Definition at line 12 of file ajax.php.

Referenced by autocomplete(), and autocomplete_multisel().


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

Generated on Wed Jan 13 09:21:05 2010 for Pronto Framework by  doxygen 1.6.1