forked from extern/egroupware
Use geolocation api to try to determine city
This commit is contained in:
parent
5cfd583904
commit
7e5d6ebb41
@ -58,17 +58,42 @@ class home_weather_portlet extends home_portlet
|
||||
$etemplate->set_dom_id($id);
|
||||
$content = $this->context;
|
||||
$request = array(
|
||||
'q' => $this->context['city'],
|
||||
'units' => $this->context['units'] ? $this->context['units'] : 'metric',
|
||||
'lang' => $GLOBALS['egw_info']['user']['preferences']['common']['lang'],
|
||||
// Always get (& cache) 10 days, we'll cut down later
|
||||
'cnt' => 10
|
||||
);
|
||||
|
||||
if($this->context['city'])
|
||||
if($this->context['city_id'])
|
||||
{
|
||||
$request['id'] = $this->context['city_id'];
|
||||
$content += $this->get_weather($request);
|
||||
}
|
||||
elseif($this->context['city'])
|
||||
{
|
||||
$request['q'] = $this->context['city'];
|
||||
$content += $this->get_weather($request);
|
||||
}
|
||||
elseif ($this->context['position'])
|
||||
{
|
||||
list($request['lat'],$request['lon']) = explode(',',$this->context['position']);
|
||||
$content += $this->get_weather($request);
|
||||
}
|
||||
|
||||
// Caching is best done by city ID, so store that
|
||||
if($content['city_id'] && (!$this->context['city_id'] || $content['city_id'] != $this->context['city_id']))
|
||||
{
|
||||
|
||||
$portlets = $GLOBALS['egw']->preferences->read_repository();
|
||||
$portlets = $portlets['home'];
|
||||
|
||||
// Save updated preferences
|
||||
$portlets[$id]['city_id'] = $content['city_id'];
|
||||
$this->context['city'] = $portlets[$id]['city'] = $content['settings']['city'] =
|
||||
$content['settings']['title'] = $content['city'] = is_array($content['city']) ? $content['city']['name'] : $content['city'];
|
||||
unset($portlets[$id]['position']);
|
||||
$GLOBALS['egw']->preferences->add('home', $id, $portlets[$id]);
|
||||
$GLOBALS['egw']->preferences->save_repository(True);
|
||||
}
|
||||
|
||||
// Adjust data to match portlet size
|
||||
if($this->context['height'] <= 2 && $this->context['width'] <= 3)
|
||||
|
@ -853,6 +853,25 @@ app.classes.home.home_list_portlet = app.classes.home.home_portlet.extend({
|
||||
}
|
||||
}
|
||||
});
|
||||
app.classes.home.home_weather_portlet = app.classes.home.home_portlet.extend({
|
||||
init: function(portlet) {
|
||||
// call parent
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// Use location API
|
||||
if(!this.portlet.options.settings && 'geolocation' in navigator)
|
||||
{
|
||||
navigator.geolocation.getCurrentPosition(function(position) {
|
||||
if(portlet && portlet.options && portlet.options.settings &&
|
||||
portlet.options.settings.position && portlet.options.settings.position == position.coords.latitude + ',' + position.coords.longitude)
|
||||
{
|
||||
return;
|
||||
}
|
||||
portlet._process_edit(et2_dialog.OK_BUTTON, {position: position.coords.latitude + ',' + position.coords.longitude});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
app.classes.home.home_favorite_portlet = app.classes.home.home_portlet.extend({
|
||||
observer: function(_msg, _app, _id, _type, _msg_type, _targetapp)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user