mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
39 lines
10 KiB
CoffeeScript
39 lines
10 KiB
CoffeeScript
|
define [
|
||
|
"base"
|
||
|
], (App) ->
|
||
|
# TODO Get actual countries list from the DB
|
||
|
countriesList = [{ code : "af", name: "Afghanistan" }, { code : "ax", name: "Åland Islands" }, { code : "al", name: "Albania" }, { code : "dz", name: "Algeria" }, { code : "as", name: "American Samoa" }, { code : "ad", name: "Andorra" }, { code : "ao", name: "Angola" }, { code : "ai", name: "Anguilla" }, { code : "aq", name: "Antarctica" }, { code : "ag", name: "Antigua and Barbuda" }, { code : "ar", name: "Argentina" }, { code : "am", name: "Armenia" }, { code : "aw", name: "Aruba" }, { code : "au", name: "Australia" }, { code : "at", name: "Austria" }, { code : "az", name: "Azerbaijan" }, { code : "bs", name: "Bahamas" }, { code : "bh", name: "Bahrain" }, { code : "bd", name: "Bangladesh" }, { code : "bb", name: "Barbados" }, { code : "by", name: "Belarus" }, { code : "be", name: "Belgium" }, { code : "bz", name: "Belize" }, { code : "bj", name: "Benin" }, { code : "bm", name: "Bermuda" }, { code : "bt", name: "Bhutan" }, { code : "bo", name: "Bolivia" }, { code : "bq", name: "Bonaire, Saint Eustatius and Saba" }, { code : "ba", name: "Bosnia and Herzegovina" }, { code : "bw", name: "Botswana" }, { code : "bv", name: "Bouvet Island" }, { code : "br", name: "Brazil" }, { code : "io", name: "British Indian Ocean Territory" }, { code : "vg", name: "British Virgin Islands" }, { code : "bn", name: "Brunei" }, { code : "bg", name: "Bulgaria" }, { code : "bf", name: "Burkina Faso" }, { code : "bi", name: "Burundi" }, { code : "kh", name: "Cambodia" }, { code : "cm", name: "Cameroon" }, { code : "ca", name: "Canada" }, { code : "cv", name: "Cabo Verde" }, { code : "ky", name: "Cayman Islands" }, { code : "cf", name: "Central African Republic" }, { code : "td", name: "Chad" }, { code : "cl", name: "Chile" }, { code : "cn", name: "China" }, { code : "cx", name: "Christmas Island" }, { code : "cc", name: "Cocos (Keeling) Islands" }, { code : "co", name: "Colombia" }, { code : "km", name: "Comoros" }, { code : "cg", name: "Congo" }, { code : "ck", name: "Cook Islands" }, { code : "cr", name: "Costa Rica" }, { code : "ci", name: "Côte d'Ivoire" }, { code : "hr", name: "Croatia" }, { code : "cu", name: "Cuba" }, { code : "cw", name: "Curaçao" }, { code : "cy", name: "Cyprus" }, { code : "cz", name: "Czech Republic" }, { code : "kp", name: "Democratic People's Republic of Korea" }, { code : "cd", name: "Democratic Republic of the Congo" }, { code : "dk", name: "Denmark" }, { code : "dj", name: "Djibouti" }, { code : "dm", name: "Dominica" }, { code : "do", name: "Dominican Republic" }, { code : "ec", name: "Ecuador" }, { code : "eg", name: "Egypt" }, { code : "sv", name: "El Salvador" }, { code : "gq", name: "Equatorial Guinea" }, { code : "er", name: "Eritrea" }, { code : "ee", name: "Estonia" }, { code : "et", name: "Ethiopia" }, { code : "fk", name: "Falkland Islands (Malvinas)" }, { code : "fo", name: "Faroe Islands" }, { code : "fj", name: "Fiji" }, { code : "fi", name: "Finland" }, { code : "fr", name: "France" }, { code : "gf", name: "French Guiana" }, { code : "pf", name: "French Polynesia" }, { code : "tf", name: "French Southern Territories" }, { code : "ga", name: "Gabon" }, { code : "gm", name: "Gambia" }, { code : "ge", name: "Georgia" }, { code : "de", name: "Germany" }, { code : "gh", name: "Ghana" }, { code : "gi", name: "Gibraltar" }, { code : "gr", name: "Greece" }, { code : "gl", name: "Greenland" }, { code : "gd", name: "Grenada" }, { code : "gp", name: "Guadeloupe" }, { code : "gu", name: "Guam" }, { code : "gt", name: "Guatemala" }, { code : "gg", name: "Guernsey" }, { code : "gn", name: "Guinea" }, { code : "gw", name: "Guinea-Bissau" }, { code : "gy", name: "Guyana" }, { code : "ht", name: "Haiti" }, { code : "hm", name: "Heard Island and McDonald Islands" }, { code : "va", name: "Holy See (Vatican City)" }, { code : "hn", name: "Honduras" }, { code : "hk", name: "Hong Kong" }, { code : "hu", name: "Hungary" }, { code : "is", name: "Iceland" }, { code : "in", name: "India" }, { code : "id", name: "Indonesia" }, { code : "ir", name: "Iran" }, { code : "iq", name: "Iraq" }, { code : "ie", name: "Ireland" },
|
||
|
universitiesByDomain = {}
|
||
|
|
||
|
App.factory "UserAffiliationsDataService", ["$http", "$q", "_", ($http, $q, _) ->
|
||
|
getCountries = () ->
|
||
|
$q.resolve(countriesList)
|
||
|
|
||
|
getUniversitiesFromCountry = (country) ->
|
||
|
if universities[country.code]?
|
||
|
universitiesFromCountry = universities[country.code]
|
||
|
else
|
||
|
universitiesFromCountry = $http
|
||
|
.get "http://www.overleaf.test:5000/universities/list.json" , { params: { country_code: country.code } }
|
||
|
.then (response) -> universities[country.code] = response.data
|
||
|
$q.resolve(universitiesFromCountry)
|
||
|
|
||
|
getUniversityDomainFromPartialDomainInput = (partialDomainInput) ->
|
||
|
if universitiesByDomain[partialDomainInput]?
|
||
|
$q.resolve universitiesByDomain[partialDomainInput]
|
||
|
else
|
||
|
$http.get "http://www.overleaf.test:5000/university/domains.json" , { params: { hostname: partialDomainInput, limit: 1 } }
|
||
|
.then (response) ->
|
||
|
university = response.data[0]
|
||
|
if university?
|
||
|
universitiesByDomain[university.hostname] = university
|
||
|
$q.resolve university
|
||
|
else
|
||
|
$q.reject null
|
||
|
|
||
|
return {
|
||
|
getCountries
|
||
|
getUniversitiesFromCountry
|
||
|
getUniversityDomainFromPartialDomainInput
|
||
|
}
|
||
|
]
|