Converted to config option, thanks to Roy!
This commit is contained in:
parent
87a4d1eb34
commit
bd2310f88e
4 changed files with 58 additions and 4 deletions
|
@ -1,5 +1,4 @@
|
||||||
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
|
||||||
require 'gmaps'
|
|
||||||
|
|
||||||
class Observer::User::Geo < ActiveRecord::Observer
|
class Observer::User::Geo < ActiveRecord::Observer
|
||||||
observe 'user'
|
observe 'user'
|
||||||
|
@ -54,8 +53,13 @@ class Observer::User::Geo < ActiveRecord::Observer
|
||||||
# return if no address is given
|
# return if no address is given
|
||||||
return if address == ''
|
return if address == ''
|
||||||
|
|
||||||
|
# load adapter
|
||||||
|
adapter = Setting.get('geo_backend')
|
||||||
|
return if !adapter
|
||||||
|
adapter_module = Object.const_get(adapter)
|
||||||
|
|
||||||
# db lookup
|
# db lookup
|
||||||
latlng = Gmaps.geocode(address)
|
latlng = adapter_module.geocode(address)
|
||||||
return if !latlng
|
return if !latlng
|
||||||
|
|
||||||
# store data
|
# store data
|
||||||
|
|
|
@ -40,9 +40,9 @@ module Zammad
|
||||||
'observer::_ticket::_article::_communicate_facebook',
|
'observer::_ticket::_article::_communicate_facebook',
|
||||||
'observer::_ticket::_article::_communicate_twitter',
|
'observer::_ticket::_article::_communicate_twitter',
|
||||||
'observer::_ticket::_notification',
|
'observer::_ticket::_notification',
|
||||||
'observer::_tag::_ticket_history',
|
|
||||||
'observer::_ticket::_reset_new_state',
|
'observer::_ticket::_reset_new_state',
|
||||||
'observer::_ticket::_escalation_calculation',
|
'observer::_ticket::_escalation_calculation',
|
||||||
|
'observer::_tag::_ticket_history',
|
||||||
'observer::_user::_geo'
|
'observer::_user::_geo'
|
||||||
|
|
||||||
|
|
||||||
|
|
29
db/migrate/20130806000001_update_geo.rb
Normal file
29
db/migrate/20130806000001_update_geo.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class UpdateGeo < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
:title => 'Geo Location Backend',
|
||||||
|
:name => 'geo_backend',
|
||||||
|
:area => 'System::Geo',
|
||||||
|
:description => 'Defines the backend for geo location lookups.',
|
||||||
|
:options => {
|
||||||
|
:form => [
|
||||||
|
{
|
||||||
|
:display => '',
|
||||||
|
:null => true,
|
||||||
|
:name => 'geo_backend',
|
||||||
|
:tag => 'select',
|
||||||
|
:options => {
|
||||||
|
'' => '-',
|
||||||
|
'Gmaps' => 'Google Maps',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
:state => 'Gmaps',
|
||||||
|
:frontend => true
|
||||||
|
)
|
||||||
|
end
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
23
db/seeds.rb
23
db/seeds.rb
|
@ -133,7 +133,28 @@ Setting.create_if_not_exists(
|
||||||
:state => 'DB',
|
:state => 'DB',
|
||||||
:frontend => false
|
:frontend => false
|
||||||
)
|
)
|
||||||
|
Setting.create_if_not_exists(
|
||||||
|
:title => 'Geo Location Backend',
|
||||||
|
:name => 'geo_backend',
|
||||||
|
:area => 'System::Geo',
|
||||||
|
:description => 'Defines the backend for geo location lookups.',
|
||||||
|
:options => {
|
||||||
|
:form => [
|
||||||
|
{
|
||||||
|
:display => '',
|
||||||
|
:null => true,
|
||||||
|
:name => 'geo_backend',
|
||||||
|
:tag => 'select',
|
||||||
|
:options => {
|
||||||
|
'' => '-',
|
||||||
|
'Gmaps' => 'Google Maps',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
:state => 'Gmaps',
|
||||||
|
:frontend => true
|
||||||
|
)
|
||||||
|
|
||||||
Setting.create_if_not_exists(
|
Setting.create_if_not_exists(
|
||||||
:title => 'New User Accounts',
|
:title => 'New User Accounts',
|
||||||
|
|
Loading…
Reference in a new issue