Add spinners to all AJAX requests and prevent accidental double-clicks
This commit is contained in:
parent
b574170de4
commit
d502b4693e
|
@ -1,12 +1,10 @@
|
||||||
class AddressesController < ApplicationController
|
class AddressesController < ApplicationController
|
||||||
respond_to :json
|
|
||||||
|
|
||||||
def show
|
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
|
render(:json => @address)
|
||||||
else
|
else
|
||||||
render :json => {"errors" => {"address" => ["Could not find address."]}}
|
render(:json => {"errors" => {"address" => ["Could not find address."]}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,15 +3,15 @@ class HydrantsController < ApplicationController
|
||||||
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
|
@hydrant = Hydrant.find_by_id(params[:hydrant_id])
|
||||||
if @hydrant.adopted?
|
if @hydrant.adopted?
|
||||||
if user_signed_in? && current_user.id == @hydrant.user_id
|
if user_signed_in? && current_user.id == @hydrant.user_id
|
||||||
render(:partial => "users/thank_you")
|
render("users/thank_you", :layout => "info_window")
|
||||||
else
|
else
|
||||||
render(:partial => "users/profile")
|
render("users/profile", :layout => "info_window")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if user_signed_in?
|
if user_signed_in?
|
||||||
render(:partial => "adopt")
|
render("adopt", :layout => "info_window")
|
||||||
else
|
else
|
||||||
render(:partial => "users/new")
|
render("users/new", :layout => "info_window")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
class PasswordsController < Devise::PasswordsController
|
class PasswordsController < Devise::PasswordsController
|
||||||
respond_to :json, :only => [:create, :update]
|
|
||||||
|
|
||||||
# POST /resource/password
|
# POST /resource/password
|
||||||
def create
|
def create
|
||||||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||||
|
|
||||||
if resource.errors.empty?
|
if resource.errors.empty?
|
||||||
render(:json => {"success" => true})
|
render(:json => {"success" => true})
|
||||||
else
|
else
|
||||||
|
@ -22,7 +19,6 @@ class PasswordsController < Devise::PasswordsController
|
||||||
# PUT /resource/password
|
# PUT /resource/password
|
||||||
def update
|
def update
|
||||||
self.resource = resource_class.reset_password_by_token(params[resource_name])
|
self.resource = resource_class.reset_password_by_token(params[resource_name])
|
||||||
|
|
||||||
if resource.errors.empty?
|
if resource.errors.empty?
|
||||||
render(:json => {"success" => true})
|
render(:json => {"success" => true})
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
class UsersController < Devise::RegistrationsController
|
class UsersController < Devise::RegistrationsController
|
||||||
def edit
|
def edit
|
||||||
render_with_scope :edit
|
render("edit", :layout => "info_window")
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if resource.update_with_password(params[resource_name])
|
if resource.update_with_password(params[resource_name])
|
||||||
sign_in resource_name, resource, :bypass => true
|
sign_in(resource_name, resource, :bypass => true)
|
||||||
redirect_to :controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id]
|
redirect_to(:controller => "hydrants", :action => "show", :hydrant_id => params[:hydrant_id])
|
||||||
else
|
else
|
||||||
clean_up_passwords(resource)
|
clean_up_passwords(resource)
|
||||||
render(:json => {"errors" => resource.errors})
|
render(:json => {"errors" => resource.errors})
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<h2>Adopt this Hydrant</h2>
|
<h2>Adopt this Hydrant</h2>
|
||||||
<%= f.hidden_field "id" %>
|
<%= f.hidden_field "id" %>
|
||||||
<%= f.hidden_field "user_id", :value => current_user.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.text_field "name", :tabindex => 1 %>
|
||||||
<%= 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>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<div id="loader" style="display: none;">
|
||||||
|
<img src="/images/ajax-loader.gif" />
|
||||||
|
</div>
|
||||||
|
<div id="info_window">
|
||||||
|
<%= yield %>
|
||||||
|
</div>
|
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -38,66 +38,81 @@ $(function() {
|
||||||
if(activeInfoWindow) {
|
if(activeInfoWindow) {
|
||||||
activeInfoWindow.close();
|
activeInfoWindow.close();
|
||||||
}
|
}
|
||||||
$.get('/hydrant', {
|
var infoWindow = new google.maps.InfoWindow({
|
||||||
'hydrant_id': hydrantId
|
maxWidth: 350
|
||||||
}, function(data) {
|
});
|
||||||
var infoWindow = new google.maps.InfoWindow({
|
activeInfoWindow = infoWindow;
|
||||||
content: data,
|
activeHydrantId = hydrantId;
|
||||||
maxWidth: 350
|
activeMarker = marker;
|
||||||
});
|
$.ajax({
|
||||||
infoWindow.open(map, marker);
|
type: 'GET',
|
||||||
activeHydrantId = hydrantId;
|
url: '/hydrant',
|
||||||
activeMarker = marker;
|
data: {
|
||||||
activeInfoWindow = infoWindow;
|
'hydrant_id': hydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
// Prevent race condition, which could lead to multiple windows being open at the same time.
|
||||||
|
if(infoWindow == activeInfoWindow) {
|
||||||
|
infoWindow.setContent(data);
|
||||||
|
infoWindow.open(map, marker);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
hydrantIds.push(hydrantId);
|
hydrantIds.push(hydrantId);
|
||||||
}
|
}
|
||||||
function addMarkersAround(lat, lng) {
|
function addMarkersAround(lat, lng) {
|
||||||
$.get('/hydrants.json', {
|
$.ajax({
|
||||||
'commit': $('#address_submit').val(),
|
type: 'GET',
|
||||||
'utf8': '✓',
|
url: '/hydrants.json',
|
||||||
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
data: {
|
||||||
'lat': lat,
|
'commit': $('#address_submit').val(),
|
||||||
'lng': lng
|
'utf8': '✓',
|
||||||
}, function(data) {
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
||||||
if(data.errors) {
|
'lat': lat,
|
||||||
$('#address_label').addClass('error', 500);
|
'lng': lng
|
||||||
$('#address').addClass('error', 500);
|
},
|
||||||
$('#address').focus();
|
success: function(data) {
|
||||||
} else {
|
if(data.errors) {
|
||||||
var northMost;
|
$('#address_label').addClass('error', 500);
|
||||||
var eastMost;
|
$('#address').addClass('error', 500);
|
||||||
var southMost;
|
$('#address').focus();
|
||||||
var westMost;
|
} else {
|
||||||
var i = 0;
|
$('#address_label').removeClass('error', 500);
|
||||||
$(data).each(function(index, hydrant) {
|
$('#address').removeClass('error', 500);
|
||||||
hydrant = hydrant.hydrant;
|
var northMost;
|
||||||
if(!northMost || northMost > hydrant.lat) {
|
var eastMost;
|
||||||
northMost = hydrant.lat;
|
var southMost;
|
||||||
}
|
var westMost;
|
||||||
if(!eastMost || eastMost > hydrant.lng) {
|
var i = 0;
|
||||||
eastMost = hydrant.lng;
|
$(data).each(function(index, hydrant) {
|
||||||
}
|
hydrant = hydrant.hydrant;
|
||||||
if(!southMost || southMost < hydrant.lat) {
|
if(!northMost || northMost > hydrant.lat) {
|
||||||
southMost = hydrant.lat;
|
northMost = hydrant.lat;
|
||||||
}
|
}
|
||||||
if(!westMost || westMost < hydrant.lng) {
|
if(!eastMost || eastMost > hydrant.lng) {
|
||||||
westMost = hydrant.lng;
|
eastMost = hydrant.lng;
|
||||||
}
|
}
|
||||||
setTimeout(function() {
|
if(!southMost || southMost < hydrant.lat) {
|
||||||
point = new google.maps.LatLng(hydrant.lat, hydrant.lng);
|
southMost = hydrant.lat;
|
||||||
color = '/images/markers/' + (hydrant.user_id ? 'green' : 'red') + '.png';
|
}
|
||||||
addMarker(hydrant.id, point, color);
|
if(!westMost || westMost < hydrant.lng) {
|
||||||
}, i * 100);
|
westMost = hydrant.lng;
|
||||||
if($.inArray(hydrant.id, hydrantIds) == -1) {
|
}
|
||||||
i += 1;
|
setTimeout(function() {
|
||||||
}
|
point = new google.maps.LatLng(hydrant.lat, hydrant.lng);
|
||||||
});
|
color = '/images/markers/' + (hydrant.user_id ? 'green' : 'red') + '.png';
|
||||||
southWest = new google.maps.LatLng(southMost, westMost);
|
addMarker(hydrant.id, point, color);
|
||||||
northEast = new google.maps.LatLng(northMost, eastMost);
|
}, i * 100);
|
||||||
bounds = new google.maps.LatLngBounds(southWest, northEast);
|
if($.inArray(hydrant.id, hydrantIds) == -1) {
|
||||||
map.fitBounds(bounds);
|
i += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
southWest = new google.maps.LatLng(southMost, westMost);
|
||||||
|
northEast = new google.maps.LatLng(northMost, eastMost);
|
||||||
|
bounds = new google.maps.LatLngBounds(southWest, northEast);
|
||||||
|
map.fitBounds(bounds);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -106,24 +121,37 @@ $(function() {
|
||||||
addMarkersAround(center.lat(), center.lng());
|
addMarkersAround(center.lat(), center.lng());
|
||||||
});
|
});
|
||||||
$('#address_form').submit(function() {
|
$('#address_form').submit(function() {
|
||||||
|
var submitButton = $("#address_form input[type='submit']");
|
||||||
|
$(submitButton).attr("disabled", true);
|
||||||
|
var submitButtonText = $(submitButton).attr("value");
|
||||||
|
$(submitButton).attr("value", "Please Wait...");
|
||||||
if($('#address').val() === '') {
|
if($('#address').val() === '') {
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
|
$(submitButton).attr("value", submitButtonText);
|
||||||
$('#address_label').addClass('error', 500);
|
$('#address_label').addClass('error', 500);
|
||||||
$('#address').addClass('error', 500);
|
$('#address').addClass('error', 500);
|
||||||
$('#address').focus();
|
$('#address').focus();
|
||||||
} else {
|
} else {
|
||||||
$.get('/address.json', {
|
$.ajax({
|
||||||
'commit': $('#address_submit').val(),
|
type: 'GET',
|
||||||
'utf8': '✓',
|
url: '/address.json',
|
||||||
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
data: {
|
||||||
'city_state': $('#city_state').val(),
|
'commit': $('#address_submit').val(),
|
||||||
'address': $('#address').val()
|
'utf8': '✓',
|
||||||
}, function(data) {
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
||||||
if(data.errors) {
|
'city_state': $('#city_state').val(),
|
||||||
$('#address_label').addClass('error', 500);
|
'address': $('#address').val()
|
||||||
$('#address').addClass('error', 500);
|
},
|
||||||
$('#address').focus();
|
success: function(data) {
|
||||||
} else {
|
$(submitButton).attr("disabled", false);
|
||||||
addMarkersAround(data[0], data[1]);
|
$(submitButton).attr("value", submitButtonText);
|
||||||
|
if(data.errors) {
|
||||||
|
$('#address_label').addClass('error', 500);
|
||||||
|
$('#address').addClass('error', 500);
|
||||||
|
$('#address').focus();
|
||||||
|
} else {
|
||||||
|
addMarkersAround(data[0], data[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -155,6 +183,8 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#combo_form').live('submit', function() {
|
$('#combo_form').live('submit', function() {
|
||||||
|
var submitButton = $("#combo_form input[type='submit']");
|
||||||
|
$(submitButton).attr("disabled", true);
|
||||||
var errors = []
|
var errors = []
|
||||||
if(!/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
if(!/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
||||||
errors.push($('#user_email'));
|
errors.push($('#user_email'));
|
||||||
|
@ -182,60 +212,78 @@ $(function() {
|
||||||
$('#user_password_confirmation').removeClass('error');
|
$('#user_password_confirmation').removeClass('error');
|
||||||
}
|
}
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('/users.json', {
|
$.ajax({
|
||||||
'commit': $('#user_sign_up_submit').val(),
|
type: 'POST',
|
||||||
'utf8': '✓',
|
url: '/users.json',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
data: {
|
||||||
'user': {
|
'commit': $('#user_sign_up_submit').val(),
|
||||||
'email': $('#user_email').val(),
|
'utf8': '✓',
|
||||||
'name': $('#user_name').val(),
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
'organization': $('#user_organization').val(),
|
'user': {
|
||||||
'voice_number': $('#user_voice_number').val(),
|
'email': $('#user_email').val(),
|
||||||
'sms_number': $('#user_sms_number').val(),
|
'name': $('#user_name').val(),
|
||||||
'password': $('#user_password_confirmation').val(),
|
'organization': $('#user_organization').val(),
|
||||||
'password_confirmation': $('#user_password_confirmation').val()
|
'voice_number': $('#user_voice_number').val(),
|
||||||
}
|
'sms_number': $('#user_sms_number').val(),
|
||||||
}, function(data) {
|
'password': $('#user_password_confirmation').val(),
|
||||||
if(data.errors) {
|
'password_confirmation': $('#user_password_confirmation').val()
|
||||||
if(data.errors.email) {
|
|
||||||
errors.push($('#user_email'));
|
|
||||||
$('#user_email_label').addClass('error', 500);
|
|
||||||
$('#user_email').addClass('error', 500);
|
|
||||||
}
|
}
|
||||||
if(data.errors.name) {
|
},
|
||||||
errors.push($('#user_name'));
|
beforeSend: function() {
|
||||||
$('#user_name_label').addClass('error', 500);
|
$('#info_window').hide();
|
||||||
$('#user_name').addClass('error', 500);
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
if(data.errors) {
|
||||||
|
$('#loader').hide();
|
||||||
|
$('#info_window').show();
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
|
if(data.errors.email) {
|
||||||
|
errors.push($('#user_email'));
|
||||||
|
$('#user_email_label').addClass('error', 500);
|
||||||
|
$('#user_email').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.name) {
|
||||||
|
errors.push($('#user_name'));
|
||||||
|
$('#user_name_label').addClass('error', 500);
|
||||||
|
$('#user_name').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.organization) {
|
||||||
|
errors.push($('#user_organization'));
|
||||||
|
$('#user_organization_label').addClass('error', 500);
|
||||||
|
$('#user_organization').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.voice_number) {
|
||||||
|
errors.push($('#user_voice_number'));
|
||||||
|
$('#user_voice_number_label').addClass('error', 500);
|
||||||
|
$('#user_voice_number').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.sms_number) {
|
||||||
|
errors.push($('#user_sms_number'));
|
||||||
|
$('#user_sms_number_label').addClass('error', 500);
|
||||||
|
$('#user_sms_number').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.password) {
|
||||||
|
errors.push($('#user_password_confirmation'));
|
||||||
|
$('#user_password_confirmation_label').addClass('error', 500);
|
||||||
|
$('#user_password_confirmation').addClass('error', 500);
|
||||||
|
}
|
||||||
|
errors[0].focus();
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if(data.errors.organization) {
|
|
||||||
errors.push($('#user_organization'));
|
|
||||||
$('#user_organization_label').addClass('error', 500);
|
|
||||||
$('#user_organization').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.voice_number) {
|
|
||||||
errors.push($('#user_voice_number'));
|
|
||||||
$('#user_voice_number_label').addClass('error', 500);
|
|
||||||
$('#user_voice_number').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.sms_number) {
|
|
||||||
errors.push($('#user_sms_number'));
|
|
||||||
$('#user_sms_number_label').addClass('error', 500);
|
|
||||||
$('#user_sms_number').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.password) {
|
|
||||||
errors.push($('#user_password_confirmation'));
|
|
||||||
$('#user_password_confirmation_label').addClass('error', 500);
|
|
||||||
$('#user_password_confirmation').addClass('error', 500);
|
|
||||||
}
|
|
||||||
errors[0].focus();
|
|
||||||
} else {
|
|
||||||
$.get('/hydrant', {
|
|
||||||
'hydrant_id': activeHydrantId
|
|
||||||
}, function(data) {
|
|
||||||
activeInfoWindow.setContent(data);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -249,50 +297,81 @@ $(function() {
|
||||||
$('#user_password').removeClass('error');
|
$('#user_password').removeClass('error');
|
||||||
}
|
}
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('/users/sign_in.json', {
|
$.ajax({
|
||||||
'commit': $('#user_sign_in_submit').val(),
|
type: 'POST',
|
||||||
'utf8': '✓',
|
url: '/users/sign_in.json',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
data: {
|
||||||
'user': {
|
'commit': $('#user_sign_in_submit').val(),
|
||||||
'email': $('#user_email').val(),
|
'utf8': '✓',
|
||||||
'password': $('#user_password').val(),
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
'remember_me': $('#user_remember_me').val()
|
'user': {
|
||||||
}
|
'email': $('#user_email').val(),
|
||||||
}, function(data) {
|
'password': $('#user_password').val(),
|
||||||
if(data.errors) {
|
'remember_me': $('#user_remember_me').val()
|
||||||
$('#user_password_label').addClass('error', 500);
|
}
|
||||||
$('#user_password').addClass('error', 500);
|
},
|
||||||
$('#user_password').focus();
|
beforeSend: function() {
|
||||||
} else {
|
$('#info_window').hide();
|
||||||
$.get('/hydrant', {
|
$('#loader').show();
|
||||||
'hydrant_id': activeHydrantId
|
},
|
||||||
}, function(data) {
|
success: function(data) {
|
||||||
activeInfoWindow.setContent(data);
|
if(data.errors) {
|
||||||
});
|
$('#loader').hide();
|
||||||
|
$('#info_window').show();
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
|
$('#user_password_label').addClass('error', 500);
|
||||||
|
$('#user_password').addClass('error', 500);
|
||||||
|
$('#user_password').focus();
|
||||||
|
} else {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if($(this).data('state') === 'user_forgot_password') {
|
} else if($(this).data('state') === 'user_forgot_password') {
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('/users/password.json', {
|
$.ajax({
|
||||||
'commit': $('#user_forgot_password_submit').val(),
|
type: 'POST',
|
||||||
'utf8': '✓',
|
url: '/users/password.json',
|
||||||
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
data: {
|
||||||
'user': {
|
'commit': $('#user_forgot_password_submit').val(),
|
||||||
'email': $('#user_email').val()
|
'utf8': '✓',
|
||||||
}
|
'authenticity_token': $('#combo_form input[name="authenticity_token"]').val(),
|
||||||
}, function(data) {
|
'user': {
|
||||||
if(data.errors) {
|
'email': $('#user_email').val()
|
||||||
$('#user_email_label').addClass('error', 500);
|
}
|
||||||
$('#user_email').addClass('error', 500);
|
},
|
||||||
$('#user_email').focus();
|
beforeSend: function() {
|
||||||
} else {
|
$('#info_window').hide();
|
||||||
$('#user_forgot_password_fields').slideUp();
|
$('#loader').show();
|
||||||
$('#user_sign_in_fields').slideDown();
|
},
|
||||||
|
success: function() {
|
||||||
|
if(data.errors) {
|
||||||
|
$('#loader').hide();
|
||||||
|
$('#info_window').show();
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
|
$('#user_email_label').addClass('error', 500);
|
||||||
|
$('#user_email').addClass('error', 500);
|
||||||
|
$('#user_email').focus();
|
||||||
|
} else {
|
||||||
|
$('#user_forgot_password_fields').slideUp();
|
||||||
|
$('#user_sign_in_fields').slideDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -300,72 +379,121 @@ $(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#sign_out_form').live('submit', function() {
|
$('#sign_out_form').live('submit', function() {
|
||||||
$.get('/users/sign_out.json', {
|
var submitButton = $("#sign_out_form input[type='submit']");
|
||||||
'commit': $('#sign_out_form_submit').val(),
|
$(submitButton).attr("disabled", true);
|
||||||
'utf8': '✓',
|
$.ajax({
|
||||||
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
|
type: 'GET',
|
||||||
}, function(data) {
|
url: '/users/sign_out.json',
|
||||||
$.get('/hydrant', {
|
data: {
|
||||||
'hydrant_id': activeHydrantId
|
'commit': $('#sign_out_form_submit').val(),
|
||||||
}, function(data) {
|
'utf8': '✓',
|
||||||
activeInfoWindow.setContent(data);
|
'authenticity_token': $('#sign_out_form input[name="authenticity_token"]').val()
|
||||||
});
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#info_window').hide();
|
||||||
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#adoption_form').live('submit', function() {
|
$('#adoption_form').live('submit', function() {
|
||||||
$.post('/hydrant', {
|
var submitButton = $("#adoption_form input[type='submit']");
|
||||||
'id': $('#hydrant_id').val(),
|
$(submitButton).attr("disabled", true);
|
||||||
'commit': $('#adoption_form_submit').val(),
|
$.ajax({
|
||||||
'utf8': '✓',
|
type: 'POST',
|
||||||
'authenticity_token': $('#adoption_form input[name="authenticity_token"]').val(),
|
url: '/hydrant',
|
||||||
'_method': 'put',
|
data: {
|
||||||
'hydrant': {
|
'id': $('#hydrant_id').val(),
|
||||||
'user_id': $('#hydrant_user_id').val(),
|
'commit': $('#adoption_form_submit').val(),
|
||||||
'name': $('#hydrant_name').val()
|
'utf8': '✓',
|
||||||
|
'authenticity_token': $('#adoption_form input[name="authenticity_token"]').val(),
|
||||||
|
'_method': 'put',
|
||||||
|
'hydrant': {
|
||||||
|
'user_id': $('#hydrant_user_id').val(),
|
||||||
|
'name': $('#hydrant_name').val()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#info_window').hide();
|
||||||
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
image = new google.maps.MarkerImage('/images/markers/green.png',
|
||||||
|
new google.maps.Size(27.0, 37.0),
|
||||||
|
new google.maps.Point(0, 0),
|
||||||
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
);
|
||||||
|
activeMarker.setIcon(image);
|
||||||
|
activeMarker.setAnimation(google.maps.Animation.BOUNCE);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, function(data) {
|
|
||||||
$.get('/hydrant', {
|
|
||||||
'hydrant_id': activeHydrantId
|
|
||||||
}, function(data) {
|
|
||||||
activeInfoWindow.setContent(data);
|
|
||||||
image = new google.maps.MarkerImage('/images/markers/green.png',
|
|
||||||
new google.maps.Size(27.0, 37.0),
|
|
||||||
new google.maps.Point(0, 0),
|
|
||||||
new google.maps.Point(13.0, 18.0)
|
|
||||||
);
|
|
||||||
activeMarker.setIcon(image);
|
|
||||||
activeMarker.setAnimation(google.maps.Animation.BOUNCE);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#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', {
|
var submitButton = $("#abandon_form input[type='submit']");
|
||||||
'id': $('#hydrant_id').val(),
|
$(submitButton).attr("disabled", true);
|
||||||
'commit': $('#abandon_form_submit').val(),
|
$.ajax({
|
||||||
'utf8': '✓',
|
type: 'POST',
|
||||||
'authenticity_token': $('#abandon_form input[name="authenticity_token"]').val(),
|
url: '/hydrant',
|
||||||
'_method': 'put',
|
data: {
|
||||||
'hydrant': {
|
'id': $('#hydrant_id').val(),
|
||||||
'user_id': $('#hydrant_user_id').val(),
|
'commit': $('#abandon_form_submit').val(),
|
||||||
'name': $('#hydrant_name').val()
|
'utf8': '✓',
|
||||||
|
'authenticity_token': $('#abandon_form input[name="authenticity_token"]').val(),
|
||||||
|
'_method': 'put',
|
||||||
|
'hydrant': {
|
||||||
|
'user_id': $('#hydrant_user_id').val(),
|
||||||
|
'name': $('#hydrant_name').val()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#info_window').hide();
|
||||||
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
image = new google.maps.MarkerImage('/images/markers/red.png',
|
||||||
|
new google.maps.Size(27.0, 37.0),
|
||||||
|
new google.maps.Point(0, 0),
|
||||||
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
);
|
||||||
|
activeMarker.setIcon(image);
|
||||||
|
activeMarker.setAnimation(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, function(data) {
|
|
||||||
$.get('/hydrant', {
|
|
||||||
'hydrant_id': activeHydrantId
|
|
||||||
}, function(data) {
|
|
||||||
activeInfoWindow.setContent(data);
|
|
||||||
image = new google.maps.MarkerImage('/images/markers/red.png',
|
|
||||||
new google.maps.Size(27.0, 37.0),
|
|
||||||
new google.maps.Point(0, 0),
|
|
||||||
new google.maps.Point(13.0, 18.0)
|
|
||||||
);
|
|
||||||
activeMarker.setIcon(image);
|
|
||||||
activeMarker.setAnimation(null);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -373,44 +501,71 @@ $(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', {
|
var submitButton = $("#steal_form input[type='submit']");
|
||||||
'id': $('#hydrant_id').val(),
|
$(submitButton).attr("disabled", true);
|
||||||
'commit': $('#steal_form_submit').val(),
|
$.ajax({
|
||||||
'utf8': '✓',
|
type: 'POST',
|
||||||
'authenticity_token': $('#steal_form input[name="authenticity_token"]').val(),
|
url: '/hydrant',
|
||||||
'_method': 'put',
|
data: {
|
||||||
'hydrant': {
|
'id': $('#hydrant_id').val(),
|
||||||
'user_id': $('#hydrant_user_id').val(),
|
'commit': $('#steal_form_submit').val(),
|
||||||
'name': $('#hydrant_name').val()
|
'utf8': '✓',
|
||||||
|
'authenticity_token': $('#steal_form input[name="authenticity_token"]').val(),
|
||||||
|
'_method': 'put',
|
||||||
|
'hydrant': {
|
||||||
|
'user_id': $('#hydrant_user_id').val(),
|
||||||
|
'name': $('#hydrant_name').val()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#info_window').hide();
|
||||||
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/hydrant',
|
||||||
|
data: {
|
||||||
|
'hydrant_id': activeHydrantId
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
image = new google.maps.MarkerImage('/images/markers/red.png',
|
||||||
|
new google.maps.Size(27.0, 37.0),
|
||||||
|
new google.maps.Point(0, 0),
|
||||||
|
new google.maps.Point(13.0, 18.0)
|
||||||
|
);
|
||||||
|
activeMarker.setIcon(image);
|
||||||
|
activeMarker.setAnimation(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, function(data) {
|
|
||||||
$.get('/hydrant', {
|
|
||||||
'hydrant_id': activeHydrantId
|
|
||||||
}, function(data) {
|
|
||||||
activeInfoWindow.setContent(data);
|
|
||||||
image = new google.maps.MarkerImage('/images/markers/red.png',
|
|
||||||
new google.maps.Size(27.0, 37.0),
|
|
||||||
new google.maps.Point(0, 0),
|
|
||||||
new google.maps.Point(13.0, 18.0)
|
|
||||||
);
|
|
||||||
activeMarker.setIcon(image);
|
|
||||||
activeMarker.setAnimation(null);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#edit_profile_form').live('submit', function() {
|
$('#edit_profile_form').live('submit', function() {
|
||||||
$.get('/users/edit', {
|
$.ajax({
|
||||||
'commit': $('#edit_profile_form_submit').val(),
|
type: 'GET',
|
||||||
'utf8': '✓',
|
url: '/users/edit',
|
||||||
'authenticity_token': $('#edit_profile_form input[name="authenticity_token"]').val()
|
data: {
|
||||||
}, function(data) {
|
'commit': $('#edit_profile_form_submit').val(),
|
||||||
activeInfoWindow.setContent(data);
|
'utf8': '✓',
|
||||||
|
'authenticity_token': $('#edit_profile_form input[name="authenticity_token"]').val()
|
||||||
|
},
|
||||||
|
beforeSend: function() {
|
||||||
|
$('#info_window').hide();
|
||||||
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$('#edit_form').live('submit', function() {
|
$('#edit_form').live('submit', function() {
|
||||||
|
var submitButton = $("#edit_form input[type='submit']");
|
||||||
|
$(submitButton).attr("disabled", true);
|
||||||
var errors = []
|
var errors = []
|
||||||
if(!/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
if(!/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
||||||
errors.push($('#user_email'));
|
errors.push($('#user_email'));
|
||||||
|
@ -445,65 +600,78 @@ $(function() {
|
||||||
$('#user_current_password').removeClass('error');
|
$('#user_current_password').removeClass('error');
|
||||||
}
|
}
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
errors[0].focus();
|
errors[0].focus();
|
||||||
} else {
|
} else {
|
||||||
$.post('/users.json', {
|
$.ajax({
|
||||||
'id': $('#id').val(),
|
type: 'POST',
|
||||||
'hydrant_id': activeHydrantId,
|
url: '/users.json',
|
||||||
'commit': $('#edit_form_submit').val(),
|
data: {
|
||||||
'utf8': '✓',
|
'id': $('#id').val(),
|
||||||
'authenticity_token': $('#edit_form input[name="authenticity_token"]').val(),
|
'hydrant_id': activeHydrantId,
|
||||||
'_method': 'put',
|
'commit': $('#edit_form_submit').val(),
|
||||||
'user': {
|
'utf8': '✓',
|
||||||
'email': $('#user_email').val(),
|
'authenticity_token': $('#edit_form input[name="authenticity_token"]').val(),
|
||||||
'name': $('#user_name').val(),
|
'_method': 'put',
|
||||||
'organization': $('#user_organization').val(),
|
'user': {
|
||||||
'voice_number': $('#user_voice_number').val(),
|
'email': $('#user_email').val(),
|
||||||
'sms_number': $('#user_sms_number').val(),
|
'name': $('#user_name').val(),
|
||||||
'password': $('#user_password').val(),
|
'organization': $('#user_organization').val(),
|
||||||
'password_confirmation': $('#user_password').val(),
|
'voice_number': $('#user_voice_number').val(),
|
||||||
'current_password': $('#user_current_password').val()
|
'sms_number': $('#user_sms_number').val(),
|
||||||
}
|
'password': $('#user_password').val(),
|
||||||
}, function(data) {
|
'password_confirmation': $('#user_password').val(),
|
||||||
if(data.errors) {
|
'current_password': $('#user_current_password').val()
|
||||||
if(data.errors.email) {
|
|
||||||
errors.push($('#user_email'));
|
|
||||||
$('#user_email_label').addClass('error', 500);
|
|
||||||
$('#user_email').addClass('error', 500);
|
|
||||||
}
|
}
|
||||||
if(data.errors.name) {
|
},
|
||||||
errors.push($('#user_name'));
|
beforeSend: function() {
|
||||||
$('#user_name_label').addClass('error', 500);
|
$('#info_window').hide();
|
||||||
$('#user_name').addClass('error', 500);
|
$('#loader').show();
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
if(data.errors) {
|
||||||
|
$('#loader').hide();
|
||||||
|
$('#info_window').show();
|
||||||
|
$(submitButton).attr("disabled", false);
|
||||||
|
if(data.errors.email) {
|
||||||
|
errors.push($('#user_email'));
|
||||||
|
$('#user_email_label').addClass('error', 500);
|
||||||
|
$('#user_email').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.name) {
|
||||||
|
errors.push($('#user_name'));
|
||||||
|
$('#user_name_label').addClass('error', 500);
|
||||||
|
$('#user_name').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.organization) {
|
||||||
|
errors.push($('#user_organization'));
|
||||||
|
$('#user_organization_label').addClass('error', 500);
|
||||||
|
$('#user_organization').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.voice_number) {
|
||||||
|
errors.push($('#user_voice_number'));
|
||||||
|
$('#user_voice_number_label').addClass('error', 500);
|
||||||
|
$('#user_voice_number').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.sms_number) {
|
||||||
|
errors.push($('#user_sms_number'));
|
||||||
|
$('#user_sms_number_label').addClass('error', 500);
|
||||||
|
$('#user_sms_number').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.password) {
|
||||||
|
errors.push($('#user_password'));
|
||||||
|
$('#user_password_label').addClass('error', 500);
|
||||||
|
$('#user_password').addClass('error', 500);
|
||||||
|
}
|
||||||
|
if(data.errors.current_password) {
|
||||||
|
errors.push($('#user_current_password'));
|
||||||
|
$('#user_current_password_label').addClass('error', 500);
|
||||||
|
$('#user_current_password').addClass('error', 500);
|
||||||
|
}
|
||||||
|
errors[0].focus();
|
||||||
|
} else {
|
||||||
|
activeInfoWindow.setContent(data);
|
||||||
}
|
}
|
||||||
if(data.errors.organization) {
|
|
||||||
errors.push($('#user_organization'));
|
|
||||||
$('#user_organization_label').addClass('error', 500);
|
|
||||||
$('#user_organization').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.voice_number) {
|
|
||||||
errors.push($('#user_voice_number'));
|
|
||||||
$('#user_voice_number_label').addClass('error', 500);
|
|
||||||
$('#user_voice_number').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.sms_number) {
|
|
||||||
errors.push($('#user_sms_number'));
|
|
||||||
$('#user_sms_number_label').addClass('error', 500);
|
|
||||||
$('#user_sms_number').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.password) {
|
|
||||||
errors.push($('#user_password'));
|
|
||||||
$('#user_password_label').addClass('error', 500);
|
|
||||||
$('#user_password').addClass('error', 500);
|
|
||||||
}
|
|
||||||
if(data.errors.current_password) {
|
|
||||||
errors.push($('#user_current_password'));
|
|
||||||
$('#user_current_password_label').addClass('error', 500);
|
|
||||||
$('#user_current_password').addClass('error', 500);
|
|
||||||
}
|
|
||||||
errors[0].focus();
|
|
||||||
} else {
|
|
||||||
activeInfoWindow.setContent(data);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue