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

277 lines
12 KiB
Plaintext
Raw Normal View History

2011-02-14 18:28:51 +00:00
<!DOCTYPE html>
<html>
2011-02-14 18:49:00 +00:00
<head>
2011-02-23 22:24:08 +00:00
<title>Adopt a Hydrant</title>
2011-02-14 18:49:00 +00:00
<%= stylesheet_link_tag "main" %>
<%= javascript_include_tag "http://maps.google.com/maps/api/js?sensor=false" %>
2011-03-05 01:43:25 +00:00
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" %>
2011-03-05 04:22:03 +00:00
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js" %>
2011-03-04 23:21:08 +00:00
<%= javascript_include_tag "https://github.com/scottschiller/Snowstorm/raw/master/snowstorm-min.js" %>
2011-02-25 21:34:01 +00:00
<script type="text/javascript">
$(function() {
var map;
var latlng = new google.maps.LatLng(<%= @lat %>, <%= @lng %>);
var myOptions = {
2011-03-01 08:20:55 +00:00
mapTypeControl: false,
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.BOTTOM_CENTER
},
2011-02-25 21:34:01 +00:00
zoom: <%= @zoom %>,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
2011-03-08 08:44:27 +00:00
comboFormString = '<%= render(:partial => "combo_form").gsub("\n", "") %>';
2011-03-01 05:11:07 +00:00
var openInfoWindow;
2011-03-01 08:20:55 +00:00
function addMarker(point, color, contentString) {
var image = new google.maps.MarkerImage(color,
2011-03-03 18:26:41 +00:00
new google.maps.Size(27.0, 37.0),
2011-03-01 08:20:55 +00:00
new google.maps.Point(0, 0),
2011-03-03 18:26:41 +00:00
new google.maps.Point(13.0, 18.0)
2011-03-01 08:20:55 +00:00
);
var shadow = new google.maps.MarkerImage('/images/markers/shadow.png',
2011-03-03 18:26:41 +00:00
new google.maps.Size(46.0, 37.0),
2011-03-01 08:20:55 +00:00
new google.maps.Point(0, 0),
2011-03-03 18:26:41 +00:00
new google.maps.Point(13.0, 18.0)
2011-03-01 08:20:55 +00:00
);
var marker = new google.maps.Marker({
position: point,
map: map,
icon: image,
shadow: shadow
});
var infoWindow = new google.maps.InfoWindow({
2011-03-08 08:44:27 +00:00
content: contentString,
maxWidth: 350
2011-03-01 08:20:55 +00:00
});
google.maps.event.addListener(marker, 'click', function() {
2011-03-08 08:44:27 +00:00
if(openInfoWindow) {
2011-03-01 08:20:55 +00:00
openInfoWindow.close();
}
infoWindow.open(map, marker);
2011-03-08 08:44:27 +00:00
$('.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;
});
2011-03-05 04:22:03 +00:00
$('.combo_form').submit(function() {
2011-03-05 16:38:44 +00:00
var errors = []
2011-03-07 07:56:55 +00:00
if(!/[\w\.%\+\-]+@[\w\-]+\.+[\w]{2,}/.test($('#user_email').val())) {
2011-03-06 18:28:00 +00:00
errors.push($('#user_email'));
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
2011-03-05 16:38:44 +00:00
} else {
2011-03-07 02:40:29 +00:00
$('#user_email_label').removeClass('error');
$('#user_email').removeClass('error');
2011-03-05 16:38:44 +00:00
}
2011-03-07 08:56:32 +00:00
if(!$(this).data('state') || $(this).data('state') === 'user_new') {
2011-03-06 18:28:00 +00:00
if($('#user_name').val() === '') {
errors.push($('#user_name'));
$('#user_name_label').addClass('error', 500);
$('#user_name').addClass('error', 500);
2011-03-05 04:22:03 +00:00
} else {
2011-03-07 02:40:29 +00:00
$('#user_name_label').removeClass('error');
$('#user_name').removeClass('error');
2011-03-05 04:22:03 +00:00
}
2011-03-06 18:28:00 +00:00
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);
2011-03-05 16:38:44 +00:00
} else {
2011-03-07 02:40:29 +00:00
$('#user_password_confirmation_label').removeClass('error');
$('#user_password_confirmation').removeClass('error');
2011-03-05 16:38:44 +00:00
}
2011-03-05 17:22:42 +00:00
if(errors.length > 0) {
errors[0].focus();
} else {
2011-03-06 18:28:00 +00:00
$.post('<%= user_registration_path :format => "json" %>', {
2011-03-08 08:44:27 +00:00
'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()
2011-03-06 18:28:00 +00:00
}
}, function(data) {
2011-03-07 02:40:29 +00:00
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 {
2011-03-07 08:56:32 +00:00
$('.combo_form').slideUp();
2011-03-08 08:44:27 +00:00
$('.adoption_form').slideDown(function() {
$('#hydrant_user_id').val(data.user.id);
});
2011-03-07 02:40:29 +00:00
}
2011-03-05 17:22:42 +00:00
});
}
2011-03-06 18:28:00 +00:00
} else if($(this).data('state') === 'user_existing') {
2011-03-07 02:40:29 +00:00
if($('#user_password').val().length < 6 || $('#user_password').val().length > 20) {
2011-03-06 18:28:00 +00:00
errors.push($('#user_password'));
$('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500);
2011-03-05 04:22:03 +00:00
} else {
2011-03-07 02:40:29 +00:00
$('#user_password_label').removeClass('error');
$('#user_password').removeClass('error');
2011-03-05 04:22:03 +00:00
}
2011-03-05 17:22:42 +00:00
if(errors.length > 0) {
errors[0].focus();
} else {
2011-03-07 01:46:06 +00:00
$.post('<%= user_session_path :format => "json" %>', {
2011-03-08 08:44:27 +00:00
'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()
2011-03-07 01:46:06 +00:00
}
}, function(data) {
2011-03-07 02:40:29 +00:00
if(data.errors) {
$('#user_password').focus();
$('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500);
} else {
2011-03-07 08:56:32 +00:00
$('.combo_form').slideUp();
2011-03-08 08:44:27 +00:00
$('.adoption_form').slideDown(function() {
$('#hydrant_user_id').val(data.user.id);
});
2011-03-07 02:40:29 +00:00
}
2011-03-05 17:22:42 +00:00
});
}
2011-03-06 18:28:00 +00:00
} else if($(this).data('state') === 'user_forgot_password') {
2011-03-05 17:22:42 +00:00
if(errors.length > 0) {
errors[0].focus();
} else {
2011-03-07 02:32:11 +00:00
$.post('<%= user_password_path :format => "json" %>', {
2011-03-08 08:44:27 +00:00
'commit': $('#user_forgot_password_submit').val(),
'utf8': '✓',
'authenticity_token': $('input[name="authenticity_token"]').val(),
'user': {
'email': $('#user_email').val()
2011-03-07 02:32:11 +00:00
}
}, function(data) {
2011-03-07 02:40:29 +00:00
if(data.errors) {
$('#user_email').focus();
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
} else {
2011-03-07 08:56:32 +00:00
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideDown();
2011-03-07 02:40:29 +00:00
}
2011-03-05 17:22:42 +00:00
});
}
2011-03-05 04:22:03 +00:00
}
return false;
});
2011-03-01 08:20:55 +00:00
openInfoWindow = infoWindow;
});
}
2011-03-07 08:56:32 +00:00
<% @hydrants.each do |hydrant| %>
2011-03-01 08:20:55 +00:00
point = new google.maps.LatLng(<%= hydrant.lat %>, <%= hydrant.lng %>);
color = <%= hydrant.user_id ? "'/images/markers/green.png'" : "'/images/markers/red.png'" %>;
2011-03-07 08:56:32 +00:00
<% if user = hydrant.user %>
2011-03-01 08:20:55 +00:00
contentString = '<%= render(:partial => "user_profile", :locals => {:user => user}).gsub("\n", "") %>'
2011-03-07 08:56:32 +00:00
<% else %>
<% if user_signed_in? %>
contentString = '<h2>Adopt this Hydrant</h2><%= render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>'
<% else %>
2011-03-08 08:44:27 +00:00
contentString = '<h2>Adopt this Hydrant</h2>' + comboFormString + '<%= render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>'
2011-03-07 08:56:32 +00:00
<% end %>
<% end %>
2011-03-01 08:20:55 +00:00
addMarker(point, color, contentString);
2011-03-07 08:56:32 +00:00
<% end %>
2011-03-05 01:43:25 +00:00
$('#location_form').submit(function() {
2011-03-05 04:22:03 +00:00
if($('#address').val() === '') {
$('#address').focus();
2011-03-05 01:43:25 +00:00
$('#address_label').addClass('error', 500);
$('#address').addClass('error', 500);
return false;
}
});
2011-03-06 18:28:00 +00:00
$('.combo_form input[type="radio"]').live('click', function() {
2011-03-01 04:13:31 +00:00
var self = $(this);
if('new' == self.val()) {
2011-03-06 18:28:00 +00:00
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideUp();
$('#user_new_fields').slideDown();
$('.combo_form').data('state', 'user_new');
2011-03-01 04:13:31 +00:00
} else if('existing' == self.val()) {
2011-03-06 18:28:00 +00:00
$('#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');
2011-03-01 04:13:31 +00:00
});
});
2011-03-06 18:28:00 +00:00
$('.combo_form').data('state', 'user_forgot_password');
2011-03-01 04:13:31 +00:00
});
});
}
});
2011-02-25 21:34:01 +00:00
})
</script>
2011-02-14 18:49:00 +00:00
<%= csrf_meta_tag %>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
2011-02-14 20:27:18 +00:00
<body>
2011-02-14 18:49:00 +00:00
<%= yield -%>
</body>
2011-02-14 18:28:51 +00:00
</html>