Skip to content

Commit

Permalink
Add spinners to all AJAX requests and prevent accidental double-clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 4, 2011
1 parent b574170 commit d502b46
Show file tree
Hide file tree
Showing 11 changed files with 474 additions and 306 deletions.
6 changes: 2 additions & 4 deletions app/controllers/addresses_controller.rb
@@ -1,12 +1,10 @@
class AddressesController < ApplicationController
respond_to :json

def show
@address = Address.find_lat_lng("#{params[:address]}, #{params[:city_state]}")
unless @address.blank?
respond_with @address
render(:json => @address)
else
render :json => {"errors" => {"address" => ["Could not find address."]}}
render(:json => {"errors" => {"address" => ["Could not find address."]}})
end
end
end
8 changes: 4 additions & 4 deletions app/controllers/hydrants_controller.rb
Expand Up @@ -3,15 +3,15 @@ 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")
render("users/thank_you", :layout => "info_window")
else
render(:partial => "users/profile")
render("users/profile", :layout => "info_window")
end
else
if user_signed_in?
render(:partial => "adopt")
render("adopt", :layout => "info_window")
else
render(:partial => "users/new")
render("users/new", :layout => "info_window")
end
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/passwords_controller.rb
@@ -1,10 +1,7 @@
class PasswordsController < Devise::PasswordsController
respond_to :json, :only => [:create, :update]

# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])

if resource.errors.empty?
render(:json => {"success" => true})
else
Expand All @@ -22,7 +19,6 @@ def edit
# PUT /resource/password
def update
self.resource = resource_class.reset_password_by_token(params[resource_name])

if resource.errors.empty?
render(:json => {"success" => true})
else
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
@@ -1,12 +1,12 @@
class UsersController < Devise::RegistrationsController
def edit
render_with_scope :edit
render("edit", :layout => "info_window")
end

def update
if resource.update_with_password(params[resource_name])
sign_in resource_name, resource, :bypass => true
redirect_to :controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id]
sign_in(resource_name, resource, :bypass => true)
redirect_to(:controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id])
else
clean_up_passwords(resource)
render(:json => {"errors" => resource.errors})
Expand Down
Expand Up @@ -2,7 +2,7 @@
<h2>Adopt this Hydrant</h2>
<%= f.hidden_field "id" %>
<%= f.hidden_field "user_id", :value => current_user.id %>
<%= f.label "name", "Give your hydrant a name", :id => "hydrant_name_label" %>
<%= f.label "name", "Give this hydrant a name", :id => "hydrant_name_label" %>
<%= f.text_field "name", :tabindex => 1 %>
<%= 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>
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/info_window.html.erb
@@ -0,0 +1,6 @@
<div id="loader" style="display: none;">
<img src="/images/ajax-loader.gif" />
</div>
<div id="info_window">
<%= yield %>
</div>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added public/images/ajax-loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d502b46

Please sign in to comment.