View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Controller_Action_Helper_Autocomplete
{zone-data}

{zone-data:proposer-list}
[~matthew]
{zone-data}

{zone-data:revision}
0.8.0 - 08 January 2008: Initial proposal creation
0.9.0 - 09 January 2008: Updated with feedback from Zend team and comments
{zone-data}

{zone-data:overview}
Zend_Controller_Action_Helper_Autocomplete is intended to automate creation and transmittal of a response for use in client-side autocompletion.
{zone-data}

{zone-data:references}
In no particular order:
* [Ajax.Autocompleter in Scriptaculous|http://wiki.script.aculo.us/scriptaculous/show/Ajax.Autocompleter]
* [Autocompletion in YUI|http://developer.yahoo.com/yui/autocomplete/]
* [Autocompletion in Dojo|http://today.java.net/pub/a/today/2006/04/27/building-ajax-with-dojo-and-json.html]
* [Autocompletion in JQuery|http://fromvega.com/wordpress/2007/05/05/auto-complete-field-with-jquery-json-php/]
{zone-data}

{zone-data:requirements}
* This component *will* provide an abstract class for handling autocomplete resultsets.
* This component *will* provide one or more concrete implementations for returning autocomplete resultsets to specific client-side JS libraries.
* This component *will* set appropriate headers and the response body with the resultset.
{zone-data}

{zone-data:dependencies}
* Zend_Controller_Action_Helper_Abstract
* Zend_Controller_Response_Abstract (for setting response headers and content)
* Zend_Controller_Action_Helper_Json (for serializing JSON resultsets and setting response headers)
{zone-data}

{zone-data:operation}
Autocompletion allows type-ahead type functionality for HTML text input, providing users with options that may match the input they've typed. There are many ways to provide such functionality on the server-side, including:

* Returning HTML unordered lists (Prototype/Scriptaculous)
* Returning JSON arrays-of-arrays (YUI)
* Returning JSON objects (basically arrays-of-arrays) (Dojo)
* Returning JSON array-of-strings (JQuery)

Due to the variety of return types, no one component may serve all scenarios. However, the base functionality is relatively the same: take an array or iterable resultset of data, and transform it to the appropriate return value.

The Autocomplete helper will provide an abstract class for the base operations, including serializing the data to JSON return values. Concrete classes will thenformat the return value for the appropriate library.
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] Complete proposal
* Milestone 2: Write tests and code and publish to incubator
* Milestone 3: Write documentation and use cases
* Milestone 4: Publish to core
{zone-data}

{zone-data:class-list}
* Zend_Controller_Action_Helper_AutoComplete_Abstract
* Zend_Controller_Action_Helper_AutoCompleteDojo
* Zend_Controller_Action_Helper_AutoCompleteScriptaculous
* Zend_Controller_Action_Helper_AutoCompleteJquery
{zone-data}

{zone-data:use-cases}
||UC-01||
{code:php}
class FooController extends Zend_Controller_Action
{
public function barAction()
{
// ...
if ($this->_helper->ajaxContext->getCurrentContext()) {
// Return autocompletion results for Dojo:
return $this->_helper->autoCompleteDojo($data);
}
// ...
}

public function bazAction()
{
// ...
if ($this->_helper->ajaxContext->getCurrentContext()) {
// Return autocompletion results for Scriptaculous:
return $this->_helper->autoCompleteScriptaculous($data);
}
// ...
}
}
{code}
{zone-data}

{zone-data:skeletons}
h2. Zend_Controller_Action_Helper_Autocomplete_Abstract
{code:php}
class Zend_Controller_Action_Helper_AutoComplete_Abstract extends Zend_Controller_Action_Helper_Abstract
{
/**
* Encode data as JSON and set headers
*/
public function encodeJson($data);

/**
* Strategy pattern: proxy to appropriate encoding
*/
abstract public function direct($data);
}
{code}

{code:php}
class Zend_Controller_Action_Helper_AutoCompleteDojo extends Zend_Controller_Action_Helper_AutoComplete_Abstract
{
public function direct($data); // proxies to encodeJson()
}
{code}

{code:php}
class Zend_Controller_Action_Helper_AutoCompleteScriptaculous extends Zend_Controller_Action_Helper_AutoComplete_Abstract
{
public function direct($data); // generates response
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>