From: Michael M Slusarz Date: Thu, 29 Oct 2009 01:27:45 +0000 (-0600) Subject: Add AutoCompleter Ajax driver. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1860ae113d00154c6b63b9f5a7a446efea869bd8;p=horde.git Add AutoCompleter Ajax driver. --- diff --git a/framework/Ajax/lib/Horde/Ajax/Imple/AutoCompleter.php b/framework/Ajax/lib/Horde/Ajax/Imple/AutoCompleter.php new file mode 100644 index 000000000..e1fb87657 --- /dev/null +++ b/framework/Ajax/lib/Horde/Ajax/Imple/AutoCompleter.php @@ -0,0 +1,114 @@ + + * @package Horde_Ajax + */ +abstract class Horde_Ajax_Imple_AutoCompleter extends Horde_Ajax_Imple_Base +{ + /** + * Constructor. + * + * @param array $params Configuration parameters. + *
+     * 'triggerId' => (string) [optional] TODO
+     * 
+ */ + public function __construct($params) + { + if (empty($params['triggerId'])) { + $params['triggerId'] = $this->_randomid(); + } + + parent::__construct($params); + } + + /** + * Attach the object to a javascript event. + */ + public function attach() + { + $params = array( + '"' . $this->_params['triggerId'] . '"' + ); + + $config = $this->_attach(array( + 'func_replace' => array(), + 'tokens' => array(',', ';') + )); + + if (isset($config['ajax'])) { + Horde::addScriptFile('autocomplete.js', 'horde'); + Horde::addScriptFile('KeyNavList.js', 'horde'); + Horde::addScriptFile('liquidmetal.js', 'horde'); + $func = 'Ajax.Autocompleter'; + $params[] = '"' . $this->_getUrl($config['ajax'], $GLOBALS['registry']->getApp(), array('input' => $this->_params['triggerId'])) . '"'; + } elseif (isset($config['browser'])) { + Horde::addScriptFile('autocomplete.js', 'horde'); + Horde::addScriptFile('KeyNavList.js', 'horde'); + Horde::addScriptFile('liquidmetal.js', 'horde'); + $func = 'Autocompleter.Local'; + $params[] = $config['browser']; + $config['params'] = array_merge(array( + 'partialSearch' => 1, + 'fullSearch' => 1, + 'score' => 1 + ), $config['params']); + } elseif (isset($config['pretty'])) { + Horde::addScriptFile('prettyautocomplete.js', 'horde'); + $func = 'PrettyAutocompleter'; + $config['params'] = array_merge(array( + 'boxClass' => 'hordeACBox kronolithLongField', + 'trigger' => $this->_params['triggerId'], + 'uri' => $this->_getUrl($config['pretty'], $GLOBALS['registry']->getApp()), + 'URI_IMG_HORDE' => $GLOBALS['registry']->getImageDir('horde') + ), $config['params']); + + if (!empty($this->_params['existing'])) { + $config['params']['existing'] = $this->_params['existing']; + } + } else { + return; + } + + $js_params = Horde_Serialize::serialize($config['params'], Horde_Serialize::JSON); + foreach ($config['func_replace'] as $key => $val) { + $js_params = str_replace($key, $val, $js_params); + } + + Horde::addScriptFile('effects.js', 'horde'); + + Horde::addInlineScript((isset($config['var']) ? $config['var'] . ' ' : '') . 'new ' . $func . '(' . implode(',', $params) . ',' . $js_params . ')', 'dom'); + } + + /** + * Attach the object to a javascript event. + * + * @return array An array with the following elements: + *
+     * ONE of the following:
+     * 'ajax' - (string) Use 'Ajax.Autocompleter' class. Value is the AJAX
+     *          function name.
+     * 'browser' - (string) Use 'Autocompleter.Local' class. Value is the
+     *             javascript list of items to search.
+     * 'pretty' - (string) Use 'PrettyAutocompleter' class. Value is the AJAX
+     *            function name.
+     *
+     * Additional Options:
+     * 'func_replace' - (array) Replaces keys with values. Useful for adding
+     *                  functions to javascript parameters output.
+     * 'params' - (array) The list of javascript parameters to pass to the
+     *            autocomplete libraries.
+     * 'var' - (string) If set, the autocomplete object will be assigned to
+     *         this variable.
+     * 
+ */ + abstract protected function _attach($js_params); + +} diff --git a/framework/Ajax/package.xml b/framework/Ajax/package.xml index 94bcf8b76..c70922004 100644 --- a/framework/Ajax/package.xml +++ b/framework/Ajax/package.xml @@ -24,7 +24,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial release. + * Add AutoCompleter driver. + * Initial release. @@ -32,6 +33,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -67,6 +69,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> +