Commit 89d35a45249707e3b459506c4d2035a70502baa1
1 parent
9e766d40
Exists in
master
and in
29 other branches
ActionItem860: The Localization Box
Showing
5 changed files
with
81 additions
and
1 deletions
Show diff stats
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
... | ... | @@ -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 | ... | ... |
... | ... | @@ -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 | ... | ... |