From c546c0c6d718416cc7593f532d570d751da5b3ec Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 7 Nov 2009 17:54:55 -0500 Subject: [PATCH] Fix location auto completion when using the ajax autocompleter. --- ansel/js/googlemap_edit.js | 49 ++++++++++++++------------ ansel/lib/Ajax/Imple/LocationAutoCompleter.php | 8 +++-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ansel/js/googlemap_edit.js b/ansel/js/googlemap_edit.js index 7bad48e8f..8a8ddf3a0 100644 --- a/ansel/js/googlemap_edit.js +++ b/ansel/js/googlemap_edit.js @@ -152,37 +152,40 @@ Ansel_MapEdit.prototype = { * Override the Ajax.Autocompleter#updateChoices method so we can handle * receiving lat/lng points bound to the location. */ -Ajax.Autocompleter.prototype.updateChoices = function(choices) { - var li, re, ul, - i = 0; - this.geocache = choices; +Ajax.Autocompleter.prototype.updateChoices = function(choices) +{ + var c = []; var hc = $H(choices); + + this.geocache = choices; + if (!this.changed && this.hasFocus) { - li = new Element('LI'); - ul = new Element('UL'); - re = new RegExp("(" + this.getToken() + ")", "i"); + var re = new RegExp("(" + this.getToken() + ")", "i"); var k = hc.keys(); k.each(function(n) { - ul.insert(li.cloneNode(false).writeAttribute('acIndex', i++).update(n.gsub(re, '#{1}'))); + c.push({ + l: n.escapeHTML().gsub(re, '#{1}'), + v: n + }); }); - this.update.update(ul); - - this.entryCount = k.size(); - ul.childElements().each(this.addObservers.bind(this)); - - this.stopIndicator(); - this.index = 0; - - if (this.entryCount == 1 && this.options.autoSelect) { - this.selectEntry(); - } else { - this.render(); + if (this.indicator) { + this.indicator.hide(); } - } - if (this.options.afterUpdateChoices) { - this.options.afterUpdateChoices(hc, ul); + if (k.size() == 1 && this.opts.autoSelect) { + this.onSelect(k.first()); + if (this.knl) { + this.knl.hide(); + } + } else if (k.size()) { + if (!this.knl) { + this.knl = new KeyNavList(this.elt, { onChoose: this.onSelect.bind(this), + onShow: this.opts.onShow.bind(this), + domParent: this.opts.domParent }); + } + this.knl.show(c); + } } } diff --git a/ansel/lib/Ajax/Imple/LocationAutoCompleter.php b/ansel/lib/Ajax/Imple/LocationAutoCompleter.php index e7919781d..847cd5369 100644 --- a/ansel/lib/Ajax/Imple/LocationAutoCompleter.php +++ b/ansel/lib/Ajax/Imple/LocationAutoCompleter.php @@ -60,10 +60,12 @@ class Ansel_Ajax_Imple_LocationAutoCompleter extends Horde_Ajax_Imple_AutoComple $locs = $GLOBALS['ansel_storage']->searchLocations($input); if (is_a($locs, 'PEAR_Error')) { Horde::logMessage($locs->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR); - $locs = array(); + $locs = new StdClass(); } - - return Horde_Serialize::serialize($locs, Horde_Serialize::JSON, Horde_Nls::getCharset()); + if (!count($locs)) { + $locs = new StdClass(); + } + return $locs; } } -- 2.11.0