From 4f0fe7d4284caaf0bc43d9b3b18d1002cc144a20 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Sat, 5 Mar 2011 09:22:42 -0800 Subject: [PATCH] Stubs for AJAX posts --- app/controllers/main_controller.rb | 35 +++++++++++++++++++ app/controllers/welcome_controller.rb | 14 -------- app/views/layouts/application.html.erb | 22 +++++++++--- .../{welcome => main}/_combo_form.html.erb | 0 .../{welcome => main}/_user_profile.html.erb | 0 app/views/{welcome => main}/index.html.erb | 0 config/routes.rb | 7 ++-- 7 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 app/controllers/main_controller.rb delete mode 100644 app/controllers/welcome_controller.rb rename app/views/{welcome => main}/_combo_form.html.erb (100%) rename app/views/{welcome => main}/_user_profile.html.erb (100%) rename app/views/{welcome => main}/index.html.erb (100%) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb new file mode 100644 index 0000000..ca4b865 --- /dev/null +++ b/app/controllers/main_controller.rb @@ -0,0 +1,35 @@ +class MainController < ApplicationController + def index + @zoom = 15 + # Default coordinates: Boston center + @lat, @lng = 42.358431, -71.059773 + @hydrants = [] + address, city_state = params[:address], params[:city_state] + if address && city_state + @zoom = 18 + @lat, @lng = Address.find_lat_lng("#{address}, #{city_state}") + @hydrants = Hydrant.find_closest(@lat, @lng) + end + end + + def sign_up + @data = {"email" => params[:email], "name" => params[:name]} + respond_to do |format| + format.json{render :json => @data} + end + end + + def sign_in + @data = {"email" => params[:email]} + respond_to do |format| + format.json{render :json => @data} + end + end + + def forgot_password + @data = {"email" => params[:email]} + respond_to do |format| + format.json{render :json => @data} + end + end +end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb deleted file mode 100644 index 3504791..0000000 --- a/app/controllers/welcome_controller.rb +++ /dev/null @@ -1,14 +0,0 @@ -class WelcomeController < ApplicationController - def index - @zoom = 15 - # Default coordinates: Boston center - @lat, @lng = 42.358431, -71.059773 - @hydrants = [] - address, city_state = params[:address], params[:city_state] - if address && city_state - @zoom = 18 - @lat, @lng = Address.find_lat_lng("#{address}, #{city_state}") - @hydrants = Hydrant.find_closest(@lat, @lng) - end - end -end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8e3d50e..c406b5e 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -78,6 +78,12 @@ $('.choose_password_label').removeClass('error', 500); $('.choose_password').removeClass('error', 500); } + if(errors.length > 0) { + errors[0].focus(); + } else { + $.post('/sign_up.json', $(this).serialize(), function(data) { + }); + } } else if($(this).data('state') === 'existing') { if($('.password').val() === '') { errors.push($('.password')); @@ -87,11 +93,19 @@ $('.password_label').removeClass('error', 500); $('.password').removeClass('error', 500); } + if(errors.length > 0) { + errors[0].focus(); + } else { + $.post('/sign_in.json', $(this).serialize(), function(data) { + }); + } } else if($(this).data('state') === 'forgot_password') { - } - if(errors.length > 0) { - errors[0].focus(); - } else { + if(errors.length > 0) { + errors[0].focus(); + } else { + $.post('/forgot_password.json', $(this).serialize(), function(data) { + }); + } } return false; }); diff --git a/app/views/welcome/_combo_form.html.erb b/app/views/main/_combo_form.html.erb similarity index 100% rename from app/views/welcome/_combo_form.html.erb rename to app/views/main/_combo_form.html.erb diff --git a/app/views/welcome/_user_profile.html.erb b/app/views/main/_user_profile.html.erb similarity index 100% rename from app/views/welcome/_user_profile.html.erb rename to app/views/main/_user_profile.html.erb diff --git a/app/views/welcome/index.html.erb b/app/views/main/index.html.erb similarity index 100% rename from app/views/welcome/index.html.erb rename to app/views/main/index.html.erb diff --git a/config/routes.rb b/config/routes.rb index 8d9bd4b..70e239c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,7 @@ AdoptAHydrant::Application.routes.draw do - get "javascripts/:action" => "javascripts#action" - root :to => "welcome#index" + get "/javascripts/:action" => "javascripts#action" + post "/sign_up.:format" => "main#sign_up" + post "/sign_in.:format" => "main#sign_in" + post "/forgot_password.:format" => "main#forgot_password" + root :to => "main#index" end