Fix location auto completion when using the ajax autocompleter.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 7 Nov 2009 22:54:55 +0000 (17:54 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 7 Nov 2009 22:55:39 +0000 (17:55 -0500)
ansel/js/googlemap_edit.js
ansel/lib/Ajax/Imple/LocationAutoCompleter.php

index 7bad48e..8a8ddf3 100644 (file)
@@ -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, '<strong>#{1}</strong>')));
+            c.push({
+                l: n.escapeHTML().gsub(re, '<strong>#{1}</strong>'),
+                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);
+        }
     }
 }
 
index e791978..847cd53 100644 (file)
@@ -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;
     }
 
 }