Refactor
This commit is contained in:
parent
a3921356a6
commit
a587c5c08f
|
@ -1,6 +1,7 @@
|
||||||
class AddressesController < ApplicationController
|
class AddressesController < ApplicationController
|
||||||
respond_to :json
|
respond_to :json
|
||||||
def index
|
|
||||||
|
def show
|
||||||
@address = Address.find_lat_lng("#{params[:address]}, #{params[:city_state]}")
|
@address = Address.find_lat_lng("#{params[:address]}, #{params[:city_state]}")
|
||||||
unless @address.blank?
|
unless @address.blank?
|
||||||
respond_with @address
|
respond_with @address
|
||||||
|
|
|
@ -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
|
|
|
@ -1,10 +1,25 @@
|
||||||
class HydrantsController < ApplicationController
|
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])
|
@hydrants = Hydrant.find_closest(params[:lat], params[:lng])
|
||||||
unless @hydrants.blank?
|
unless @hydrants.blank?
|
||||||
respond_with @hydrants
|
render(:json => @hydrants)
|
||||||
else
|
else
|
||||||
render(:json => {"errors" => {"address" => ["Could not find address."]}})
|
render(:json => {"errors" => {"address" => ["Could not find address."]}})
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
class JavascriptsController < ApplicationController
|
|
||||||
def main
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,3 +0,0 @@
|
||||||
<h2>Thank you for adopting this hydrant!</h2>
|
|
||||||
<%= render :partial => 'abandon_form' %>
|
|
||||||
<%= render :partial => 'sign_out_form' %>
|
|
|
@ -7,4 +7,4 @@
|
||||||
<%= f.submit "Adopt!", :tabindex => 2, :id => "adoption_form_submit" %>
|
<%= 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>
|
<p>By adopting this hydrant, you agree to the <%= link_to "Terms of Service", "#", :tabindex => 3 %>.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= render :partial => 'sign_out_form' %>
|
<%= render(:partial => 'users/sign_out_form') %>
|
|
@ -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/jquery/1/jquery.min.js" %>
|
||||||
<%= javascript_include_tag "https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.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 "https://github.com/scottschiller/Snowstorm/raw/master/snowstorm-min.js" %>
|
||||||
<%= javascript_include_tag javascripts_main_path %>
|
<%= javascript_include_tag :all %>
|
||||||
<%= csrf_meta_tag %>
|
<%= csrf_meta_tag %>
|
||||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2><%= @hydrant.name ? @hydrant.name.titleize : "This hydrant" %> has been adopted by <%= @hydrant.user.name %></h2>
|
<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 %>
|
<%= @hydrant.user.organization.blank? ? nil : "<h3>of #{@hydrant.user.organization}</h3>".html_safe %>
|
||||||
<% if user_signed_in? %>
|
<% if user_signed_in? %>
|
||||||
<%= render :partial => 'steal_form' %>
|
<%= render :partial => 'users/steal_form' %>
|
||||||
<%= render :partial => 'sign_out_form' %>
|
<%= render :partial => 'users/sign_out_form' %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<h2>Thank you for adopting this hydrant!</h2>
|
||||||
|
<%= render :partial => 'users/abandon_form' %>
|
||||||
|
<%= render :partial => 'users/sign_out_form' %>
|
|
@ -5,13 +5,9 @@ AdoptAHydrant::Application.routes.draw do
|
||||||
:sessions => 'sessions',
|
:sessions => 'sessions',
|
||||||
}
|
}
|
||||||
resource :user
|
resource :user
|
||||||
get 'hydrants' => 'hydrants#index'
|
get 'hydrants' => 'hydrants#list'
|
||||||
resource :hydrant
|
resource :hydrant
|
||||||
scope 'javascripts', :controller => 'javascripts', :as => 'javascripts' do
|
get 'address' => 'addresses#show'
|
||||||
get 'main', :action => 'main', :as => 'main'
|
|
||||||
end
|
|
||||||
get 'address' => 'addresses#index', :as => 'address'
|
|
||||||
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
|
get 'sitemap' => 'sitemaps#index', :as => 'sitemap'
|
||||||
get 'contents' => 'contents#index', :as => 'contents'
|
|
||||||
root :to => 'main#index'
|
root :to => 'main#index'
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,7 +38,7 @@ $(function() {
|
||||||
if(activeInfoWindow) {
|
if(activeInfoWindow) {
|
||||||
activeInfoWindow.close();
|
activeInfoWindow.close();
|
||||||
}
|
}
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': hydrantId
|
'hydrant_id': hydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
var infoWindow = new google.maps.InfoWindow({
|
var infoWindow = new google.maps.InfoWindow({
|
||||||
|
@ -54,7 +54,7 @@ $(function() {
|
||||||
hydrantIds.push(hydrantId);
|
hydrantIds.push(hydrantId);
|
||||||
}
|
}
|
||||||
function addMarkersAround(lat, lng) {
|
function addMarkersAround(lat, lng) {
|
||||||
$.get('<%= hydrants_path :format => "json" %>', {
|
$.get('/hydrants.json', {
|
||||||
'commit': $('#address_submit').val(),
|
'commit': $('#address_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
||||||
|
@ -111,7 +111,7 @@ $(function() {
|
||||||
$('#address').addClass('error', 500);
|
$('#address').addClass('error', 500);
|
||||||
$('#address').focus();
|
$('#address').focus();
|
||||||
} else {
|
} else {
|
||||||
$.get('<%= address_path :format => "json" %>', {
|
$.get('/address.json', {
|
||||||
'commit': $('#address_submit').val(),
|
'commit': $('#address_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
||||||
|
@ -184,7 +184,7 @@ $(function() {
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('<%= user_registration_path :format => "json" %>', {
|
$.post('/users.json', {
|
||||||
'commit': $('#user_sign_up_submit').val(),
|
'commit': $('#user_sign_up_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
|
@ -231,7 +231,7 @@ $(function() {
|
||||||
}
|
}
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
|
@ -251,7 +251,7 @@ $(function() {
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('<%= user_session_path :format => "json" %>', {
|
$.post('/users/sign_in.json', {
|
||||||
'commit': $('#user_sign_in_submit').val(),
|
'commit': $('#user_sign_in_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
|
@ -266,7 +266,7 @@ $(function() {
|
||||||
$('#user_password').addClass('error', 500);
|
$('#user_password').addClass('error', 500);
|
||||||
$('#user_password').focus();
|
$('#user_password').focus();
|
||||||
} else {
|
} else {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
|
@ -278,7 +278,7 @@ $(function() {
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('<%= user_password_path :format => "json" %>', {
|
$.post('/users/password.json', {
|
||||||
'commit': $('#user_forgot_password_submit').val(),
|
'commit': $('#user_forgot_password_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
|
@ -300,12 +300,12 @@ $(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#sign_out_form').live('submit', function() {
|
$('#sign_out_form').live('submit', function() {
|
||||||
$.get('<%= destroy_user_session_path :format => "json" %>', {
|
$.get('/users/sign_out.json', {
|
||||||
'commit': $('#sign_out_form_submit').val(),
|
'commit': $('#sign_out_form_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
|
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
|
@ -314,7 +314,7 @@ $(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#adoption_form').live('submit', function() {
|
$('#adoption_form').live('submit', function() {
|
||||||
$.post('<%= hydrant_path :format => "json" %>', {
|
$.post('/hydrant', {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': $('#adoption_form_submit').val(),
|
'commit': $('#adoption_form_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
|
@ -325,7 +325,7 @@ $(function() {
|
||||||
'name': $('#hydrant_name').val()
|
'name': $('#hydrant_name').val()
|
||||||
}
|
}
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
|
@ -343,7 +343,7 @@ $(function() {
|
||||||
$('#abandon_form').live('submit', function() {
|
$('#abandon_form').live('submit', function() {
|
||||||
var answer = window.confirm("Are you sure you want to abandon this hydrant?")
|
var answer = window.confirm("Are you sure you want to abandon this hydrant?")
|
||||||
if(answer) {
|
if(answer) {
|
||||||
$.post('<%= hydrant_path :format => "json" %>', {
|
$.post('/hydrant', {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': $('#abandon_form_submit').val(),
|
'commit': $('#abandon_form_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
|
@ -354,7 +354,7 @@ $(function() {
|
||||||
'name': $('#hydrant_name').val()
|
'name': $('#hydrant_name').val()
|
||||||
}
|
}
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
||||||
|
@ -373,7 +373,7 @@ $(function() {
|
||||||
$('#steal_form').live('submit', function() {
|
$('#steal_form').live('submit', function() {
|
||||||
var answer = window.confirm("Are you sure you want to steal this hydrant?")
|
var answer = window.confirm("Are you sure you want to steal this hydrant?")
|
||||||
if(answer) {
|
if(answer) {
|
||||||
$.post('<%= hydrant_path :format => "json" %>', {
|
$.post('/hydrant', {
|
||||||
'id': $('#hydrant_id').val(),
|
'id': $('#hydrant_id').val(),
|
||||||
'commit': $('#steal_form_submit').val(),
|
'commit': $('#steal_form_submit').val(),
|
||||||
'utf8': '✓',
|
'utf8': '✓',
|
||||||
|
@ -384,7 +384,7 @@ $(function() {
|
||||||
'name': $('#hydrant_name').val()
|
'name': $('#hydrant_name').val()
|
||||||
}
|
}
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$.get('<%= contents_path %>', {
|
$.get('/hydrant', {
|
||||||
'hydrant_id': activeHydrantId
|
'hydrant_id': activeHydrantId
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
activeInfoWindow.setContent(data);
|
Loading…
Reference in New Issue