This commit is contained in:
Erik Michaels-Ober 2011-03-27 11:45:58 -07:00
parent a3921356a6
commit a587c5c08f
15 changed files with 45 additions and 55 deletions

View File

@ -1,6 +1,7 @@
class AddressesController < ApplicationController
respond_to :json
def index
def show
@address = Address.find_lat_lng("#{params[:address]}, #{params[:city_state]}")
unless @address.blank?
respond_with @address

View File

@ -1,18 +0,0 @@
class ContentsController < ApplicationController
def index
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
if @hydrant.adopted?
if user_signed_in? && current_user.id == @hydrant.user_id
render(:partial => "thank_you")
else
render(:partial => "user_profile")
end
else
if user_signed_in?
render(:partial => "adoption_form")
else
render(:partial => "combo_form")
end
end
end
end

View File

@ -1,10 +1,25 @@
class HydrantsController < ApplicationController
respond_to :json
def show
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
if @hydrant.adopted?
if user_signed_in? && current_user.id == @hydrant.user_id
render(:partial => "users/thank_you")
else
render(:partial => "users/profile")
end
else
if user_signed_in?
render(:partial => "adopt")
else
render(:partial => "users/new")
end
end
end
def index
def list
@hydrants = Hydrant.find_closest(params[:lat], params[:lng])
unless @hydrants.blank?
respond_with @hydrants
render(:json => @hydrants)
else
render(:json => {"errors" => {"address" => ["Could not find address."]}})
end

View File

@ -1,4 +0,0 @@
class JavascriptsController < ApplicationController
def main
end
end

View File

@ -1,3 +0,0 @@
<h2>Thank you for adopting this hydrant!</h2>
<%= render :partial => 'abandon_form' %>
<%= render :partial => 'sign_out_form' %>

View File

@ -7,4 +7,4 @@
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
<% end %>
<%= render :partial => 'sign_out_form' %>
<%= render(:partial => 'users/sign_out_form') %>

View File

@ -7,7 +7,7 @@
<%= 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" %>
<%= javascript_include_tag javascripts_main_path %>
<%= javascript_include_tag :all %>
<%= csrf_meta_tag %>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>

View File

@ -1,6 +1,6 @@
<h2><%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %></h2>
<%= @hydrant.user.organization.blank? ? nil : "<h3>of #{@hydrant.user.organization}</h3>".html_safe %>
<% if user_signed_in? %>
<%= render :partial => 'steal_form' %>
<%= render :partial => 'sign_out_form' %>
<%= render :partial => 'users/steal_form' %>
<%= render :partial => 'users/sign_out_form' %>
<% end %>

View File

@ -0,0 +1,3 @@
<h2>Thank you for adopting this hydrant!</h2>
<%= render :partial => 'users/abandon_form' %>
<%= render :partial => 'users/sign_out_form' %>

View File

@ -5,13 +5,9 @@ AdoptAHydrant::Application.routes.draw do
:sessions => 'sessions',
}
resource :user
get 'hydrants' => 'hydrants#index'
get 'hydrants' => 'hydrants#list'
resource :hydrant
scope 'javascripts', :controller => 'javascripts', :as => 'javascripts' do
get 'main', :action => 'main', :as => 'main'
end
get 'address' => 'addresses#index', :as => 'address'
get 'address' => 'addresses#show'
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
get 'contents' => 'contents#index', :as => 'contents'
root :to => 'main#index'
end

View File

@ -38,7 +38,7 @@ $(function() {
if(activeInfoWindow) {
activeInfoWindow.close();
}
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': hydrantId
}, function(data) {
var infoWindow = new google.maps.InfoWindow({
@ -54,7 +54,7 @@ $(function() {
hydrantIds.push(hydrantId);
}
function addMarkersAround(lat, lng) {
$.get('<%= hydrants_path :format => "json" %>', {
$.get('/hydrants.json', {
'commit': $('#address_submit').val(),
'utf8': '✓',
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
@ -111,7 +111,7 @@ $(function() {
$('#address').addClass('error', 500);
$('#address').focus();
} else {
$.get('<%= address_path :format => "json" %>', {
$.get('/address.json', {
'commit': $('#address_submit').val(),
'utf8': '✓',
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
@ -184,7 +184,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_registration_path :format => "json" %>', {
$.post('/users.json', {
'commit': $('#user_sign_up_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@ -231,7 +231,7 @@ $(function() {
}
errors[0].focus();
} else {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@ -251,7 +251,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_session_path :format => "json" %>', {
$.post('/users/sign_in.json', {
'commit': $('#user_sign_in_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@ -266,7 +266,7 @@ $(function() {
$('#user_password').addClass('error', 500);
$('#user_password').focus();
} else {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@ -278,7 +278,7 @@ $(function() {
if(errors.length > 0) {
errors[0].focus();
} else {
$.post('<%= user_password_path :format => "json" %>', {
$.post('/users/password.json', {
'commit': $('#user_forgot_password_submit').val(),
'utf8': '✓',
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
@ -300,12 +300,12 @@ $(function() {
return false;
});
$('#sign_out_form').live('submit', function() {
$.get('<%= destroy_user_session_path :format => "json" %>', {
$.get('/users/sign_out.json', {
'commit': $('#sign_out_form_submit').val(),
'utf8': '✓',
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
}, function(data) {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@ -314,7 +314,7 @@ $(function() {
return false;
});
$('#adoption_form').live('submit', function() {
$.post('<%= hydrant_path :format => "json" %>', {
$.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#adoption_form_submit').val(),
'utf8': '✓',
@ -325,7 +325,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@ -343,7 +343,7 @@ $(function() {
$('#abandon_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to abandon this hydrant?")
if(answer) {
$.post('<%= hydrant_path :format => "json" %>', {
$.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#abandon_form_submit').val(),
'utf8': '✓',
@ -354,7 +354,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);
@ -373,7 +373,7 @@ $(function() {
$('#steal_form').live('submit', function() {
var answer = window.confirm("Are you sure you want to steal this hydrant?")
if(answer) {
$.post('<%= hydrant_path :format => "json" %>', {
$.post('/hydrant', {
'id': $('#hydrant_id').val(),
'commit': $('#steal_form_submit').val(),
'utf8': '✓',
@ -384,7 +384,7 @@ $(function() {
'name': $('#hydrant_name').val()
}
}, function(data) {
$.get('<%= contents_path %>', {
$.get('/hydrant', {
'hydrant_id': activeHydrantId
}, function(data) {
activeInfoWindow.setContent(data);