1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Horde_Core_Ajax_Imple_WeatherLocationAutoCompleter extends Horde_Core_Ajax_Imple_AutoCompleter
15: {
16: 17: 18:
19: protected function _attach($js_params)
20: {
21: $js_params['indicator'] = $this->_params['triggerId'] . '_loading_img';
22: $js_params['tokens'] = array();
23: $updateurl = Horde::getServiceLink('ajax', 'horde')->setRaw(true);
24: $updateurl->pathInfo = 'blockRefresh';
25: $updateurl->add('app', 'horde')
26: ->add('blockid', 'horde_block_weather');
27: Horde::addInlineScript(
28: array(
29: 'window.weatherupdate = window.weatherupdate || {};',
30: 'window.weatherupdate["' . $this->_params['instance'] . '"] = {
31: value: false,
32: choices: {},
33: update: function() {
34: var v;
35: if (this.value) {
36: v = this.value;
37: } else {
38: v = $F("location' . $this->_params['instance'] . '");
39: }
40: $("' . $js_params['indicator'] . '").toggle();
41: new Ajax.Updater(
42: "weathercontent' . $this->_params['instance'] . '",
43: "' . strval($updateurl) . '",
44: {
45: evalScripts: true,
46: parameters: { location: v },
47: onComplete: function() { $("' . $js_params['indicator'] . '").toggle(); }
48: }
49: );
50:
51: this.value = false;
52: }
53: }',
54: '$("button' . $this->_params['instance'] . '").observe("click", function(e) {
55: window.weatherupdate["' . $this->_params['instance'] . '"].update();
56: e.stop();
57: });'
58: ),
59: 'dom'
60: );
61:
62:
63: $ret = array(
64: 'params' => $js_params,
65: 'raw_params' => array(
66: 'filterCallback' => 'function(c) {
67: if (c) {
68: window.weatherupdate["' . $this->_params['instance'] . '"].choices = c;
69: var r = [];
70: c.each(function(i) {
71: r.push(i.name);
72: });
73: return r;
74: } else {
75: return [];
76: }
77: }',
78: 'onSelect' => 'function(c) {
79: window.weatherupdate["' . $this->_params['instance'] . '"].choices.each(function(i) {
80: if (i.name == c) {
81: window.weatherupdate["' . $this->_params['instance'] . '"].value = i.code.replace("/q/", "");
82: throw $break;
83: } else {
84: window.weatherupdate["' . $this->_params['instance'] . '"].value = false;
85: }
86: });
87: return c;
88: }'
89: )
90: );
91: $ret['params']['minChars'] = 5;
92: $ret['ajax'] = 'WeatherLocationAutoCompleter';
93:
94: if (!empty($this->_params['var'])) {
95: $ret['var'] = $this->_params['var'];
96: }
97:
98: return $ret;
99: }
100:
101: 102: 103: 104: 105: 106: 107:
108: public function handle($args, $post)
109: {
110:
111: if (empty($args['input']) ||
112: !($input = Horde_Util::getPost($args['input']))) {
113: return array();
114: }
115: $w = $GLOBALS['injector']
116: ->getInstance('Horde_Weather');
117: $r = $w->autocompleteLocation($input);
118:
119: return $r;
120: }
121:
122: }
123: