2011-09-03 20:47:28 +00:00
|
|
|
$(function() {
|
|
|
|
var center = new google.maps.LatLng(42.358431, -71.059773);
|
|
|
|
var mapOptions = {
|
|
|
|
center: center,
|
2012-01-14 22:31:01 +00:00
|
|
|
disableDoubleClickZoom: true,
|
|
|
|
keyboardShortcuts: false,
|
2011-09-03 20:47:28 +00:00
|
|
|
mapTypeControl: false,
|
|
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
2012-01-25 23:59:40 +00:00
|
|
|
maxZoom: 19,
|
|
|
|
minZoom: 15,
|
2011-09-03 20:47:28 +00:00
|
|
|
panControl: false,
|
2012-01-14 22:31:01 +00:00
|
|
|
rotateControl: false,
|
|
|
|
scaleControl: false,
|
2011-12-25 07:23:19 +00:00
|
|
|
scrollwheel: false,
|
2012-01-14 22:31:01 +00:00
|
|
|
streetViewControl: true,
|
|
|
|
zoom: 15,
|
2012-01-25 23:59:40 +00:00
|
|
|
zoomControl: true
|
2012-01-14 22:31:01 +00:00
|
|
|
};
|
2011-12-25 07:23:19 +00:00
|
|
|
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
|
2012-01-14 22:31:01 +00:00
|
|
|
var size = new google.maps.Size(27.0, 37.0);
|
|
|
|
var origin = new google.maps.Point(0, 0);
|
|
|
|
var anchor = new google.maps.Point(13.0, 18.0);
|
2012-01-14 19:59:59 +00:00
|
|
|
var greenMarkerImage = new google.maps.MarkerImage('<%= image_path 'markers/green.png' %>',
|
2012-01-14 22:31:01 +00:00
|
|
|
size,
|
|
|
|
origin,
|
|
|
|
anchor
|
2012-01-14 19:59:59 +00:00
|
|
|
);
|
|
|
|
var redMarkerImage = new google.maps.MarkerImage('<%= image_path 'markers/red.png' %>',
|
2012-01-14 22:31:01 +00:00
|
|
|
size,
|
|
|
|
origin,
|
|
|
|
anchor
|
2012-01-14 19:59:59 +00:00
|
|
|
);
|
|
|
|
var markerShadowImage = new google.maps.MarkerImage('<%= image_path 'markers/shadow.png' %>',
|
|
|
|
new google.maps.Size(46.0, 37.0),
|
2012-01-14 22:31:01 +00:00
|
|
|
origin,
|
|
|
|
anchor
|
2012-01-14 19:59:59 +00:00
|
|
|
);
|
2011-09-15 21:41:26 +00:00
|
|
|
var activeThingId;
|
2011-09-03 20:47:28 +00:00
|
|
|
var activeMarker;
|
|
|
|
var activeInfoWindow;
|
|
|
|
var isWindowOpen = false;
|
2011-09-15 21:41:26 +00:00
|
|
|
var thingIds = [];
|
2012-01-14 19:59:59 +00:00
|
|
|
function addMarker(thingId, point, color) {
|
|
|
|
if(color == 'green') {
|
|
|
|
var image = greenMarkerImage;
|
|
|
|
} else if(color == 'red') {
|
|
|
|
var image = redMarkerImage;
|
|
|
|
}
|
2011-09-03 20:47:28 +00:00
|
|
|
var marker = new google.maps.Marker({
|
|
|
|
animation: google.maps.Animation.DROP,
|
|
|
|
icon: image,
|
|
|
|
map: map,
|
|
|
|
position: point,
|
2012-01-14 19:59:59 +00:00
|
|
|
shadow: markerShadowImage
|
2011-09-03 20:47:28 +00:00
|
|
|
});
|
|
|
|
google.maps.event.addListener(marker, 'click', function() {
|
|
|
|
if(activeInfoWindow) {
|
|
|
|
activeInfoWindow.close();
|
|
|
|
}
|
|
|
|
var infoWindow = new google.maps.InfoWindow({
|
2012-01-14 22:31:01 +00:00
|
|
|
maxWidth: 210
|
2011-09-03 20:47:28 +00:00
|
|
|
});
|
|
|
|
google.maps.event.addListener(infoWindow, 'closeclick', function() {
|
|
|
|
isWindowOpen = false;
|
|
|
|
});
|
|
|
|
activeInfoWindow = infoWindow;
|
2011-09-15 21:41:26 +00:00
|
|
|
activeThingId = thingId;
|
2011-09-03 20:47:28 +00:00
|
|
|
activeMarker = marker;
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/info_window',
|
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': thingId
|
2011-09-03 20:47:28 +00:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
isWindowOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2011-09-15 21:41:26 +00:00
|
|
|
thingIds.push(thingId);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
function addMarkersAround(lat, lng) {
|
2012-01-14 19:59:59 +00:00
|
|
|
var submitButton = $("#address_form input[type='submit']");
|
2011-09-03 20:47:28 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-09-15 21:41:26 +00:00
|
|
|
url: '/things.json',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
|
|
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
|
|
|
'lat': lat,
|
|
|
|
'lng': lng,
|
|
|
|
'limit': $('#address_form input[name="limit"]').val()
|
|
|
|
},
|
2012-01-14 19:59:59 +00:00
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
},
|
2011-09-03 20:47:28 +00:00
|
|
|
success: function(data) {
|
2012-01-14 19:59:59 +00:00
|
|
|
$(submitButton).attr("disabled", false);
|
2011-09-03 20:47:28 +00:00
|
|
|
if(data.errors) {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#address').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#address').focus();
|
|
|
|
} else {
|
|
|
|
$('#address_label').removeClass('error', 500);
|
|
|
|
$('#address').removeClass('error', 500);
|
|
|
|
var i = -1;
|
2011-09-15 21:41:26 +00:00
|
|
|
$(data).each(function(index, thing) {
|
|
|
|
if($.inArray(thing.id, thingIds) == -1) {
|
2011-09-03 20:47:28 +00:00
|
|
|
i += 1;
|
|
|
|
} else {
|
|
|
|
// continue
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
setTimeout(function() {
|
2012-01-14 19:59:59 +00:00
|
|
|
var point = new google.maps.LatLng(thing.lat, thing.lng);
|
2011-09-15 21:41:26 +00:00
|
|
|
if(thing.user_id) {
|
2012-01-14 19:59:59 +00:00
|
|
|
var color = 'green';
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 19:59:59 +00:00
|
|
|
var color = 'red';
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
2012-01-14 19:59:59 +00:00
|
|
|
addMarker(thing.id, point, color);
|
2011-09-03 20:47:28 +00:00
|
|
|
}, i * 100);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
google.maps.event.addListener(map, 'dragend', function() {
|
2012-01-14 19:59:59 +00:00
|
|
|
var center = map.getCenter();
|
2011-09-03 20:47:28 +00:00
|
|
|
addMarkersAround(center.lat(), center.lng());
|
|
|
|
});
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#address_form').live('submit', function() {
|
2011-09-03 20:47:28 +00:00
|
|
|
var submitButton = $("#address_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
if($('#address').val() === '') {
|
|
|
|
$(submitButton).attr("disabled", false);
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#address').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#address').focus();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/address.json',
|
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
|
|
|
'authenticity_token': $('#address_form input[name="authenticity_token"]').val(),
|
|
|
|
'city_state': $('#city_state').val(),
|
|
|
|
'address': $('#address').val()
|
|
|
|
},
|
2012-01-14 19:59:59 +00:00
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#address').parent().addClass('error');
|
2012-01-14 19:59:59 +00:00
|
|
|
$('#address').focus();
|
|
|
|
},
|
2011-09-03 20:47:28 +00:00
|
|
|
success: function(data) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
if(data.errors) {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#address').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#address').focus();
|
|
|
|
} else {
|
2012-01-14 19:59:59 +00:00
|
|
|
$('#address_label').removeClass('error', 500);
|
|
|
|
$('#address').removeClass('error', 500);
|
2011-09-03 20:47:28 +00:00
|
|
|
addMarkersAround(data[0], data[1]);
|
2012-01-14 19:59:59 +00:00
|
|
|
var center = new google.maps.LatLng(data[0], data[1]);
|
|
|
|
map.setCenter(center);
|
2012-01-25 23:59:40 +00:00
|
|
|
map.setZoom(19);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2011-12-25 07:23:19 +00:00
|
|
|
// Focus on the first non-empty text input or password field
|
|
|
|
function setComboFormFocus() {
|
2012-01-02 12:36:34 +00:00
|
|
|
$('#combo-form input[type="email"], #combo-form input[type="text"]:visible, #combo-form input[type="password"]:visible, #combo-form input[type="submit"]:visible, #combo-form input[type="tel"]:visible, #combo-form button:visible').each(function(index) {
|
2011-12-25 07:23:19 +00:00
|
|
|
if($(this).val() === "" || $(this).attr('type') === 'submit' || this.tagName.toLowerCase() === 'button') {
|
|
|
|
$(this).focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$('#combo-form input[type="radio"]').live('click', function() {
|
2012-01-14 19:59:59 +00:00
|
|
|
var radioInput = $(this);
|
|
|
|
if('new' == radioInput.val()) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#combo-form').data('state', 'user_sign_up');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_forgot_password_fields').slideUp();
|
|
|
|
$('#user_sign_in_fields').slideUp();
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#user_sign_up_fields').slideDown(function() {
|
|
|
|
setComboFormFocus();
|
|
|
|
});
|
2012-01-14 19:59:59 +00:00
|
|
|
} else if('existing' == radioInput.val()) {
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_sign_up_fields').slideUp();
|
|
|
|
$('#user_sign_in_fields').slideDown(function() {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#combo-form').data('state', 'user_sign_in');
|
|
|
|
setComboFormFocus();
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_forgot_password_link').click(function() {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#combo-form').data('state', 'user_forgot_password');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_sign_in_fields').slideUp();
|
|
|
|
$('#user_forgot_password_fields').slideDown(function() {
|
2011-12-25 07:23:19 +00:00
|
|
|
setComboFormFocus();
|
2011-09-14 23:50:39 +00:00
|
|
|
$('#user_remembered_password_link').click(function() {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#combo-form').data('state', 'user_sign_in');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_forgot_password_fields').slideUp();
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#user_sign_in_fields').slideDown(function() {
|
|
|
|
setComboFormFocus();
|
|
|
|
});
|
2011-09-03 20:47:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#combo-form').live('submit', function() {
|
|
|
|
var submitButton = $("#combo-form input[type='submit']");
|
2011-09-03 20:47:28 +00:00
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
var errors = []
|
2012-01-25 19:15:56 +00:00
|
|
|
if(!/[\w\.%\+]+@[\w]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
2011-09-03 20:47:28 +00:00
|
|
|
errors.push($('#user_email'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(!$(this).data('state') || $(this).data('state') === 'user_sign_up') {
|
|
|
|
if($('#user_name').val() === '') {
|
|
|
|
errors.push($('#user_name'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if($('#user_password_confirmation').val().length < 6 || $('#user_password_confirmation').val().length > 20) {
|
|
|
|
errors.push($('#user_password_confirmation'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password_confirmation').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password_confirmation').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(errors.length > 0) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
errors[0].focus();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/users.json',
|
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
2011-12-25 07:23:19 +00:00
|
|
|
'authenticity_token': $('#combo-form input[name="authenticity_token"]').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'user': {
|
|
|
|
'email': $('#user_email').val(),
|
|
|
|
'name': $('#user_name').val(),
|
|
|
|
'organization': $('#user_organization').val(),
|
|
|
|
'voice_number': $('#user_voice_number').val(),
|
|
|
|
'sms_number': $('#user_sms_number').val(),
|
|
|
|
'password': $('#user_password_confirmation').val(),
|
|
|
|
'password_confirmation': $('#user_password_confirmation').val()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
2012-01-14 19:59:59 +00:00
|
|
|
var data = $.parseJSON(jqXHR.responseText);
|
2011-09-03 20:47:28 +00:00
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
if(data.errors.email) {
|
|
|
|
errors.push($('#user_email'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.name) {
|
|
|
|
errors.push($('#user_name'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.organization) {
|
|
|
|
errors.push($('#user_organization'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_organization').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.voice_number) {
|
|
|
|
errors.push($('#user_voice_number'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_voice_number').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.sms_number) {
|
|
|
|
errors.push($('#user_sms_number'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_sms_number').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.password) {
|
|
|
|
errors.push($('#user_password_confirmation'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password_confirmation').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
errors[0].focus();
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-12-25 07:23:19 +00:00
|
|
|
url: '/sidebar/search',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
|
|
|
'flash': {
|
2011-09-16 05:00:04 +00:00
|
|
|
'notice': "<%= I18n.t("notices.signed_up") %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if($(this).data('state') === 'user_sign_in') {
|
|
|
|
if($('#user_password').val().length < 6 || $('#user_password').val().length > 20) {
|
|
|
|
errors.push($('#user_password'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(errors.length > 0) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
errors[0].focus();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/users/sign_in.json',
|
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
2011-12-25 07:23:19 +00:00
|
|
|
'authenticity_token': $('#combo-form input[name="authenticity_token"]').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'user': {
|
|
|
|
'email': $('#user_email').val(),
|
|
|
|
'password': $('#user_password').val(),
|
|
|
|
'remember_me': $('#user_remember_me').val()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_password').focus();
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-12-25 07:23:19 +00:00
|
|
|
url: '/sidebar/search',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
|
|
|
'flash': {
|
2011-09-16 05:00:04 +00:00
|
|
|
'notice': "<%= I18n.t("notices.signed_in") %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else if($(this).data('state') === 'user_forgot_password') {
|
|
|
|
if(errors.length > 0) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
errors[0].focus();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/users/password.json',
|
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
2011-12-25 07:23:19 +00:00
|
|
|
'authenticity_token': $('#combo-form input[name="authenticity_token"]').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'user': {
|
|
|
|
'email': $('#user_email').val()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
$('#user_email').focus();
|
|
|
|
},
|
|
|
|
success: function() {
|
2011-12-25 07:23:19 +00:00
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
$('#user_remembered_password_link').click();
|
|
|
|
$('#user_password').focus();
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#adoption_form').live('submit', function() {
|
|
|
|
var submitButton = $("#adoption_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
2011-09-15 21:41:26 +00:00
|
|
|
url: '/things.json',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'id': $('#thing_id').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'utf8': '✓',
|
|
|
|
'authenticity_token': $('#adoption_form input[name="authenticity_token"]').val(),
|
|
|
|
'_method': 'put',
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing': {
|
|
|
|
'user_id': $('#thing_user_id').val(),
|
|
|
|
'name': $('#thing_name').val()
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/info_window',
|
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': activeThingId,
|
2011-09-03 20:47:28 +00:00
|
|
|
'flash': {
|
2011-09-16 05:00:04 +00:00
|
|
|
'notice': "<%= I18n.t("notices.adopted", :thing => I18n.t("defaults.thing")) %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.close();
|
2011-09-03 20:47:28 +00:00
|
|
|
activeInfoWindow.setContent(data);
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.open(map, activeMarker);
|
2012-01-14 19:59:59 +00:00
|
|
|
activeMarker.setIcon(greenMarkerImage);
|
2011-09-03 20:47:28 +00:00
|
|
|
activeMarker.setAnimation(google.maps.Animation.BOUNCE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#abandon_form').live('submit', function() {
|
2011-09-16 05:00:04 +00:00
|
|
|
var answer = window.confirm("Are you sure you want to abandon this <%= I18n.t("defaults.thing") %>?")
|
2011-09-03 20:47:28 +00:00
|
|
|
if(answer) {
|
|
|
|
var submitButton = $("#abandon_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
2011-09-15 21:41:26 +00:00
|
|
|
url: '/things.json',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'id': $('#thing_id').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'utf8': '✓',
|
|
|
|
'authenticity_token': $('#abandon_form input[name="authenticity_token"]').val(),
|
|
|
|
'_method': 'put',
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing': {
|
|
|
|
'user_id': $('#thing_user_id').val(),
|
|
|
|
'name': $('#thing_name').val()
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/info_window',
|
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': activeThingId,
|
2011-09-03 20:47:28 +00:00
|
|
|
'flash': {
|
2011-12-25 07:23:19 +00:00
|
|
|
'warning': "<%= I18n.t("notices.abandoned", :thing => I18n.t("defaults.thing").capitalize) %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.close();
|
2011-09-03 20:47:28 +00:00
|
|
|
activeInfoWindow.setContent(data);
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.open(map, activeMarker);
|
2012-01-14 19:59:59 +00:00
|
|
|
activeMarker.setIcon(redMarkerImage);
|
2011-09-03 20:47:28 +00:00
|
|
|
activeMarker.setAnimation(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#edit_profile_link').live('click', function() {
|
|
|
|
var link = $(this);
|
|
|
|
$(link).addClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/users/edit',
|
|
|
|
error: function(jqXHR) {
|
2012-01-14 22:31:01 +00:00
|
|
|
$(link).removeClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#edit_form').live('submit', function() {
|
|
|
|
var submitButton = $("#edit_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
var errors = []
|
|
|
|
if(!/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($('#user_email').val())) {
|
|
|
|
errors.push($('#user_email'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if($('#user_name').val() === '') {
|
|
|
|
errors.push($('#user_name'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
2012-01-02 12:36:34 +00:00
|
|
|
if($('#user_zip').val() != '' && !/^\d{5}(-\d{4})?$/.test($('#user_zip').val())) {
|
|
|
|
errors.push($('#user_zip'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_zip').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_zip').parent().removeClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
2011-09-03 20:47:28 +00:00
|
|
|
if($('#user_password').val() && ($('#user_password').val().length < 6 || $('#user_password').val().length > 20)) {
|
|
|
|
errors.push($('#user_password'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if($('#user_current_password').val().length < 6 || $('#user_current_password').val().length > 20) {
|
|
|
|
errors.push($('#user_current_password'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_current_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
} else {
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_current_password').parent().removeClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(errors.length > 0) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
errors[0].focus();
|
|
|
|
} else {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/users.json',
|
|
|
|
data: {
|
|
|
|
'id': $('#id').val(),
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': activeThingId,
|
2011-09-03 20:47:28 +00:00
|
|
|
'utf8': '✓',
|
|
|
|
'authenticity_token': $('#edit_form input[name="authenticity_token"]').val(),
|
|
|
|
'_method': 'put',
|
|
|
|
'user': {
|
|
|
|
'email': $('#user_email').val(),
|
|
|
|
'name': $('#user_name').val(),
|
|
|
|
'organization': $('#user_organization').val(),
|
|
|
|
'voice_number': $('#user_voice_number').val(),
|
|
|
|
'sms_number': $('#user_sms_number').val(),
|
2012-01-02 12:36:34 +00:00
|
|
|
'address_1': $('#user_address_1').val(),
|
|
|
|
'address_2': $('#user_address_2').val(),
|
|
|
|
'city': $('#user_city').val(),
|
|
|
|
'state': $('#user_state').val(),
|
|
|
|
'zip': $('#user_zip').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'password': $('#user_password').val(),
|
|
|
|
'password_confirmation': $('#user_password').val(),
|
|
|
|
'current_password': $('#user_current_password').val()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
2012-01-14 19:59:59 +00:00
|
|
|
var data = $.parseJSON(jqXHR.responseText);
|
2011-09-03 20:47:28 +00:00
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
if(data.errors.email) {
|
|
|
|
errors.push($('#user_email'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_email').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.name) {
|
|
|
|
errors.push($('#user_name'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_name').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.organization) {
|
|
|
|
errors.push($('#user_organization'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_organization').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.voice_number) {
|
|
|
|
errors.push($('#user_voice_number'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_voice_number').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.sms_number) {
|
|
|
|
errors.push($('#user_sms_number'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_sms_number').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
2012-01-02 12:36:34 +00:00
|
|
|
if(data.errors.address_1) {
|
|
|
|
errors.push($('#user_address_1'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_address_1').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
|
|
|
if(data.errors.address_2) {
|
|
|
|
errors.push($('#user_address_2'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_address_2').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
|
|
|
if(data.errors.city) {
|
|
|
|
errors.push($('#user_city'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_city').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
|
|
|
if(data.errors.state) {
|
|
|
|
errors.push($('#user_state'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_state').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
|
|
|
if(data.errors.zip) {
|
|
|
|
errors.push($('#user_zip'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_zip').parent().addClass('error');
|
2012-01-02 12:36:34 +00:00
|
|
|
}
|
2011-09-03 20:47:28 +00:00
|
|
|
if(data.errors.password) {
|
|
|
|
errors.push($('#user_password'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
if(data.errors.current_password) {
|
|
|
|
errors.push($('#user_current_password'));
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#user_current_password').parent().addClass('error');
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
errors[0].focus();
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#sign_out_link').live('click', function() {
|
|
|
|
var link = $(this);
|
|
|
|
$(link).addClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/users/sign_out.json',
|
|
|
|
error: function(jqXHR) {
|
2012-01-14 22:31:01 +00:00
|
|
|
$(link).removeClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-12-25 07:23:19 +00:00
|
|
|
url: '/sidebar/combo_form',
|
2011-09-03 20:47:28 +00:00
|
|
|
data: {
|
|
|
|
'flash': {
|
2011-12-25 07:23:19 +00:00
|
|
|
'warning': "<%= I18n.t("notices.signed_out") %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#sign_in_form').live('submit', function() {
|
|
|
|
var submitButton = $("#sign_in_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/users/sign_in',
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.close();
|
2011-09-03 20:47:28 +00:00
|
|
|
activeInfoWindow.setContent(data);
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.open(map, activeMarker);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2012-01-14 22:31:01 +00:00
|
|
|
$('#back_link').live('click', function() {
|
|
|
|
var link = $(this);
|
|
|
|
$(link).addClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
2011-12-25 07:23:19 +00:00
|
|
|
url: '/sidebar/search',
|
2011-09-03 20:47:28 +00:00
|
|
|
error: function(jqXHR) {
|
2012-01-14 22:31:01 +00:00
|
|
|
$(link).removeClass('disabled');
|
2011-09-03 20:47:28 +00:00
|
|
|
},
|
|
|
|
success: function(data) {
|
2011-12-25 07:23:19 +00:00
|
|
|
$('#content').html(data);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$('#reminder_form').live('submit', function() {
|
|
|
|
var submitButton = $("#reminder_form input[type='submit']");
|
|
|
|
$(submitButton).attr("disabled", true);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: '/reminders.json',
|
|
|
|
data: {
|
|
|
|
'utf8': '✓',
|
2011-12-25 07:23:19 +00:00
|
|
|
'authenticity_token': $('#reminder_form input[name="authenticity_token"]').val(),
|
2011-09-03 20:47:28 +00:00
|
|
|
'reminder': {
|
|
|
|
'from_user_id': $('#reminder_from_user_id').val(),
|
|
|
|
'to_user_id': $('#reminder_to_user_id').val(),
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': activeThingId
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function(jqXHR) {
|
|
|
|
$(submitButton).attr("disabled", false);
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: '/info_window',
|
|
|
|
data: {
|
2011-09-15 21:41:26 +00:00
|
|
|
'thing_id': activeThingId,
|
2011-09-03 20:47:28 +00:00
|
|
|
'flash': {
|
2011-09-16 05:00:04 +00:00
|
|
|
'notice': "<%= I18n.t("notices.reminder_sent") %>"
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.close();
|
2011-09-03 20:47:28 +00:00
|
|
|
activeInfoWindow.setContent(data);
|
2012-01-14 22:31:01 +00:00
|
|
|
activeInfoWindow.open(map, activeMarker);
|
2011-09-03 20:47:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2011-12-25 17:17:49 +00:00
|
|
|
$('.alert-message').alert();
|
|
|
|
$('#tos').modal({
|
|
|
|
backdrop: true,
|
|
|
|
keyboard: true
|
|
|
|
});
|
2011-09-03 20:47:28 +00:00
|
|
|
});
|