Create adoption form

This commit is contained in:
Erik Michaels-Ober 2011-03-07 00:56:32 -08:00
parent 428995778d
commit 80994fa76b
4 changed files with 29 additions and 13 deletions

View File

@ -24,7 +24,6 @@
};
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),
@ -50,7 +49,6 @@
openInfoWindow.close();
}
infoWindow.open(map, marker);
$('.combo_form').data('state', 'user_new');
$('.combo_form').submit(function() {
var errors = []
if(!/[\w\.%\+\-]+@[\w\-]+\.+[\w]{2,}/.test($('#user_email').val())) {
@ -61,7 +59,7 @@
$('#user_email_label').removeClass('error');
$('#user_email').removeClass('error');
}
if($(this).data('state') === 'user_new') {
if(!$(this).data('state') || $(this).data('state') === 'user_new') {
if($('#user_name').val() === '') {
errors.push($('#user_name'));
$('#user_name_label').addClass('error', 500);
@ -128,6 +126,8 @@
}
errors[0].focus();
} else {
$('.combo_form').slideUp();
$('.adoption_form').slideDown();
}
});
}
@ -157,6 +157,8 @@
$('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500);
} else {
$('.combo_form').slideUp();
$('.adoption_form').slideDown();
}
});
}
@ -177,6 +179,8 @@
$('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500);
} else {
$('#user_forgot_password_fields').slideUp();
$('#user_existing_fields').slideDown();
}
});
}
@ -192,7 +196,11 @@
<% if user = hydrant.user %>
contentString = '<%= render(:partial => "user_profile", :locals => {:user => user}).gsub("\n", "") %>'
<% else %>
contentString = formString;
<% 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><%= render(:partial => "combo_form").gsub("\n", "") + render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>'
<% end %>
<% end %>
addMarker(point, color, contentString);
<% end %>

View File

@ -0,0 +1,10 @@
<% style = user_signed_in? ? {} : {:style => "display: none;"}%>
<%= form_for hydrant, :html => {:class => "adoption_form"}.merge(style) do |f| %>
<div id="adoption_fields">
<%= f.hidden_field "user_id", :value => (user_signed_in? ? current_user.id : nil) %>
<%= f.label "name", "Name your hydrant", :id => "hydrant_name_label" %>
<%= f.text_field "name", :tabindex => 1 %>
<%= f.submit "Adopt!", :tabindex => 2, :id => "user_new_submit" %>
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
</div>
<% end %>

View File

@ -1,5 +1,3 @@
<div class="box">
<h2>Adopt this Hydrant</h2>
<%= form_for :user, :html => {:class => "combo_form"} do |f| %>
<div id="common_fields">
<%= f.label "email", "Email address", :id => "user_email_label" %>
@ -19,7 +17,7 @@
<%= f.label "password_confirmation", "Choose a password", :id => "user_password_confirmation_label" %>
<%= f.password_field "password_confirmation", :tabindex => 7 %>
<%= f.submit "Sign up", :tabindex => 8, :id => "user_new_submit" %>
<p>By signing up you accept the <%= link_to "Terms of Service", "#", :tabindex => 9 %>.</p>
<p>By signing up, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 9 %>.</p>
</div>
<div id="user_existing_fields" style="display: none;">
<%= f.label "password", "Password", :id => "user_password_label" %>
@ -33,4 +31,3 @@
<p><%= link_to "Never mind. I remembered my password.", "#", :id => "user_remembered_password", :tabindex => 0 %></p>
</div>
<% end %>
</div>

View File

@ -5,6 +5,7 @@ AdoptAHydrant::Application.routes.draw do
:sessions => 'sessions',
}
resource :user
resource :hydrant
get 'sitemap(.format)' => 'sitemaps#index', :as => 'sitemap'
root :to => 'main#index'
end