diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 9abee36..98e571f 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -18,6 +18,11 @@ class ProfileDesignController < BoxOrganizerController blocks << FavoriteEnterprisesBlock end + # blocks exclusive for enterprises + if profile.enterprise? + blocks << LocalizationBlock + end + # product block exclusive for enterprises in environments that permits it if profile.enterprise? && !profile.environment.enabled?('disable_products_for_enterprises') blocks << ProductsBlock diff --git a/app/models/google_maps.rb b/app/models/google_maps.rb index 6f4ca90..4850abc 100644 --- a/app/models/google_maps.rb +++ b/app/models/google_maps.rb @@ -28,7 +28,7 @@ class GoogleMaps end def key - config['key'] + config['key'] || '' end def initial_zoom diff --git a/app/models/localization_block.rb b/app/models/localization_block.rb new file mode 100644 index 0000000..d7011d0 --- /dev/null +++ b/app/models/localization_block.rb @@ -0,0 +1,29 @@ +class LocalizationBlock < Block + + def self.description + _('Localization map block') + end + + def help + _('Shows where the profile is on the material world.') + end + + def default_title + _('Localization Map') + end + + def content + profile = self.owner + title = self.title + lambda do + profile.lat ? + block_title(title) + + content_tag('div', + '', + :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')", + :class => 'the-localization-map' ) : + content_tag('i', _('This profile has no geographical position registered.')) + end + end + +end diff --git a/public/stylesheets/blocks/localization-block.css b/public/stylesheets/blocks/localization-block.css new file mode 100644 index 0000000..ae58176 --- /dev/null +++ b/public/stylesheets/blocks/localization-block.css @@ -0,0 +1,14 @@ +.localization-block { + text-align: center; +} + +.the-localization-map { + margin: auto; + width: 211px; + max-width: 205px; + padding: 3px; + background: #FFF; + border: 1px solid #888; + cursor: pointer; +} + diff --git a/test/unit/localization_block_test.rb b/test/unit/localization_block_test.rb new file mode 100644 index 0000000..771c3c2 --- /dev/null +++ b/test/unit/localization_block_test.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class LocalizationBlockTest < Test::Unit::TestCase + + def setup + @profile = create_user('lele').person + @block = LocalizationBlock.new + @profile.boxes.first.blocks << @block + @block.save! + end + attr_reader :block, :profile + + should 'provide description' do + assert_not_equal Block.description, LocalizationBlock.description + end + + should 'display no localization map without lat' do + assert_tag_in_string block.content, :tag => 'i' + end + + should 'display localization map' do + profile.lat = 0 + profile.lng = 0 + profile.save! + assert_tag_in_string block.content, :tag => 'img' + end + + should 'not be editable' do + assert !LocalizationBlock.new.editable? + end + +end -- libgit2 0.21.2