Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. ## index.html.erb
  2. <h1>Listing restaurants</h1>
  3.  
  4. <script type="text/javascript">
  5. google.load("maps", "2.x");
  6.  
  7. // Call this function when the page has been loaded
  8. function initialize() {
  9. var map = getMap(<%= @location.lat %>, <%= @location.lng %>);
  10. var markerIcon = getMarkerIcon();
  11.  
  12. var marker = new GMarker(map.getCenter(), {
  13. draggable: true, bouncy: false, icon: markerIcon});
  14.  
  15. map.addOverlay(marker);
  16.  
  17. var tinyIcon = getTinyIcon();
  18.  
  19. // Set up our GMarkerOptions object literal
  20. markerOptions = { icon:tinyIcon };
  21.  
  22. <% for restaurant in @restaurants %>
  23. point = new google.maps.LatLng(<%= restaurant.lat %>, <%= restaurant.lng %>);
  24. icon = new GMarker(point, markerOptions);
  25. map.addOverlay(icon);
  26.  
  27. <% unless restaurant.menu_url.nil? || restaurant.menu_url.empty? %>
  28. GEvent.addListener(icon, "click", function() {
  29. MOOdalBox.open(
  30. "/restaurants/<%=restaurant.id%>/menu",
  31. "<%=restaurant.name %>",
  32. "500 900"
  33. );
  34. });
  35.  
  36. <% end %>
  37. <% end %>
  38.  
  39. GEvent.addListener(marker, "dragend", function() {
  40. var latlng = marker.getLatLng();
  41.  
  42. var jSonRequest = new Json.Remote("/location/move", {
  43. onComplete: function(currentLocation){
  44. window.location.reload(true);
  45. }}).send({'lat': latlng.lat(), 'lng': latlng.lng()});
  46. });
  47. }
  48. google.setOnLoadCallback(initialize);
  49. </script>
  50.  
  51. <div id="map"></div>
  52.  
  53. <table>
  54. <thead>
  55. <tr>
  56. <th>Distance</th>
  57. <th>Name</th>
  58. <th>Address</th>
  59. <th></th>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <% for @restaurant in @restaurants %>
  64. <tr>
  65. <td><%= "%.0f" % (@restaurant.distance_to(@location)*1000) %> meter</td>
  66. <td><%= link_to @restaurant.name, @restaurant %></td>
  67. <td><%=h @restaurant.address %></td>
  68. <td>
  69. <% if @restaurant.menu_url.nil? || @restaurant.menu_url.empty? %>
  70. <%= link_to 'Web', @restaurant.website if @restaurant.website %>
  71. <% else %>
  72. <%= link_to 'Menu', menu_restaurant_path(@restaurant),
  73. :rel => 'moodalbox 500 900',
  74. :title => @restaurant.name %>
  75. <% end %>
  76. </td>
  77. </tr>
  78. <% end %>
  79. </tbody>
  80. </table>
  81.  
  82. <br />
  83.  
  84. <%= link_to 'New restaurant', new_restaurant_path %>
Add Comment
Please, Sign In to add comment