Adding additional fixes for autoComplete(), Ticket #1002

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3131 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-18 19:21:09 +00:00
parent 3d4b5ebc09
commit dfb49aad38
2 changed files with 38 additions and 10 deletions

View file

@ -341,9 +341,9 @@ class DboSource extends DataSource {
}
if ($this->_queriesCnt > 1) {
$text = 'queries';
$text = 'queries';
} else {
$text = 'query';
$text = 'query';
}
print ("<table id=\"cakeSqlLog\" border = \"0\">\n<caption>{$this->_queriesCnt} {$text} took {$this->_queriesTime} ms</caption>\n");
print ("<thead>\n<tr><th>Nr</th><th>Query</th><th>Error</th><th>Affected</th><th>Num. rows</th><th>Took (ms)</th></tr>\n</thead>\n<tbody>\n");

View file

@ -86,6 +86,12 @@ class AjaxHelper extends Helper {
* @var array
*/
var $editorOptions = array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'rows', 'cols', 'size', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'callback', 'ajaxOptions', 'clickToEditText', 'collection');
/**
* Options for auto-complete editor.
*
* @var array
*/
var $autoCompleteOptions = array('paramName', 'tokens', 'frequency', 'minChars', 'indicator', 'updateElement', 'afterUpdateElement', 'onShow', 'onHide');
/**
* Output buffer for Ajax update content
*
@ -428,24 +434,46 @@ class AjaxHelper extends Helper {
* @return string Ajax script
*/
function autoComplete($field, $url = "", $options = array()) {
$var = '';
if (isset($options['var'])) {
$var = 'var ' . $options['var'] . ' = ';
unset($options['var']);
}
if (!isset($options['id'])) {
$options['id'] = r("/", "_", $field);
}
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => isset($options['class']) ? $options['class'] : 'auto_complete');
if (isset($options['div_id'])) {
$divOptions['id'] = $options['div_id'];
unset($options['div_id']);
}
$htmlOptions = $this->__getHtmlOptions($options);
$htmlOptions['autocomplete'] = "off";
if (!isset($options['class'])) {
$options['class'] = "auto_complete";
foreach ($this->autoCompleteOptions as $opt) {
unset($htmlOptions[$opt]);
}
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => $options['class']);
if (isset($options['tokens'])) {
if (is_array($options['tokens'])) {
$options['tokens'] = $this->Javascript->object($options['tokens']);
} else {
$options['tokens'] = '"' . $options['tokens'] . '"';
}
}
return $this->Html->input($field, $htmlOptions) .
$this->Html->tag("div", $divOptions, true) . "</div>" .
$this->Javascript->codeBlock("new Ajax.Autocompleter('" . $options['id'] .
"', '" . $divOptions['id'] . "', '" . $this->Html->url($url) . "', " .
$this->__optionsForAjax($options) . ");");
$options = $this->_optionsToString($options, array('paramName', 'indicator'));
$options = $this->_buildOptions($options, $this->autoCompleteOptions);
return $this->Html->input($field, $htmlOptions) . "\n" .
$this->Html->tag("div", $divOptions, true) . "</div>\n" .
$this->Javascript->codeBlock("{$var}new Ajax.Autocompleter('" . $htmlOptions['id']
. "', '" . $divOptions['id'] . "', '" . $this->Html->url($url) . "', " .
$options . ");");
}
/**
* Creates an Ajax-updateable DIV element