Commit 89d35a45249707e3b459506c4d2035a70502baa1

Authored by Aurelio A. Heckert
1 parent 9e766d40

ActionItem860: The Localization Box

app/controllers/my_profile/profile_design_controller.rb
... ... @@ -18,6 +18,11 @@ class ProfileDesignController < BoxOrganizerController
18 18 blocks << FavoriteEnterprisesBlock
19 19 end
20 20  
  21 + # blocks exclusive for enterprises
  22 + if profile.enterprise?
  23 + blocks << LocalizationBlock
  24 + end
  25 +
21 26 # product block exclusive for enterprises in environments that permits it
22 27 if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises')
23 28 blocks << ProductsBlock
... ...
app/models/google_maps.rb
... ... @@ -28,7 +28,7 @@ class GoogleMaps
28 28 end
29 29  
30 30 def key
31   - config['key']
  31 + config['key'] || ''
32 32 end
33 33  
34 34 def initial_zoom
... ...
app/models/localization_block.rb 0 → 100644
... ... @@ -0,0 +1,29 @@
  1 +class LocalizationBlock < Block
  2 +
  3 + def self.description
  4 + _('Localization map block')
  5 + end
  6 +
  7 + def help
  8 + _('Shows where the profile is on the material world.')
  9 + end
  10 +
  11 + def default_title
  12 + _('Localization Map')
  13 + end
  14 +
  15 + def content
  16 + profile = self.owner
  17 + title = self.title
  18 + lambda do
  19 + profile.lat ?
  20 + block_title(title) +
  21 + content_tag('div',
  22 + '<img src="http://maps.google.com/staticmap?center='+profile.lat.to_s()+','+profile.lng.to_s()+'&zoom=8&size=205x250&maptype=roadmap&markers='+profile.lat.to_s()+','+profile.lng.to_s()+',green&key='+GoogleMaps::key+'&sensor=false"/>',
  23 + :onclick => "window.open('http://wikimapia.org/#lat=#{profile.lat.to_s()}&lon=#{profile.lng.to_s()}&z=12&l=0&m=m&v=2','_blank','width=750,height=500')",
  24 + :class => 'the-localization-map' ) :
  25 + content_tag('i', _('This profile has no geographical position registered.'))
  26 + end
  27 + end
  28 +
  29 +end
... ...
public/stylesheets/blocks/localization-block.css 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +.localization-block {
  2 + text-align: center;
  3 +}
  4 +
  5 +.the-localization-map {
  6 + margin: auto;
  7 + width: 211px;
  8 + max-width: 205px;
  9 + padding: 3px;
  10 + background: #FFF;
  11 + border: 1px solid #888;
  12 + cursor: pointer;
  13 +}
  14 +
... ...
test/unit/localization_block_test.rb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +
  3 +class LocalizationBlockTest < Test::Unit::TestCase
  4 +
  5 + def setup
  6 + @profile = create_user('lele').person
  7 + @block = LocalizationBlock.new
  8 + @profile.boxes.first.blocks << @block
  9 + @block.save!
  10 + end
  11 + attr_reader :block, :profile
  12 +
  13 + should 'provide description' do
  14 + assert_not_equal Block.description, LocalizationBlock.description
  15 + end
  16 +
  17 + should 'display no localization map without lat' do
  18 + assert_tag_in_string block.content, :tag => 'i'
  19 + end
  20 +
  21 + should 'display localization map' do
  22 + profile.lat = 0
  23 + profile.lng = 0
  24 + profile.save!
  25 + assert_tag_in_string block.content, :tag => 'img'
  26 + end
  27 +
  28 + should 'not be editable' do
  29 + assert !LocalizationBlock.new.editable?
  30 + end
  31 +
  32 +end
... ...