VRFS-878 use IP address to default location for band setup

This commit is contained in:
Brian Smith 2013-12-08 22:31:49 -05:00
parent 5856c5d176
commit 833eb45379
4 changed files with 59 additions and 30 deletions

View File

@ -246,7 +246,17 @@
}
else {
loadGenres();
loadCountries();
rest.getResolvedLocation()
.done(function(location) {
loadCountries(location.country, function() {
loadRegions(location.region, function() {
loadCities(location.city);
});
});
});
$("#band-setup-title").html("set up band");
$("#btn-band-setup-save").html("CREATE BAND");
}
@ -261,7 +271,7 @@
loadGenres(band.genres);
loadCountries(band.country, function() {
loadRegions(band.state, function () {
loadRegions(band.region, function() {
loadCities(band.city);
});
});
@ -357,24 +367,26 @@
nilOption.text(nilOptionText);
$region.append(nilOption);
rest.getRegions({'country': selectedCountry}).done(function(response) {
$.each(response["regions"], function(index, region) {
if(!region) return;
var option = $('<option></option>');
option.text(region);
option.attr("value", region);
if (selectedCountry) {
rest.getRegions({'country': selectedCountry}).done(function(response) {
$.each(response["regions"], function(index, region) {
if(!region) return;
var option = $('<option></option>');
option.text(region);
option.attr("value", region);
if (initialRegion === region) {
option.attr("selected", "selected");
if (initialRegion === region) {
option.attr("selected", "selected");
}
$region.append(option);
});
if (onRegionsLoaded) {
onRegionsLoaded();
}
$region.append(option);
});
if (onRegionsLoaded) {
onRegionsLoaded();
}
});
}
}
function loadCities(initialCity) {
@ -387,20 +399,22 @@
nilOption.text(nilOptionText);
$city.append(nilOption);
rest.getCities({'country': selectedCountry, 'region': selectedRegion}) .done(function(response) {
$.each(response["cities"], function(index, city) {
if(!city) return;
var option = $('<option></option>');
option.text(city);
option.attr("value", city);
if (selectedCountry && selectedRegion) {
rest.getCities({'country': selectedCountry, 'region': selectedRegion}) .done(function(response) {
$.each(response["cities"], function(index, city) {
if(!city) return;
var option = $('<option></option>');
option.text(city);
option.attr("value", city);
if (initialCity === city) {
option.attr("selected", "selected");
}
if (initialCity === city) {
option.attr("selected", "selected");
}
$city.append(option);
$city.append(option);
});
});
});
}
}
function friendSelectorCallback(newSelections) {
@ -467,13 +481,14 @@
$('#band-country').on('change', function(evt) {
evt.stopPropagation();
loadRegions('');
loadRegions();
loadCities();
return false;
});
$('#band-region').on('change', function(evt) {
evt.stopPropagation();
loadCities('');
loadCities();
return false;
});

View File

@ -184,6 +184,12 @@
});
}
function getResolvedLocation() {
return $.ajax('/api/resolved_location', {
dataType: 'json'
});
}
function getInstruments(options) {
return $.ajax('/api/instruments', {
data : { },
@ -466,6 +472,7 @@
this.getRegions = getRegions;
this.getCountries = getCountries;
this.getIsps = getIsps;
this.getResolvedLocation = getResolvedLocation;
this.getInstruments = getInstruments;
this.getGenres = getGenres;
this.updateAvatar = updateAvatar;

View File

@ -34,4 +34,10 @@ class ApiMaxmindRequestsController < ApiController
end
end
# returns location hash (country, region, state) based on requesting IP
def resolved_location
location = MaxMindManager.lookup(request.remote_ip)
render :json => { :country => location[:country], :region => location[:state], :city => location[:city] }, :status => 200
end
end

View File

@ -259,6 +259,7 @@ SampleApp::Application.routes.draw do
match '/regions' => 'api_maxmind_requests#regions', :via => :get
match '/cities' => 'api_maxmind_requests#cities', :via => :get
match '/isps' => 'api_maxmind_requests#isps', :via => :get
match '/resolved_location' => 'api_maxmind_requests#resolved_location', :via => :get
# Recordings