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

277 lines
12 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 %>,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
comboFormString = '<%= render(:partial => "combo_form").gsub("\n", "") %>';
var openInfoWindow;
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,
maxWidth: 350
});
google.maps.event.addListener(marker, 'click', function() {
if(openInfoWindow) {
openInfoWindow.close();
}
infoWindow.open(map, marker);
$('.adoption_form').submit(function() {
$.post('<%= hydrant_path :format => "json" %>', {
'id': $('#hydrant_id').val(),
'commit': $('#adoption_form_submit').val(),
'utf8': '✓',
'authenticity_token': $('input[name="authenticity_token"]').val(),
'_method': 'put',
'hydrant': {
'user_id': $('#hydrant_user_id').val() || <%= user_signed_in? ? current_user.id : false %>,
'name': $('#hydrant_name').val()
}
}, function(data) {
image = new google.maps.MarkerImage('/images/markers/green.png',
new google.maps.Size(27.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(13.0, 18.0)
);
marker.setIcon(image);
marker.setAnimation(google.maps.Animation.BOUNCE);
});
return false;
});
$('.combo_form').submit(function() {
var errors = []
if(!/[\w\.%\+\-]+@[\w\-]+\.+[\w]{2,}/.test($('#user_email').val())) {
errors.push($('#user_email'));
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
} else {
$('#user_email_label').removeClass('error');
$('#user_email').removeClass('error');
}
if(!$(this).data('state') || $(this).data('state') === 'user_new') {
if($('#user_name').val() === '') {
errors.push($('#user_name'));
$('#user_name_label').addClass('error', 500);
$('#user_name').addClass('error', 500);
} else {
$('#user_name_label').removeClass('error');
$('#user_name').removeClass('error');
}
if($('#user_password_confirmation').val().length < 6 || $('#user_password_confirmation').val().length > 20) {
errors.push($('#user_password_confirmation'));
$('#user_password_confirmation_label').addClass('error', 500);
$('#user_password_confirmation').addClass('error', 500);
} else {
$('#user_password_confirmation_label').removeClass('error');
$('#user_password_confirmation').removeClass('error');
}
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_registration_path :format => "json" %>', {
'commit': $('#user_new_submit').val(),
'utf8': '✓',
'authenticity_token': $('input[name="authenticity_token"]').val(),
'user': {
'email': $('#user_email').val(),
'name': $('#user_name').val(),
'organization': $('#user_organization').val(),
'voice_number': $('#user_voice_number').val(),
'sms_number': $('#user_sms_number').val(),
'password': $('#user_password_confirmation').val(),
'password_confirmation': $('#user_password_confirmation').val()
}
}, function(data) {
if(data.errors) {
if(data.errors.email) {
errors.push($('#user_email'));
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
}
if(data.errors.name) {
errors.push($('#user_name'));
$('#user_name_label').addClass('error', 500);
$('#user_name').addClass('error', 500);
}
if(data.errors.organization) {
errors.push($('#user_organization'));
$('#user_organization_label').addClass('error', 500);
$('#user_organization').addClass('error', 500);
}
if(data.errors.voice_number) {
errors.push($('#user_voice_number'));
$('#user_voice_number_label').addClass('error', 500);
$('#user_voice_number').addClass('error', 500);
}
if(data.errors.sms_number) {
errors.push($('#user_sms_number'));
$('#user_sms_number_label').addClass('error', 500);
$('#user_sms_number').addClass('error', 500);
}
if(data.errors.password) {
errors.push($('#user_password_confirmation'));
$('#user_password_confirmation_label').addClass('error', 500);
$('#user_password_confirmation').addClass('error', 500);
}
errors[0].focus();
} else {
$('.combo_form').slideUp();
$('.adoption_form').slideDown(function() {
$('#hydrant_user_id').val(data.user.id);
});
}
});
}
} else if($(this).data('state') === 'user_existing') {
if($('#user_password').val().length < 6 || $('#user_password').val().length > 20) {
errors.push($('#user_password'));
$('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500);
} else {
$('#user_password_label').removeClass('error');
$('#user_password').removeClass('error');
}
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_session_path :format => "json" %>', {
'commit': $('#user_existing_submit').val(),
'utf8': '✓',
'authenticity_token': $('input[name="authenticity_token"]').val(),
'user': {
'email': $('#user_email').val(),
'password': $('#user_password').val(),
'remember_me': $('#user_remember_me').val()
}
}, function(data) {
if(data.errors) {
$('#user_password').focus();
$('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500);
} else {
$('.combo_form').slideUp();
$('.adoption_form').slideDown(function() {
$('#hydrant_user_id').val(data.user.id);
});
}
});
}
} else if($(this).data('state') === 'user_forgot_password') {
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_password_path :format => "json" %>', {
'commit': $('#user_forgot_password_submit').val(),
'utf8': '✓',
'authenticity_token': $('input[name="authenticity_token"]').val(),
'user': {
'email': $('#user_email').val()
}
}, function(data) {
if(data.errors) {
$('#user_email').focus();
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
} else {
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideDown();
}
});
}
}
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 %>
<% if user_signed_in? %>
contentString = '<h2>Adopt this Hydrant</h2><%= render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>'
<% else %>
contentString = '<h2>Adopt this Hydrant</h2>' + comboFormString + '<%= render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>'
<% end %>
<% 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;
}
});
$('.combo_form input[type="radio"]').live('click', function() {
var self = $(this);
if('new' == self.val()) {
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideUp();
$('#user_new_fields').slideDown();
$('.combo_form').data('state', 'user_new');
} else if('existing' == self.val()) {
$('#user_new_fields').slideUp();
$('#user_existing_fields').slideDown(function() {
$('.combo_form').data('state', 'user_existing');
$('#user_forgot_password_link').click(function() {
$('#user_existing_fields').slideUp();
$('#user_forgot_password_fields').slideDown(function() {
$('#user_remembered_password').click(function() {
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideDown();
$('.combo_form').data('state', 'user_existing');
});
});
$('.combo_form').data('state', 'user_forgot_password');
});
});
}
});
})
</script>
<%= csrf_meta_tag %>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<%= yield -%>
</body>
</html>