From 81eb23f25652c0b7608b267a62d10d3d768d06e2 Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Mon, 11 Jul 2011 12:48:52 +0000 Subject: [PATCH] Add MapBalloonController --- app/controllers/public/map_balloon_controller.rb | 28 ++++++++++++++++++++++++++++ app/helpers/search_helper.rb | 56 -------------------------------------------------------- app/views/map_balloon/product.rhtml | 3 +++ app/views/map_balloon/profile.rhtml | 28 ++++++++++++++++++++++++++++ app/views/search/_google_maps.rhtml | 88 +++++++++++++++++++++++++--------------------------------------------------------------- app/views/search/_product.rhtml | 2 +- config/routes.rb | 3 +++ public/javascripts/google_maps.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 146 insertions(+), 120 deletions(-) create mode 100644 app/controllers/public/map_balloon_controller.rb create mode 100644 app/views/map_balloon/product.rhtml create mode 100644 app/views/map_balloon/profile.rhtml create mode 100644 public/javascripts/google_maps.js diff --git a/app/controllers/public/map_balloon_controller.rb b/app/controllers/public/map_balloon_controller.rb new file mode 100644 index 0000000..69e95cf --- /dev/null +++ b/app/controllers/public/map_balloon_controller.rb @@ -0,0 +1,28 @@ +class MapBalloonController < PublicController + + before_filter :profile, :only => [:person, :enterprise, :community] + + def product + @product = Product.find(params[:id]) + render :action => 'product', :layout => false + end + + def person + render :action => 'profile', :layout => false + end + + def enterprise + render :action => 'profile', :layout => false + end + + def community + render :action => 'profile', :layout => false + end + + protected + + def profile + @profile = Profile.find(params[:id]) + end + +end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 15dc0b0..f0def29 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -33,62 +33,6 @@ module SearchHelper content_tag('div', data[:toggle] + (render :partial => data[:partial]), :class => "map-or-list-search-results #{data[:class]}") end - def display_item_map_info(item) - if item.kind_of?(Profile) - display_profile_info(item) - elsif item.kind_of?(Product) - display_product_info(item) - end - end - - def display_profile_info(profile) - data = '' - unless profile.contact_email.nil? - data << content_tag('strong', _('E-Mail: ')) + profile.contact_email + '
' - end - unless profile.contact_phone.nil? - data << content_tag('strong', _('Phone(s): ')) + profile.contact_phone + '
' - end - unless profile.region.nil? - data << content_tag('strong', _('Location: ')) + profile.region.name + '
' - end - unless profile.address.nil? - data << content_tag('strong', _('Address: ')) + profile.address + '
' - end - unless profile.products.empty? - data << content_tag('strong', _('Products/Services: ')) + profile.products.map{|i| link_to(i.name, :controller => 'manage_products', :profile => profile.identifier, :action => 'show', :id => i.id)}.join(', ') + '
' - end - if profile.respond_to?(:distance) and !profile.distance.nil? - data << content_tag('strong', _('Distance: ')) + "%.2f%" % profile.distance + '
' - end - content_tag('table', - content_tag('tr', - content_tag('td', content_tag('div', profile_image(profile, :thumb), :class => 'profile-info-picture')) + - content_tag('td', content_tag('strong', link_to(profile.name, url_for(profile.url))) + '
' + data - ) - ), - :class => 'profile-info' - ) - end - - def display_product_info(product) - data = '' - unless product.price.nil? - data << content_tag('strong', _('Price: ')) + product.price + '
' - end - unless product.enterprise.nil? - data << content_tag('strong', _('Provider: ')) + link_to_profile(product.enterprise.name, product.enterprise.identifier) - end - unless product.product_category.nil? - data << content_tag('strong', _('Category: ')) + link_to(product.product_category.name, :controller => 'search', :action => 'assets', :asset => 'products', :product_category => product.product_category.id) - end - content_tag('table', - content_tag('tr', - content_tag('td', content_tag('div', image_tag(product.image ? product.image.public_filename(:thumb) : '/images/icons-app/product-default-pic-portrait.png'), :class => 'profile-info-picture')) + - content_tag('td', content_tag('strong', link_to(product.name, :controller => 'catalog', :profile => product.enterprise.identifier, :id => product.id)) + '
' + data) - ), :class => 'profile-info') - end - def product_categories_menu(asset, product_category, object_ids = nil) cats = ProductCategory.menu_categories(@product_category, environment) cats += cats.select { |c| c.children_count > 0 }.map(&:children).flatten diff --git a/app/views/map_balloon/product.rhtml b/app/views/map_balloon/product.rhtml new file mode 100644 index 0000000..c3a2f1e --- /dev/null +++ b/app/views/map_balloon/product.rhtml @@ -0,0 +1,3 @@ +
+ <%= render :partial => 'search/product', :locals => {:product => @product} %> +
diff --git a/app/views/map_balloon/profile.rhtml b/app/views/map_balloon/profile.rhtml new file mode 100644 index 0000000..97be683 --- /dev/null +++ b/app/views/map_balloon/profile.rhtml @@ -0,0 +1,28 @@ +
+ + + + + +
<%= profile_image(@profile, :thumb) %>
+ <%= link_to(@profile.name, url_for(@profile.url)) %>
+ <% unless @profile.contact_email.nil? %> + <%= _('E-Mail: ') + @profile.contact_email %>
+ <% end %> + <% unless @profile.contact_phone.nil? %> + <%= _('Phone(s): ') + @profile.contact_phone %>
+ <% end %> + <% unless @profile.region.nil? %> + <%= _('Location: ') + @profile.region.name %>
+ <% end %> + <% unless @profile.address.nil? %> + <%= _('Address: ') + @profile.address %>
+ <% end %> + <% unless @profile.products.empty? %> + <%= _('Products/Services: ') + @profile.products.map{|i| link_to(i.name, :controller => 'manage_products', :profile => @profile.identifier, :action => 'show', :id => i.id)}.join(', ') %>
+ <% end %> + <% if @profile.respond_to?(:distance) and !@profile.distance.nil? %> + <%= _('Distance: ') + "%.2f%" % @profile.distance %>
+ <% end %> +
+
diff --git a/app/views/search/_google_maps.rhtml b/app/views/search/_google_maps.rhtml index ea27e49..d2a7ff0 100644 --- a/app/views/search/_google_maps.rhtml +++ b/app/views/search/_google_maps.rhtml @@ -1,72 +1,34 @@ -<%= content_tag('script', '', :src => GoogleMaps.api_url(environment.default_hostname), :type => 'text/javascript') %> - - +
- diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml index c2841e7..bac132f 100644 --- a/app/views/search/_product.rhtml +++ b/app/views/search/_product.rhtml @@ -45,5 +45,5 @@
<%= property[:name] + ': ' + instance_eval(&property[:content]) %>
<% end %> -
+

diff --git a/config/routes.rb b/config/routes.rb index 34ee42b..440d00b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,6 +80,9 @@ ActionController::Routing::Routes.draw do |map| # contact map.contact 'contact/:profile/:action/:id', :controller => 'contact', :action => 'index', :id => /.*/, :profile => /#{Noosfero.identifier_format}/ + # map balloon + map.contact 'map_balloon/:action/:id', :controller => 'map_balloon', :id => /.*/ + # chat map.chat 'chat/:action/:id', :controller => 'chat' map.chat 'chat/:action', :controller => 'chat' diff --git a/public/javascripts/google_maps.js b/public/javascripts/google_maps.js new file mode 100644 index 0000000..797ea87 --- /dev/null +++ b/public/javascripts/google_maps.js @@ -0,0 +1,58 @@ +var map; +var mapPoints = {}; +var mapBounds; +var mapDefaultIcon = new GIcon(G_DEFAULT_ICON); + +function mapPutMarker(lat, lng, title, _icon, url) { + var point_str = lat + ":" + lng; + + var icon = _icon == null ? mapDefaultIcon : _icon; + + if (mapPoints[point_str]) { + lng += (Math.random() - 0.5) * 0.02; + lat += (Math.random() - 0.5) * 0.02; + } else { + mapPoints[point_str] = true; + } + + var point = new GLatLng(lat, lng); + var options = { 'title' : title, 'icon' : icon }; + var marker = new GMarker(point, options); + map.addOverlay(marker); + + GEvent.addListener(marker, 'click', function() { + if (url) { + jQuery.ajax({url: url, + success: function(data) { + map.openInfoWindowHtml(point, jQuery(data).html()); + } + }); + } + }); + mapBounds.extend(point); + + return marker; +} + +window.unload = function() { + GUnload(); +}; + +function mapLoad(initial_zoom) { + if (GBrowserIsCompatible()) { + map = new GMap2(document.getElementById("map")); + + new GKeyboardHandler(map); + map.addControl(new GLargeMapControl()); + map.addControl(new GMapTypeControl()); + + centerPoint = new GLatLng(-15.0, -50.1419); + map.setCenter(centerPoint, initial_zoom); + mapBounds = new GLatLngBounds(); + } +} + +function mapCenter(latlng) { + map.setZoom(map.getBoundsZoomLevel(mapBounds)); + map.setCenter(latlng ? latlng : mapBounds.getCenter()); +} -- libgit2 0.21.2