From 80994fa76b0fad68430f795fc6f0fc5cf4951fc0 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 7 Mar 2011 00:56:32 -0800 Subject: [PATCH] Create adoption form --- app/views/layouts/application.html.erb | 26 +++++++++++++++++--------- app/views/main/_adoption_form.html.erb | 10 ++++++++++ app/views/main/_combo_form.html.erb | 5 +---- config/routes.rb | 1 + 4 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 app/views/main/_adoption_form.html.erb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d6a9feb..cd04c93 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -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(); } }); } @@ -186,16 +190,20 @@ openInfoWindow = infoWindow; }); } -<% @hydrants.each do |hydrant| %> + <% @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 %> + <% if user = hydrant.user %> contentString = '<%= render(:partial => "user_profile", :locals => {:user => user}).gsub("\n", "") %>' - <% else %> - contentString = formString; - <% end %> + <% else %> + <% if user_signed_in? %> + contentString = '

Adopt this Hydrant

<%= render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>' + <% else %> + contentString = '

Adopt this Hydrant

<%= render(:partial => "combo_form").gsub("\n", "") + render(:partial => "adoption_form", :locals => {:hydrant => hydrant}).gsub("\n", "") %>' + <% end %> + <% end %> addMarker(point, color, contentString); -<% end %> + <% end %> $('#location_form').submit(function() { if($('#address').val() === '') { $('#address').focus(); diff --git a/app/views/main/_adoption_form.html.erb b/app/views/main/_adoption_form.html.erb new file mode 100644 index 0000000..9f9fbcf --- /dev/null +++ b/app/views/main/_adoption_form.html.erb @@ -0,0 +1,10 @@ +<% style = user_signed_in? ? {} : {:style => "display: none;"}%> +<%= form_for hydrant, :html => {:class => "adoption_form"}.merge(style) do |f| %> +
+ <%= 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" %> +

By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.

+
+<% end %> diff --git a/app/views/main/_combo_form.html.erb b/app/views/main/_combo_form.html.erb index 9d1a1a2..fe6843b 100644 --- a/app/views/main/_combo_form.html.erb +++ b/app/views/main/_combo_form.html.erb @@ -1,5 +1,3 @@ -
-

Adopt this Hydrant

<%= form_for :user, :html => {:class => "combo_form"} do |f| %>
<%= 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" %> -

By signing up you accept the <%= link_to "Terms of Service", "#", :tabindex => 9 %>.

+

By signing up, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 9 %>.

<% end %> -
diff --git a/config/routes.rb b/config/routes.rb index 49653a7..7ae29ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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