Source for file Action.php
Documentation is available at Action.php
* OO AJAX Implementation for PHP, contains HTML_AJAX_Action
* @author Elizabeth Smith <auroraeosrose@gmail.com>
* @copyright 2005-2006 Elizabeth Smith
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: @package_version@
* Require the response class and json serializer
require_once 'HTML/AJAX/Response.php';
require_once 'HTML/AJAX/Serializer/JSON.php';
* Helper class to eliminate the need to write javascript functions to deal with data
* This class creates information that can be properly serialized and used by
* the haaction serializer which eliminates the need for php users to write javascript
* for dealing with the information returned by an ajax method - instead the javascript
* is basically created for them
* @version $Id: Action.php 537 2006-08-12 01:48:12Z emsmith $
* Content type for the HAA response
* goofy but unique content type to tell the javascript which deserializer to use
* overrides HTML_AJAX_Response
* An array holding all the actions for the class
* these have numeric keys and each new action is added on the end, remember
* these are executed in the order added
* Prepends data to the attribute identified by id
* The data will be added to the beginning of the attribute identified by the id
* sent, id must be unique
* $response->prependAttr('myid', 'class', 'red');
* $response->prependAttr('myid', array('class' => 'red', 'innerHTML' => 'this is an error'));
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string|array $attribute either an array of attribute/data pairs or a string attribute name
* @param mixed $data should be NULL if attribute is an array, otherwise data you wish to set the attribute to
$attribute = array ($attribute => $data);
$this->_actions[] = array (
'attributes' => $attribute,
* Appends data to the attribute identified by id
* The data will be added to the end of the attribute identified by the id
* sent, id must be unique
* $response->appendAttr('myid', 'class', 'red');
* $response->appendAttr('myid', array('class' => 'red', 'innerHTML' => 'this is an error'));
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string|array $attribute either an array of attribute/data pairs or a string attribute name
* @param mixed $data should be NULL if attribute is an array, otherwise data you wish to set the attribute to
function appendAttr($id, $attribute, $data = NULL )
$attribute = array ($attribute => $data);
$this->_actions[] = array (
'attributes' => $attribute,
* Assigns data to the attribute identified by id overwriting any previous values
* The data will be assigned to the attribute identified by the id
* sent, id must be unique
* $response->assignAttr('myid', 'class', 'red');
* $response->assignAttr('myid', array('class' => 'red', 'innerHTML' => 'this is an error'));
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string|array $attribute either an array of attribute/data pairs or a string attribute name
* @param mixed $data should be NULL if attribute is an array, otherwise data you wish to set the attribute to
function assignAttr($id, $attribute, $data = NULL )
$attribute = array ($attribute => $data);
$this->_actions[] = array (
'attributes' => $attribute,
* Deletes or assigns a value of an empty string to an attribute
* You may send either a single attribute or an array of attributes to clear
* $response->clearAttr('myid', 'class');
* $response->clearAttr('myid', array('class', 'innerHTML'));
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string|array $attribute either an array of attribute/data pairs or a string attribute name
$attribute = array ($attribute);
$this->_actions[] = array (
'attributes' => $attribute,
* create a dom node via javascript
* higher level dom manipulation - creates a new node to insert into the dom
* You can control where the new node is inserted with two things, the insertion
* type and the id/ The type should be append, prepend, insertBefore, or insertAfter
* The id is a sibling node - like a div in the same div you want to add more to
* If you choose to append or prepend a node it will be placed at the beginning
* or end of the node with the id you send. If you choose insertBefore or
* InsertAfter it will be put right before or right after the node you specified.
* You can send an array of attributes to apply to the new node as well,
* so you don't have to create it and then assign Attributes.
* $response->createNode('myid', 'div');
* $response->createNode('submit', 'input',
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string $tag html node to create
* @param array $attributes array of attribute -> data to fill the node with
function createNode($id, $tag, $attributes, $type = 'append')
$types = array ('append', 'prepend', 'insertBefore', 'insertAfter');
$this->_actions[] = array (
'attributes' => $attributes,
* Replace a dom node via javascript
* higher level dom manipulation - replaces one node with another
* This can be used to replace a div with a form for inline editing
* use innerHtml attribute to change inside text
* $response->replaceNode('myid', 'div', array('innerHTML' => 'loading complete'));
* $response->replaceNode('mydiv', 'form', array('innerHTML' => $form));
* @param string $id id for a specific item on the page <div id="myid"></div>
* @param string $tag html node to create
* @param array $attributes array of attribute -> data to fill the node with
$this->_actions[] = array (
'attributes' => $attributes,
* Delete a dom node via javascript
* $response->removeNode('myid');
* $response->removeNode(array('mydiv', 'myform'));
* @param string $id id for a specific item on the page <div id="myid"></div>
$this->_actions[] = array (
* Send a string to a javascript eval
* This will send the data right to the eval javascript function, it will NOT
* allow you to dynamically add a javascript function for use later on because
* it is constrined by the eval function
* @param string $data string to pass to the alert javascript function
$this->_actions[] = array (
* Send a string to a javascript alert
* This will send the data right to the alert javascript function
* @param string $data string to pass to the alert javascript function
$this->_actions[] = array (
* Returns the serialized content of the response class
* we actually use the json serializer underneath, so we send the actions array
* to the json serializer and return the data
* @return string serialized response content
return $serializer->serialize ($this->_actions);
* Adds all the actions from one response object to another, feature request
* @param object $instance referenced HTML_AJAX_Action object
$this->_actions = array_merge($this->_actions, $instance->retrieveActions ());
* to follow proper property access we need a way to retrieve the private
Documentation generated on Sat, 05 May 2007 18:00:06 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|