1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_Ajax_Imple_LocationAutoCompleter extends Horde_Core_Ajax_Imple_AutoCompleter
14: {
15: protected function _attach($js_params)
16: {
17: $js_params['indicator'] = $this->_params['triggerId'] . '_loading_img';
18: $js_params['tokens'] = array();
19:
20: $ret = array(
21: 'params' => $js_params,
22: 'raw_params' => array(
23: 'onSelect' => 'function (v) { ' . $this->_params['map'] . '.ll = Ansel.ajax.locationAutoCompleter.geocache[v]; return v; }'
24: ),
25: 'var' => "Ansel.ajax['locationAutoCompleter']"
26: );
27:
28:
29: if (!$GLOBALS['session']->exists('ansel', 'ajax_locationac')) {
30: try {
31: $results = $GLOBALS['injector']->getInstance('Ansel_Storage')->searchLocations();
32: $GLOBALS['session']->set('ansel', 'ajax_locationac', (count($results) > 50));
33: } catch (Ansel_Exception $e) {
34: Horde::logMessage($e, 'ERR');
35: }
36: }
37:
38: if ($GLOBALS['session']->get('ansel', 'ajax_locationac')) {
39: $ret['ajax'] = 'LocationAutoCompleter';
40: } else {
41: if (empty($results)) {
42: $results = $GLOBALS['injector']->getInstance('Ansel_Storage')->searchLocations();
43: }
44: $ret['browser'] = Horde_Serialize::serialize($results, Horde_Serialize::JSON);
45: }
46:
47: return $ret;
48: }
49:
50: public function handle($args, $post)
51: {
52:
53: if (empty($args['input']) ||
54: !($input = Horde_Util::getFormData($args['input']))) {
55: return array();
56: }
57: try {
58: $locs = $GLOBALS['injector']->getInstance('Ansel_Storage')->searchLocations($input);
59: if (!count($locs)) {
60: $locs = new StdClass();
61: }
62: } catch (Ansel_Exception $e) {
63: Horde::logMessage($e->getMessage(), 'ERR');
64: $locs = new StdClass();
65: }
66: return $locs;
67: }
68:
69: }
70: