FEATURE: Add user preferences field to select region (#44)

FEATURE: Add user preferences field to select region (#44)

diff --git a/assets/javascripts/connectors/user-custom-preferences/region.js.es6 b/assets/javascripts/connectors/user-custom-preferences/region.js.es6
new file mode 100644
index 0000000..1bdb740
--- /dev/null
+++ b/assets/javascripts/connectors/user-custom-preferences/region.js.es6
@@ -0,0 +1,25 @@
+import { action } from "@ember/object";
+import { TIME_ZONE_TO_REGION } from "discourse/plugins/discourse-calendar/lib/regions";
+
+export default {
+  setupComponent(args, component) {
+    component.setProperties({
+      @action
+      onChange(value) {
+        this.model.set("custom_fields.holidays-region", value);
+      },
+
+      @action
+      useCurrentRegion() {
+        this.model.set(
+          "custom_fields.holidays-region",
+          TIME_ZONE_TO_REGION[moment.tz.guess()] || "us"
+        );
+      }
+    });
+  },
+
+  shouldRender(args, component) {
+    return component.siteSettings.calendar_enabled;
+  }
+};
diff --git a/assets/javascripts/discourse/components/region-input.js.es6 b/assets/javascripts/discourse/components/region-input.js.es6
new file mode 100644
index 0000000..26b9099
--- /dev/null
+++ b/assets/javascripts/discourse/components/region-input.js.es6
@@ -0,0 +1,28 @@
+import { computed } from "@ember/object";
+import { HOLIDAY_REGIONS } from "discourse/plugins/discourse-calendar/lib/regions";
+import I18n from "I18n";
+import ComboBoxComponent from "select-kit/components/combo-box";
+
+export default ComboBoxComponent.extend({
+  pluginApiIdentifiers: ["timezone-input"],
+  classNames: ["timezone-input"],
+
+  selectKitOptions: {
+    filterable: true,
+    allowAny: false
+  },
+
+  content: computed(function() {
+    const localeNames = {};
+    JSON.parse(this.siteSettings.available_locales).forEach(locale => {
+      localeNames[locale.value] = locale.name;
+    });
+
+    return HOLIDAY_REGIONS.map(region => {
+      return {
+        name: I18n.t(`discourse_calendar.region.names.${region}`),
+        id: region
+      };
+    });
+  })
+});
diff --git a/assets/javascripts/lib/regions.js.es6 b/assets/javascripts/lib/regions.js.es6
new file mode 100644
index 0000000..ddc787c
--- /dev/null
+++ b/assets/javascripts/lib/regions.js.es6
@@ -0,0 +1,454 @@
+// DO NOT EDIT THIS FILE!!!
+// Update it by running `rake javascript:update_constants`
+
+export const HOLIDAY_REGIONS = [
+  "ar",
+  "at",
+  "au",
+  "au_nsw",
+  "au_vic",
+  "au_qld",
+  "au_nt",
+  "au_act",
+  "au_sa",
+  "au_wa",
+  "au_tas",
+  "au_tas_south",
+  "au_qld_cairns",
+  "au_qld_brisbane",
+  "au_tas_north",
+  "au_vic_melbourne",
+  "be_fr",
+  "be_nl",
+  "br",
+  "bg_en",
+  "bg_bg",
+  "ca",
+  "ca_qc",
+  "ca_ab",
+  "ca_sk",
+  "ca_on",
+  "ca_bc",
+  "ca_nb",
+  "ca_mb",
+  "ca_ns",
+  "ca_pe",
+  "ca_nl",
+  "ca_nt",
+  "ca_nu",
+  "ca_yt",
+  "us",
+  "ch_zh",
+  "ch_be",
+  "ch_lu",
+  "ch_ur",
+  "ch_sz",
+  "ch_ow",
+  "ch_nw",
+  "ch_gl",
+  "ch_zg",
+  "ch_fr",
+  "ch_so",
+  "ch_bs",
+  "ch_bl",
+  "ch_sh",
+  "ch_ar",
+  "ch_ai",
+  "ch_sg",
+  "ch_gr",
+  "ch_ag",
+  "ch_tg",
+  "ch_ti",
+  "ch_vd",
+  "ch_ne",
+  "ch_ge",
+  "ch_ju",
+  "ch_vs",
+  "ch",
+  "cl",
+  "co",
+  "cr",
+  "cz",
+  "dk",
+  "de",
+  "de_bw",
+  "de_by",
+  "de_he",
+  "de_nw",
+  "de_rp",
+  "de_sl",
+  "de_sn_sorbian",
+  "de_th_cath",
+  "de_sn",
+  "de_st",
+  "de_be",
+  "de_by_cath",
+  "de_by_augsburg",
+  "de_bb",
+  "de_mv",
+  "de_th",
+  "de_hb",
+  "de_hh",
+  "de_ni",
+  "de_sh",
+  "ee",
+  "el",
+  "es_pv",
+  "es_na",
+  "es_an",
+  "es_ib",
+  "es_cm",
+  "es_mu",
+  "es_m",
+  "es_ar",
+  "es_cl",
+  "es_cn",
+  "es_lo",
+  "es_ga",
+  "es_ce",
+  "es_o",
+  "es_ex",
+  "es",
+  "es_ct",
+  "es_v",
+  "es_vc",
+  "fi",
+  "fr_a",
+  "fr_m",
+  "fr",
+  "gb",
+  "gb_eng",
+  "gb_wls",
+  "gb_eaw",
+  "gb_nir",
+  "je",
+  "gb_jsy",
+  "gg",
+  "gb_gsy",
+  "gb_sct",
+  "gb_con",
+  "im",
+  "gb_iom",
+  "ge",
+  "hr",
+  "hk",
+  "hu",
+  "ie",
+  "is",
+  "it",
+  "it_ve",
+  "it_tv",
+  "it_vr",
+  "it_pd",
+  "it_fi",
+  "it_ge",
+  "it_to",
+  "it_rm",
+  "it_vi",
+  "it_bl",
+  "it_ro",
+  "kr",
+  "li",
+  "lt",
+  "lv",
+  "ma",
+  "mt_mt",
+  "mt_en",
+  "mx",
+  "mx_pue",
+  "nl",
+  "lu",
+  "no",
+  "nyse",
+  "nz",
+  "nz_sl",
+  "nz_we",
+  "nz_ak",
+  "nz_nl",
+  "nz_ne",
+  "nz_ot",
+  "nz_ta",
+  "nz_sc",
+  "nz_hb",
+  "nz_mb",
+  "nz_ca",
+  "nz_ch",
+  "nz_wl",
+  "pe",
+  "ph",
+  "pl",
+  "pt",
+  "pt_li",
+  "pt_po",
+  "ro",
+  "rs_cyrl",
+  "rs_la",
+  "ru",
+  "se",
+  "tn",
+  "tr",
+  "ua",
+  "us_fl",
+  "us_la",
+  "us_ct",
+  "us_de",
+  "us_gu",
+  "us_hi",
+  "us_in",
+  "us_ky",
+  "us_nj",
+  "us_nc",
+  "us_nd",
+  "us_pr",
+  "us_tn",
+  "us_ms",
+  "us_id",
+  "us_ar",
+  "us_tx",
+  "us_dc",
+  "us_md",
+  "us_va",
+  "us_vt",
+  "us_ak",
+  "us_ca",
+  "us_me",
+  "us_ma",
+  "us_al",
+  "us_ga",
+  "us_ne",
+  "us_mo",
+  "us_sc",
+  "us_wv",
+  "us_vi",
+  "us_ut",
+  "us_ri",
+  "us_az",
+  "us_co",
+  "us_il",
+  "us_mt",
+  "us_nm",
+  "us_ny",
+  "us_oh",
+  "us_pa",
+  "us_mi",
+  "us_mn",
+  "us_nv",
+  "us_or",
+  "us_sd",
+  "us_wa",
+  "us_wi",
+  "us_wy",
+  "us_ia",
+  "us_ks",
+  "us_nh",
+  "us_ok",
+  "za",
+  "ve",
+  "sk",
+  "si",
+  "jp",
+  "vi",
+  "sg",
+  "my",
+  "th",
+];
+
+export const TIME_ZONE_TO_REGION = {
+  "America/Argentina/Buenos_Aires": "ar",
+  "America/Argentina/Cordoba": "ar",
+  "America/Argentina/Salta": "ar",
+  "America/Argentina/Jujuy": "ar",
+  "America/Argentina/Tucuman": "ar",
+  "America/Argentina/Catamarca": "ar",
+  "America/Argentina/La_Rioja": "ar",
+  "America/Argentina/San_Juan": "ar",
+  "America/Argentina/Mendoza": "ar",
+  "America/Argentina/San_Luis": "ar",
+  "America/Argentina/Rio_Gallegos": "ar",
+  "America/Argentina/Ushuaia": "ar",
+  "Europe/Vienna": "at",
+  "Australia/Lord_Howe": "au",
+  "Antarctica/Macquarie": "au",
+  "Australia/Hobart": "au",
+  "Australia/Currie": "au",
+  "Australia/Melbourne": "au",
+  "Australia/Sydney": "au",
+  "Australia/Broken_Hill": "au",
+  "Australia/Brisbane": "au",
+  "Australia/Lindeman": "au",
+  "Australia/Adelaide": "au",
+  "Australia/Darwin": "au",
+  "Australia/Perth": "au",
+  "Australia/Eucla": "au",
+  "America/Noronha": "br",
+  "America/Belem": "br",
+  "America/Fortaleza": "br",
+  "America/Recife": "br",
+  "America/Araguaina": "br",
+  "America/Maceio": "br",
+  "America/Bahia": "br",
+  "America/Sao_Paulo": "br",
+  "America/Campo_Grande": "br",
+  "America/Cuiaba": "br",
+  "America/Santarem": "br",
+  "America/Porto_Velho": "br",
+  "America/Boa_Vista": "br",
+  "America/Manaus": "br",
+  "America/Eirunepe": "br",
+  "America/Rio_Branco": "br",
+  "America/St_Johns": "ca",
+  "America/Halifax": "ca",
+  "America/Glace_Bay": "ca",
+  "America/Moncton": "ca",
+  "America/Goose_Bay": "ca",
+  "America/Blanc-Sablon": "ca",
+  "America/Toronto": "ca",
+  "America/Nipigon": "ca",
+  "America/Thunder_Bay": "ca",
+  "America/Iqaluit": "ca",
+  "America/Pangnirtung": "ca",
+  "America/Atikokan": "ca",
+  "America/Winnipeg": "ca",
+  "America/Rainy_River": "ca",
+  "America/Resolute": "ca",
+  "America/Rankin_Inlet": "ca",
+  "America/Regina": "ca",
+  "America/Swift_Current": "ca",
+  "America/Edmonton": "ca",
+  "America/Cambridge_Bay": "ca",
+  "America/Yellowknife": "ca",
+  "America/Inuvik": "ca",
+  "America/Creston": "ca",
+  "America/Dawson_Creek": "ca",
+  "America/Fort_Nelson": "ca",
+  "America/Vancouver": "ca",
+  "America/Whitehorse": "ca",
+  "America/Dawson": "ca",
+  "Europe/Zurich": "ch",
+  "America/Santiago": "cl",
+  "America/Punta_Arenas": "cl",
+  "Pacific/Easter": "cl",
+  "America/Bogota": "co",
+  "America/Costa_Rica": "cr",
+  "Europe/Prague": "cz",
+  "Europe/Berlin": "de",
+  "Europe/Copenhagen": "dk",
+  "Europe/Tallinn": "ee",
+  "Europe/Madrid": "es",
+  "Africa/Ceuta": "es",
+  "Atlantic/Canary": "es",
+  "Europe/Helsinki": "fi",
+  "Europe/Paris": "fr",
+  "Europe/London": "gb",
+  "Asia/Tbilisi": "ge",
+  "Asia/Hong_Kong": "hk",
+  "Europe/Budapest": "hu",

[... diff too long, it was truncated ...]

GitHub sha: b8322322

This commit appears in #44 which was approved by ZogStriP. It was merged by udan11.