Merge branch 'develop' of bitbucket.org:jamkazam/jam-cloud into develop

This commit is contained in:
Brian Smith 2014-03-18 21:52:54 -04:00
commit 44da456a42
10 changed files with 118 additions and 49 deletions

View File

@ -12,6 +12,7 @@
var loadingCitiesData = false;
var loadingRegionsData = false;
var loadingCountriesData = false;
var nilOptionStr = '<option value=""></option>';
var nilOptionText = 'n/a';
function beforeShow(data) {
@ -109,18 +110,20 @@
function populateCountries(countries, userCountry) {
// countries has the format ["US", ...]
var foundCountry = false;
var countrySelect = getCountryElement();
countrySelect.children().remove();
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
countrySelect.append(nilOption);
$.each(countries, function(index, country) {
if(!country) return;
var option = $('<option></option>');
var option = $(nilOptionStr);
option.text(country);
option.attr("value", country);
@ -132,10 +135,53 @@
});
if(!foundCountry) {
// in this case, the user has a country that is not in the database
// this can happen in a development/test scenario, but let's assume it can
// happen in production too.
var option = $('<option></option>');
// in this case, the user has a country that is not in the database
// this can happen in a development/test scenario, but let's assume it can
// happen in production too.
var option = $(nilOptionStr);
option.text(userCountry);
option.attr("value", userCountry);
countrySelect.append(option);
}
countrySelect.val(userCountry);
countrySelect.attr("disabled", null)
context.JK.dropdown(countrySelect);
}
function populateCountriesx(countriesx, userCountry) {
// countriesx has the format [{countrycode: "US", countryname: "United States"}, ...]
var foundCountry = false;
var countrySelect = getCountryElement();
countrySelect.children().remove();
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
countrySelect.append(nilOption);
$.each(countriesx, function(index, countryx) {
if(!countryx.countrycode) return;
var option = $(nilOptionStr);
option.text(countryx.countryname);
option.attr("value", countryx.countrycode);
if(countryx.countrycode == userCountry) {
foundCountry = true;
}
countrySelect.append(option);
});
if(!foundCountry) {
// in this case, the user has a country that is not in the database
// this can happen in a development/test scenario, but let's assume it can
// happen in production too.
var option = $(nilOptionStr);
option.text(userCountry);
option.attr("value", userCountry);
countrySelect.append(option);
@ -152,14 +198,14 @@
var regionSelect = getRegionElement()
regionSelect.children().remove()
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
regionSelect.append(nilOption);
$.each(regions, function(index, region) {
if(!region) return;
var option = $('<option></option>')
var option = $(nilOptionStr)
option.text(region)
option.attr("value", region)
@ -176,14 +222,14 @@
var citySelect = getCityElement();
citySelect.children().remove();
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
citySelect.append(nilOption);
$.each(cities, function(index, city) {
if(!city) return;
var option = $('<option></option>')
var option = $(nilOptionStr)
option.text(city)
option.attr("value", city)
@ -248,8 +294,8 @@
// make the 3 slower requests, which only matter if the user wants to affect their ISP or location
api.getCountries()
.done(function(countries) { populateCountries(countries["countries"], userDetail.country); } )
api.getCountriesx()
.done(function(countriesx) { populateCountriesx(countriesx["countriesx"], userDetail.country); } )
.fail(app.ajaxError)
.always(function() { loadingCountriesData = false; })
@ -394,7 +440,7 @@
loadingRegionsData = true;
regionElement.children().remove()
regionElement.append($('<option value=""></option>').text('loading...'))
regionElement.append($(nilOptionStr).text('loading...'))
api.getRegions({ country: selectedCountry })
.done(getRegionsDone)
@ -405,7 +451,7 @@
}
else {
regionElement.children().remove()
regionElement.append($('<option value=""></option>').text(nilOptionText))
regionElement.append($(nilOptionStr).text(nilOptionText))
}
}
@ -419,7 +465,7 @@
loadingCitiesData = true;
cityElement.children().remove()
cityElement.append($('<option value=""></option>').text('loading...'))
cityElement.append($(nilOptionStr).text('loading...'))
api.getCities({ country: selectedCountry, region: selectedRegion })
.done(getCitiesDone)
@ -430,7 +476,7 @@
}
else {
cityElement.children().remove()
cityElement.append($('<option value=""></option>').text(nilOptionText))
cityElement.append($(nilOptionStr).text(nilOptionText))
}
}

View File

@ -18,6 +18,7 @@
var userIds = [];
var userPhotoUrls = [];
var selectedFriendIds = {};
var nilOptionStr = '<option value=""></option>';
var nilOptionText = 'n/a';
var bandId = '';
@ -300,27 +301,27 @@
}
function loadCountries(initialCountry, onCountriesLoaded) {
var $country = $("#band-country");
var countrySelect = $("#band-country");
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
$country.append(nilOption);
countrySelect.append(nilOption);
rest.getCountries().done(function (response) {
$.each(response["countries"], function (index, country) {
if (!country) return;
var option = $('<option></option>');
option.text(country);
option.attr("value", country);
rest.getCountriesx().done(function (response) {
$.each(response["countriesx"], function (index, countryx) {
if (!countryx.countrycode) return;
var option = $(nilOptionStr);
option.text(countryx.countryname);
option.attr("value", countryx.countrycode);
if (initialCountry === country) {
if (initialCountry === countryx.countrycode) {
option.attr("selected", "selected");
}
$country.append(option);
countrySelect.append(option);
});
context.JK.dropdown($country);
context.JK.dropdown(countrySelect);
if (onCountriesLoaded) {
onCountriesLoaded();
@ -333,7 +334,7 @@
$region.empty();
var selectedCountry = $("#band-country").val();
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
$region.append(nilOption);
@ -341,7 +342,7 @@
rest.getRegions({'country': selectedCountry}).done(function (response) {
$.each(response["regions"], function (index, region) {
if (!region) return;
var option = $('<option></option>');
var option = $(nilOptionStr);
option.text(region);
option.attr("value", region);
@ -368,7 +369,7 @@
var selectedCountry = $("#band-country").val();
var selectedRegion = $("#band-region").val();
var nilOption = $('<option value=""></option>');
var nilOption = $(nilOptionStr);
nilOption.text(nilOptionText);
$city.append(nilOption);
@ -376,7 +377,7 @@
rest.getCities({'country': selectedCountry, 'region': selectedRegion}).done(function (response) {
$.each(response["cities"], function (index, city) {
if (!city) return;
var option = $('<option></option>');
var option = $(nilOptionStr);
option.text(city);
option.attr("value", city);

View File

@ -195,7 +195,7 @@
var obj = {
method: 'feed',
link: signupUrl,
picture: 'http://www.jamkazam.com/assets/web/logo-512.png',
picture: 'http://www.jamkazam.com/assets/web/logo-256.png',
name: 'Join me on JamKazam',
caption: 'Play live music in real-time sessions with others over the Internet, as if in the same room.',
description: '',
@ -216,13 +216,7 @@
function showFacebookDialog(evt) {
if (!(evt === undefined)) evt.stopPropagation();
facebookHelper.promptLogin()
.done(function(response) {
if (response && response.status == "connected") {
showFeedDialog();
}
})
showFeedDialog();
}
// END FB handlers

View File

@ -301,6 +301,12 @@
});
}
function getCountriesx() {
return $.ajax('/api/countriesx', {
dataType : 'json'
});
}
function getIsps(options) {
var country = options["country"]
@ -911,6 +917,7 @@
this.getCities = getCities;
this.getRegions = getRegions;
this.getCountries = getCountries;
this.getCountriesx = getCountriesx;
this.getIsps = getIsps;
this.getResolvedLocation = getResolvedLocation;
this.getInstruments = getInstruments;

View File

@ -3,8 +3,14 @@ class ApiMaxmindRequestsController < ApiController
respond_to :json
def countries
countries = MaxMindManager.countries()
render :json => { :countries => countries }, :status => 200
raise "no longer supported, use countriesx"
#countries = MaxMindManager.countries()
#render :json => { :countries => countries }, :status => 200
end
def countriesx
countriesx = MaxMindManager.countriesx()
render :json => { :countriesx => countriesx }, :status => 200
end
def regions

View File

@ -439,7 +439,7 @@ class UsersController < ApplicationController
@location[:country] = "US" if @location[:country].nil?
# right now we only accept US signups for beta
@countries = MaxMindManager.countries()
@countriesx = MaxMindManager.countriesx()
# populate regions based on current country
@regions = MaxMindManager.regions(@location[:country])
@cities = @location[:state].nil? ? [] : MaxMindManager.cities(@location[:country], @location[:state])

View File

@ -38,9 +38,9 @@
<%= f.label :country, "Country:" %>
<select id="country_select" name="jam_ruby_user[country]" autocomplete="off" class="easydropdown">
<option class="label" value="" <%= @location[:country].blank? ? "selected" : "" %>>Select Country</option>
<% @countries.each do |country| %>
<% unless country.blank? %>
<option value="<%= country %>" <%= @location[:country] == country ? "selected" : "" %>><%= country %></option>
<% @countriesx.each do |country| %>
<% unless country[:countrycode].blank? %>
<option value="<%= country %>" <%= @location[:country] == country[:countrycode] ? "selected" : "" %>><%= country[:countryname] %></option>
<% end %>
<% end %>
</select>

View File

@ -316,6 +316,7 @@ SampleApp::Application.routes.draw do
# Location lookups
match '/countries' => 'api_maxmind_requests#countries', :via => :get
match '/countriesx' => 'api_maxmind_requests#countriesx', :via => :get
match '/regions' => 'api_maxmind_requests#regions', :via => :get
match '/cities' => 'api_maxmind_requests#cities', :via => :get
match '/isps' => 'api_maxmind_requests#isps', :via => :get

View File

@ -63,8 +63,22 @@ class MaxMindManager < BaseManager
# end
#end
raise "no longer supported, use countriesx"
# returns ordered array of Country objects (countrycode, countryname)
Country.get_all.map { |c| c.countrycode }
#Country.get_all.map { |c| c.countrycode }
end
def self.countriesx()
#ActiveRecord::Base.connection_pool.with_connection do |connection|
# pg_conn = connection.instance_variable_get("@connection")
# pg_conn.exec("SELECT DISTINCT country FROM max_mind_geo ORDER BY country ASC").map do |tuple|
# tuple["country"]
# end
#end
# returns ordered array of Country objects (countrycode, countryname)
Country.get_all.map { |c| {countrycode: c.countrycode, countryname: c.countryname} }
end

View File

@ -11,9 +11,9 @@ describe MaxMindManager do
end
it "looks up countries successfully" do
countries = MaxMindManager.countries()
countries = MaxMindManager.countriesx()
countries.length.should == 1
countries[0] == "US"
countries[0] == {countrycode: "US", countryname: "United States"}
end
it "looks up regions successfully" do