Converted to config option, thanks to Roy!

This commit is contained in:
Martin Edenhofer 2013-08-06 15:31:27 +02:00
parent 87a4d1eb34
commit bd2310f88e
4 changed files with 58 additions and 4 deletions

View file

@ -1,5 +1,4 @@
# Copyright (C) 2012-2013 Zammad Foundation, http://zammad-foundation.org/
require 'gmaps'
class Observer::User::Geo < ActiveRecord::Observer
observe 'user'
@ -54,8 +53,13 @@ class Observer::User::Geo < ActiveRecord::Observer
# return if no address is given
return if address == ''
# load adapter
adapter = Setting.get('geo_backend')
return if !adapter
adapter_module = Object.const_get(adapter)
# db lookup
latlng = Gmaps.geocode(address)
latlng = adapter_module.geocode(address)
return if !latlng
# store data

View file

@ -40,9 +40,9 @@ module Zammad
'observer::_ticket::_article::_communicate_facebook',
'observer::_ticket::_article::_communicate_twitter',
'observer::_ticket::_notification',
'observer::_tag::_ticket_history',
'observer::_ticket::_reset_new_state',
'observer::_ticket::_escalation_calculation',
'observer::_tag::_ticket_history',
'observer::_user::_geo'

View 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

View file

@ -133,7 +133,28 @@ Setting.create_if_not_exists(
:state => 'DB',
: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(
:title => 'New User Accounts',