From fd21e0945c1ed8a6efe9c7749ae207809845dd53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Mon, 19 Sep 2011 10:30:30 +0000 Subject: [PATCH] Dynamic list of countris git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2909 44740490-163a-0410-bde0-09ae8108e29a --- .../www/discojuice/discojuice.control.js | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/modules/discojuice/www/discojuice/discojuice.control.js b/modules/discojuice/www/discojuice/discojuice.control.js index cc9d1551c..02a1a0285 100644 --- a/modules/discojuice/www/discojuice/discojuice.control.js +++ b/modules/discojuice/www/discojuice/discojuice.control.js @@ -52,6 +52,12 @@ DiscoJuice.Control = { that.data = data; that.parent.Utils.log('Successfully loaded metadata (' + data.length + ')'); that.postLoad(); + + if (that.parent.Utils.options.get('country', false)) { + that.filterCountrySetup(); + } + that.getCountry(); + }); @@ -76,11 +82,6 @@ DiscoJuice.Control = { this.discoReadSetup(); this.discoSubReadSetup(); this.searchboxSetup(); - if (this.parent.Utils.options.get('country', false)) { - this.filterCountrySetup(); - } - - this.getCountry(); }, @@ -642,6 +643,23 @@ DiscoJuice.Control = { "filterCountrySetup": function (choice) { var that = this; var key; + + console.log('filterCountrySetup()'); + + // Reduce country list to those in metadata + var validCountry = {}; + for (key in this.data) { + if (this.data[key].country && this.data[key].country !== '_all_') { + validCountry[this.data[key].country] = true; + } + } + console.log(validCountry); + + var countries = 0; + for (key in validCountry) { + countries++; + } + var preset = this.parent.Utils.options.get('setCountry'); if (!choice && preset) { @@ -658,9 +676,10 @@ DiscoJuice.Control = { } for (key in this.parent.Constants.Countries) { + console.log('Considering: ' + this.parent.Constants.Countries[key]); if (key === choice) { ftext += '<option value="' + key + '" selected="selected">' + this.parent.Constants.Countries[key] + '</option>'; - } else { + } else if (validCountry[key]) { ftext += '<option value="' + key + '" >' + this.parent.Constants.Countries[key] + '</option>'; } } -- GitLab