Commit 9296f29daf6bcc17624b7250b1a578456618c9d4

Authored by AntonioTerceiro
1 parent cbfac6a3

ActionItem265: actually displaying items in map


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1927 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/helpers/search_helper.rb
... ... @@ -16,13 +16,20 @@ module SearchHelper
16 16 end
17 17  
18 18 def display_results
19   - partial =
  19 + data =
20 20 if params[:display] == 'map'
21   - 'google_maps'
  21 + {
  22 + :partial => 'google_maps',
  23 + :toggle => link_to(_('Display in list'), params.merge(:display => 'list'))
  24 + }
22 25 else
23   - 'display_results'
  26 + {
  27 + :partial => 'display_results',
  28 + :toggle => link_to(_('Display in map'), params.merge(:display => 'map'))
  29 + }
24 30 end
25   - render :partial => partial
  31 +
  32 + data[:toggle] + (render :partial => data[:partial])
26 33 end
27 34  
28 35 end
... ...
app/views/search/_display_results.rhtml
1   -<div style='float: left;'>
2   - <%= link_to _('Display in map'), :display => 'map' %>
3   -</div>
4   -
5 1 <div id="search-results" class="<%= 'only-one-result-box' if @results.size == 1 %>">
6 2  
7 3 <%
... ...
app/views/search/_google_maps.rhtml
1   -<div style='float: left;'>
2   - <%= link_to _('Display in list'), :display => 'list' %>
3   -</div>
4   -
5 1 <%= content_tag('script', '', :src => GoogleMaps.api_url, :type => 'text/javascript') %>
6 2  
7 3  
... ... @@ -10,14 +6,30 @@
10 6 </div>
11 7  
12 8 <script type='text/javascript'>
13   -if (GBrowserIsCompatible()) {
14   - var map = new GMap2(document.getElementById("map"));
15   - map.setCenter(new GLatLng(-15.0, -50.1419), 4);
16 9  
17   - point = new GLatLng(-15, -40);
18   - marker = new GMarker(point);
  10 +function putMarker(lat, lng, title) {
  11 + var point = new GLatLng(lat, lng);
  12 + var options = { 'title' : title };
  13 + var marker = new GMarker(point, options);
19 14 map.addOverlay(marker);
20   - GEvent.addListener(marker, 'click', function() { marker.openInfoWindow("teste") });
  15 + GEvent.addListener(marker, 'click', function() {
  16 + map.openInfoWindowHtml(point, title);
  17 + });
  18 +}
21 19  
  20 +if (GBrowserIsCompatible()) {
  21 + var map = new GMap2(document.getElementById("map"));
  22 + map.setCenter(new GLatLng(-15.0, -50.1419), 4);
  23 +<%
  24 + @results.each do |name,results|
  25 + results.each do |item|
  26 + if item.lat && item.lng
  27 + %>
  28 + putMarker(<%= item.lat.to_json %>, <%= item.lng.to_json %>, <%= item.name.to_json %>);
  29 + <%
  30 + end
  31 + end
  32 + end
  33 +%>
22 34 }
23 35 </script>
... ...