Skip to content

Commit

Permalink
Merge pull request #382 from RefugeRestrooms/develop
Browse files Browse the repository at this point in the history
Merge with all the map/preview changes/fixes
  • Loading branch information
mi-wood authored Oct 26, 2017
2 parents d8f9f52 + 9a960ef commit 807f0b2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
12 changes: 11 additions & 1 deletion app/assets/javascripts/maps.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var map;

function initMap(x, y, image){
function initMap(x, y, image, draggable, callback){
image = typeof image !== 'undefined' ? image : currentLocationImage;

// Draggable defaults to false
draggable = draggable || false;

//init map
var mapOptions = {
zoom: 15,
Expand All @@ -21,9 +24,12 @@ function initMap(x, y, image){

var currentLocation = new google.maps.Marker({
position: myLatLng,
draggable: draggable,
map: map,
icon: image
});

currentLocation.addListener("dragend", callback);
}


Expand Down Expand Up @@ -272,6 +278,10 @@ $(function(){
window.Maps = {
reloadMap: function(map) {
initMap(map.dataset.latitude, map.dataset.longitude, showMarkerImage);
},

reloadDraggable: function(map, callback) {
initMap(map.dataset.latitude, map.dataset.longitude, showMarkerImage, true, callback);
}
}
});
40 changes: 29 additions & 11 deletions app/assets/javascripts/views/restrooms/new.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,49 @@ class Refuge.Restrooms.NewRestroomForm
console.log result[0]
@_getNewForm(coords).then (data, textStatus) =>
console.log data
$('.form-container').html(data).hide().fadeIn()
@_requestNearbyRestrooms(coords)
@_updateMap(coords)
@_updateForm(coords, data, textStatus)


_bindPreviewButton: =>
@_previewButton.click (event) =>
# Show map
@_map.classList.remove("hidden")

form = @_form[0]
name = form.elements.restroom_name.value
street = form.elements.restroom_street.value
city = form.elements.restroom_city.value
state = form.elements.restroom_state.value
country = form.elements.restroom_country.value
address = "#{name}, #{street}, #{city}, #{state}, #{country}"
address = "#{street}, #{city}, #{state}, #{country}"

# Obtain coordinates
@_geocoder.geocodeSearchString(address).then (coords) =>
@_updateMap(coords)


_rebind: =>
@_map = $("#mapArea").get(0)
@_previewButton = $(".preview-btn")
@_guessButton = $(".guess-btn")

@_bindEvents()

# Rebind form
@_form = $('form.simple_form')


_updateMap: (coords) =>
# Show map
@_map.classList.remove("hidden")

@_map.dataset.latitude = coords.lat
@_map.dataset.longitude = coords.long
Maps.reloadMap(@_map)
Maps.reloadDraggable(@_map, @_onDrag)

# Callback for map marker 'dragend' event
_onDrag: (event) =>
coords =
lat: event.latLng.lat(),
long: event.latLng.lng()
@_getNewForm(coords).then (data, textStatus) =>
@_updateForm(coords, data, textStatus)

_getNewForm: (coords) =>
$.ajax
Expand All @@ -67,9 +82,12 @@ class Refuge.Restrooms.NewRestroomForm
restroom:
latitude: coords.lat
longitude: coords.long
success: (data, textStatus) ->
# $('.new-restrooms-form-container').html(data)

_updateForm: (coords, data, textStatus) =>
$('.form-container').html(data).hide().fadeIn()
@_rebind()
@_requestNearbyRestrooms(coords)
@_updateMap(coords)

_requestNearbyRestrooms: (coords) ->
$.ajax
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ input {
border-radius: 0;
}

.form-control{
color: black;
}

h1 {
padding: 5px;
text-align: center;
Expand Down
2 changes: 1 addition & 1 deletion app/models/restroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Restroom < ApplicationRecord
obj.street = geo.address.split(',').first
obj.city = geo.city
obj.state = geo.state
obj.country = geo.country
obj.country = geo.country_code
end
end

Expand Down

0 comments on commit 807f0b2

Please sign in to comment.