adopt-a-hydrant/app/views/layouts/application.html.erb

153 lines
6.0 KiB
Plaintext

<!DOCTYPE html>
<html>
<head>
<title>Adopt a Hydrant</title>
<%= stylesheet_link_tag "main" %>
<%= javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false" %>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" %>
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" %>
<%= javascript_include_tag "https://github.com/scottschiller/Snowstorm/raw/master/snowstorm-min.js" %>
<script type="text/javascript">
$(function() {
var map;
var latlng = new google.maps.LatLng(<%= @lat %>, <%= @lng %>);
var myOptions = {
mapTypeControl: false,
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.BOTTOM_CENTER
},
zoom: <%= @zoom %>,
zoomControl: false,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var openInfoWindow;
var formString = '<%= render(:partial => "combo_form").gsub("\n", "") %>'
function addMarker(point, color, contentString) {
var image = new google.maps.MarkerImage(color,
new google.maps.Size(27.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(13.0, 18.0)
);
var shadow = new google.maps.MarkerImage('/images/markers/shadow.png',
new google.maps.Size(46.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(13.0, 18.0)
);
var marker = new google.maps.Marker({
position: point,
map: map,
icon: image,
shadow: shadow
});
var infoWindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', function() {
if(openInfoWindow) {
openInfoWindow.close();
}
infoWindow.open(map, marker);
$('.combo_form').data('state', 'new');
$('.combo_form').submit(function() {
var errors = []
if(!/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]+$/.test($('.email').val())) {
errors.push($('.email'));
$('.email_label').addClass('error', 500);
$('.email').addClass('error', 500);
} else {
$('.email_label').removeClass('error', 500);
$('.email').removeClass('error', 500);
}
if($(this).data('state') === 'new') {
if($('.name').val() === '') {
errors.push($('.name'));
$('.name_label').addClass('error', 500);
$('.name').addClass('error', 500);
} else {
$('.name_label').removeClass('error', 500);
$('.name').removeClass('error', 500);
}
if($('.choose_password').val() === '') {
errors.push($('.choose_password'));
$('.choose_password_label').addClass('error', 500);
$('.choose_password').addClass('error', 500);
} else {
$('.choose_password_label').removeClass('error', 500);
$('.choose_password').removeClass('error', 500);
}
} else if($(this).data('state') === 'existing') {
if($('.password').val() === '') {
errors.push($('.password'));
$('.password_label').addClass('error', 500);
$('.password').addClass('error', 500);
} else {
$('.password_label').removeClass('error', 500);
$('.password').removeClass('error', 500);
}
} else if($(this).data('state') === 'forgot_password') {
}
if(errors.length > 0) {
errors[0].focus();
} else {
}
return false;
});
openInfoWindow = infoWindow;
});
}
<% @hydrants.each do |hydrant| %>
point = new google.maps.LatLng(<%= hydrant.lat %>, <%= hydrant.lng %>);
color = <%= hydrant.user_id ? "'/images/markers/green.png'" : "'/images/markers/red.png'" %>;
<% if user = hydrant.user %>
contentString = '<%= render(:partial => "user_profile", :locals => {:user => user}).gsub("\n", "") %>'
<% else %>
contentString = formString;
<% end %>
addMarker(point, color, contentString);
<% end %>
$('#location_form').submit(function() {
if($('#address').val() === '') {
$('#address').focus();
$('#address_label').addClass('error', 500);
$('#address').addClass('error', 500);
return false;
}
});
$('.box input[type="radio"]').live('click', function() {
var self = $(this);
if('new' == self.val()) {
$('.forgot_password_fields').slideUp();
$('.account_existing_fields').slideUp();
$('.account_new_fields').slideDown();
$('.combo_form').data('state', 'new');
} else if('existing' == self.val()) {
$('.account_new_fields').slideUp();
$('.account_existing_fields').slideDown(function() {
$('.combo_form').data('state', 'existing');
$('.forgot_password').click(function() {
$('.account_existing_fields').slideUp();
$('.forgot_password_fields').slideDown(function() {
$('.remembered_password').click(function() {
$('.forgot_password_fields').slideUp();
$('.account_existing_fields').slideDown();
$('.combo_form').data('state', 'existing');
});
});
$('.combo_form').data('state', 'forgot_password');
});
});
}
});
})
</script>
<%= csrf_meta_tag %>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<%= yield -%>
</body>
</html>