From 849af469f13d54977bcef8c05a5497a6ad3fa92e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Tue, 27 Sep 2011 07:21:31 +0000
Subject: [PATCH] Update for parallell processing. Some  UI fixes, partial
 support for local login box etc...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2924 44740490-163a-0410-bde0-09ae8108e29a
---
 .../www/discojuice/css/discojuice.css         |  58 ++++-
 .../www/discojuice/discojuice.control.js      | 199 +++++++++++-------
 .../www/discojuice/discojuice.misc.js         |  14 +-
 .../www/discojuice/discojuice.ui.js           |  60 +++++-
 .../discojuiceDiscoveryResponse.html          |  18 +-
 5 files changed, 256 insertions(+), 93 deletions(-)

diff --git a/modules/discojuice/www/discojuice/css/discojuice.css b/modules/discojuice/www/discojuice/css/discojuice.css
index ed30ae3f8..06e940811 100644
--- a/modules/discojuice/www/discojuice/css/discojuice.css
+++ b/modules/discojuice/www/discojuice/css/discojuice.css
@@ -1,10 +1,12 @@
 
+
 /*
  * Generic css for whole popup box
  */
 div.discojuice {
 	font-family: Arial;
-	font-size: small;
+	
+/*	font-size: small;*/
 	z-index: 100;
 	margin: 0;
 	padding: 0;
@@ -16,10 +18,10 @@ div.discojuice {
 
 }
 
-div.discojuice * {
+/*div.discojuice * {
 	color: #000;
 	background: none;
-}
+}*/
 
 div.discojuice p {
 	margin: 2px; padding: 0px;
@@ -27,6 +29,48 @@ div.discojuice p {
 
 
 
+
+
+
+div.discojuice form.discojuice_up {
+	padding: 0px; 
+	margin: 0px;
+	font-family: Helvetica;
+}
+div.discojuice form.discojuice_up h2 {
+	margin: 0px inherit 3px inherit;
+}
+div.discojuice form.discojuice_up  p{
+		padding: 0px; margin: 0px;
+}
+div.discojuice form.discojuice_up label.discojuice_up {
+	display: block;
+	margin: 22px 5px 0px 0px;
+	font-size: 160%;
+	color: #444;
+
+}
+div.discojuice form.discojuice_up input.discojuice_up {
+	width: 60%;
+	font-size: 200%;
+	border-radius: 6px;
+	border: 1px solid #aaa;
+	padding: 6px 20px;
+	background: #fff;
+	margin: 0px 5px 3px 0px;
+}
+div.discojuice form.discojuice_up input.submit {
+	font-size: 105px ! important;
+}
+
+
+div.discojuice div.discojuice_page {
+	
+}
+
+
+
+
 div.discojuice > div.top {
 
 	background: #fff;
@@ -132,6 +176,7 @@ div.discojuice div.scroller img.logo {
 
 div.discojuice div.scroller a {
 	padding: 3px 6px;
+	font-size: 100% ! important;
 }
 div.discojuice div.scroller a span {
 /*	margin: 3px;*/
@@ -300,7 +345,12 @@ div.discojuice div.scroller a.hothit {
 	text-shadow: 0 1px #fff;
 }
 
-
+div.discojuice div.scroller a.disabled span.title {
+	color: #999 !important;
+}
+div.discojuice div.scroller a.disabled span.location {
+	color: #999 !important;
+}
 
 
 
diff --git a/modules/discojuice/www/discojuice/discojuice.control.js b/modules/discojuice/www/discojuice/discojuice.control.js
index 3e94e03dc..59f609ebc 100644
--- a/modules/discojuice/www/discojuice/discojuice.control.js
+++ b/modules/discojuice/www/discojuice/discojuice.control.js
@@ -14,8 +14,13 @@ DiscoJuice.Control = {
 
 	// Reference to the UI object...
 	"ui": null,	
+	
+	// entity data.
 	"data": null,
 	
+	"quickEntry": null,
+	"subsetEnabled": null,
+	
 	// Set filter values to filter the result.
 	"filters": {},
 	
@@ -26,7 +31,7 @@ DiscoJuice.Control = {
 	
 	"extensionResponse": null,
 	
-	"quickEntry": null,
+
 
 	// Waiter Notification Callback Registry
 	"wncr": [],
@@ -50,6 +55,8 @@ DiscoJuice.Control = {
 		if (this.data) return;
 		this.data = [];
 		
+		this.subsetEnabled = this.parent.Utils.options.get('subsetEnabled', null);
+		
 		var metadataurl = this.parent.Utils.options.get('metadata');
 		var metadataurls = [];
 		var parameters = {};
@@ -129,19 +136,23 @@ DiscoJuice.Control = {
 			that.filterCountrySetup();
 		}
 
-		that.getCountry(); // Syncronous
+
 		that.readCookie(); // Syncronous
 		that.readExtensionResponse(); // Reading response set by the Browser extension
 
 		that.parent.Utils.log('Setting up postLoad() waiter');
+
 		waiter = DiscoJuice.Utils.waiter(function() {
 			that.prepareData();
 			that.searchboxSetup();
 			that.parent.Utils.log('postLoad() waiter EXECUTE');
-		}, 10000);
+		}, 2000);
 		
+		waiter.allowMultiple = true;
+				
 		that.discoReadSetup(waiter);
 		that.discoSubReadSetup(waiter);
+		that.getCountry(waiter);
 		
 		waiter.startTimer();
 		
@@ -240,6 +251,17 @@ DiscoJuice.Control = {
 		this.parent.Utils.log('DiscoJuice setWeight failer (no entries found for) ' + entityID + ' # ' + subID);
 	},
 	
+	"discoResponseError": function (cid, error) {
+		this.parent.Utils.log('DiscoResponse ERROR Received cid=' + cid);
+		if (cid) {
+			this.runCallback(cid);
+		}
+		
+		if (error) {
+			this.ui.error(error);
+		}
+	},
+	
 	"discoResponse": function(sender, entityID, subID, cid) {
 		this.parent.Utils.log('DiscoResponse Received from [' + sender  + '] entityID: ' + entityID + ' subID: ' + subID);
 		
@@ -255,7 +277,6 @@ DiscoJuice.Control = {
 		}
 		
 		this.setWeight(-100, entityID, subID);
-		this.prepareData();
 		
 		if (cid) {
 			this.runCallback(cid);			
@@ -266,7 +287,7 @@ DiscoJuice.Control = {
 		
 	},
 	
-	"calculateDistance": function() {
+	"calculateDistance": function(update) {
 		var targets, distances;
 		for(var i = 0; i < this.data.length; i++) {
 			if (this.data[i].geo) {
@@ -314,7 +335,7 @@ DiscoJuice.Control = {
 // 			}
 // 		}
 		this.showdistance = true;
-		this.prepareData();
+		if (update) this.prepareData();
 	},
 	
 	"locateMe": function() {
@@ -337,7 +358,7 @@ DiscoJuice.Control = {
 					that.ui.setLocationText('You are here: ' + position.coords.latitude + ', ' + position.coords.longitude + '. Nearby providers shown on top.');
 					
 					that.location = [position.coords.latitude, position.coords.longitude];
-					that.calculateDistance();
+					that.calculateDistance(true);
 					
 				}, 
 				// next function is the error callback
@@ -371,6 +392,20 @@ DiscoJuice.Control = {
 		
 	},
 	
+	"isEnabled": function (item) {
+		
+		var relID = item.entityID;
+		if (item.subID) {
+			relID += '#' + item.subID;
+		}
+		
+		if (this.subsetEnabled === null) return true;		
+		if (this.subsetEnabled[relID]) return true;
+		if (this.subsetEnabled[item.entityID]) return true;
+
+		return false;
+	},
+	
 	"prepareData": function(showall) {
 	
 		var showall = (showall ? true : false);
@@ -476,7 +511,10 @@ DiscoJuice.Control = {
 				}
 			}
 			
-			this.ui.addItem(current, countrydef, search, current.distance, quickSel);
+			var enabled = this.isEnabled(current);
+			
+			
+			this.ui.addItem(current, countrydef, search, current.distance, quickSel, enabled);
 
 			if (quickSel) {
 				this.quickEntry = current;
@@ -497,8 +535,28 @@ DiscoJuice.Control = {
 	
 		// console.log('entityid: '  + entityID);
 	
+	
 		var callback;
 		var that = this;
+		var entity = null;
+		
+		callback = this.parent.Utils.options.get('callback');	
+		
+		for(i = 0; i < this.data.length; i++) {
+			if (this.data[i].entityID == entityID) {
+				if (!subID || subID == this.data[i].subID) {
+					entity = this.data[i];
+				}
+			}
+		}
+		
+		if (entity.auth && entity.auth === 'local') {
+			console.log('local');
+			callback(entity, that);
+			return;
+		}
+		
+		
 		var mustwait = that.discoWrite(entityID, subID);
 		
 		if (this.parent.Utils.options.get('cookie', false)) {
@@ -509,29 +567,22 @@ DiscoJuice.Control = {
 			this.parent.Utils.createCookie(relID);
 		}
 
-		var entity = null;
-		for(i = 0; i < this.data.length; i++) {
-			if (this.data[i].entityID == entityID) {
-				if (!subID || subID == this.data[i].subID) {
-					entity = this.data[i];
-				}
-			}
-		}
 
-// 		console.log('Entity Selected');
-// 		console.log(entity);
+
+		console.log('Entity Selected');
+		console.log(entity);
 // 		return;
 
-		callback = this.parent.Utils.options.get('callback');	
+
 		if (callback) {
 			if (mustwait) {
 				$.doTimeout(1000, function(){
-					callback(entity);
+					callback(entity, that);
 					// alert('done');
 				});
 				
 			} else {
-				callback(entity);
+				callback(entity, that);
 			}
 			return;
 		}
@@ -540,6 +591,7 @@ DiscoJuice.Control = {
 	
 	// Setup an iframe to read discovery cookies from other domains
 	"discoReadSetup": function(waiter) {
+		var that = this;
 		var settings = this.parent.Utils.options.get('disco');
 		
 		if (!settings) return;
@@ -559,14 +611,14 @@ DiscoJuice.Control = {
 			
 			waiter.runAction(function (notifyCompleted) {
 			
-				callbackid = this.registerCallback(notifyCompleted);
-				returnurlwithparams = returnurl + 'cid=' + callbackid;
+				callbackid = that.registerCallback(notifyCompleted);
+				returnurlwithparams = returnurl + '?cid=' + callbackid;
 				
 				currentStore = stores[i];
-				this.parent.Utils.log('Setting up DisoJuice Read from Store [' + currentStore + ']');
+				that.parent.Utils.log('Setting up DisoJuice Read from Store [' + currentStore + ']');
 				iframeurl = currentStore + '?entityID=' + escape(spentityid) + '&isPassive=true&returnIDParam=entityID&return=' + escape(returnurlwithparams);
 				html = '<iframe src="' + iframeurl + '" style="display: none"></iframe>';
-				this.ui.addContent(html);
+				that.ui.addContent(html);
 				
 			});
 
@@ -576,6 +628,7 @@ DiscoJuice.Control = {
 	// Setup an iframe to read discovery cookies from other domains
 	"discoSubReadSetup": function(waiter) {
 		var settings = this.parent.Utils.options.get('disco');
+		var that = this;
 		
 		if (!settings) return;
 	
@@ -593,16 +646,16 @@ DiscoJuice.Control = {
 			
 			waiter.runAction(function (notifyCompleted) {
 			
-				callbackid = this.registerCallback(notifyCompleted);
-				returnurl = settings.url + 'entityID=' + escape(idp) + '&callbackid=' + callbackid;
+				callbackid = that.registerCallback(notifyCompleted);
+				returnurl = settings.url + '?entityID=' + escape(idp) + '&cid=' + callbackid;
 				
 				currentStore = stores[idp];
-				this.parent.Utils.log('Setting up SubID DisoJuice Read from Store [' + idp + '] =>  [' + currentStore + ']');
+				that.parent.Utils.log('Setting up SubID DisoJuice Read from Store [' + idp + '] =>  [' + currentStore + ']');
 				iframeurl = currentStore + '?entityID=' + escape(spentityid) + '&isPassive=true&returnIDParam=subID&return=' + escape(returnurl);
-				this.parent.Utils.log('iFrame URL is  [' + iframeurl + ']');
-				this.parent.Utils.log('return URL is  [' + returnurl + ']');
+				that.parent.Utils.log('iFrame URL is  [' + iframeurl + ']');
+				that.parent.Utils.log('return URL is  [' + returnurl + ']');
 				html = '<iframe src="' + iframeurl + '" style="display: none"></iframe>';
-				this.ui.addContent(html);
+				that.ui.addContent(html);
 			});
 		}
 	},
@@ -619,10 +672,13 @@ DiscoJuice.Control = {
 		var spentityid = settings.spentityid;
 		var writableStore = settings.writableStore;
 		
+		this.parent.Utils.log('DiscoJuice.Control discoWrite()');
+		
 		if (subID) {
-			
+			this.parent.Utils.log('DiscoJuice.Control discoWrite(...)');			
 			if (settings.subIDwritableStores && settings.subIDwritableStores[entityID]) {
 			
+				this.parent.Utils.log('DiscoJuice.Control discoWrite(...)');			
 				writableStore = settings.subIDwritableStores[entityID];
 				
 				this.parent.Utils.log('DiscoJuice.Control discoWrite(' + entityID + ') with SubID [' + subID + ']');
@@ -643,8 +699,12 @@ DiscoJuice.Control = {
 		
 		this.parent.Utils.log('DiscoJuice.Control discoWrite(' + entityID + ') to ' + writableStore);
 			
-		iframeurl = writableStore + '?entityID=' + escape(spentityid) + '&IdPentityID=' + 
+		// iframeurl = writableStore + '?entityID=' + escape(spentityid) + '&IdPentityID=' + 
+		// 	escape(entityID) + '&isPassive=true&returnIDParam=bogus&return=' + escape(returnurl);
+
+		iframeurl = writableStore + '&entityID=' + escape(spentityid) + '&origin=' + 
 			escape(entityID) + '&isPassive=true&returnIDParam=bogus&return=' + escape(returnurl);
+
 			
 		this.parent.Utils.log('DiscoJuice.Control discoWrite iframeURL (' + iframeurl + ') ');
 			
@@ -764,7 +824,7 @@ DiscoJuice.Control = {
 		}
 		
 		for (key in this.parent.Constants.Countries) {
-			console.log('Considering: ' + this.parent.Constants.Countries[key]);
+			//console.log('Considering: ' + this.parent.Constants.Countries[key]);
 			if (key === choice) {
 				ftext += '<option value="' + key + '" selected="selected">' + this.parent.Constants.Countries[key] + '</option>';
 			} else if (validCountry[key]) {
@@ -798,23 +858,25 @@ DiscoJuice.Control = {
 		});
 		
 	},
-	"setCountry": function(country) {
+	"setCountry": function(country, update) {
 		if (this.parent.Constants.Countries[country]) {
 			this.ui.popup.find('select.discojuice_filterCountrySelect').val(country);
-			this.prepareData();		
+			if (update) {
+				this.prepareData();
+			}
+
 		}
 	},
-	"setPosition": function(lat, lon) {
+	"setPosition": function(lat, lon, update) {
 		this.location = [lat, lon];
-		this.calculateDistance();
+		this.calculateDistance(update);
 	},
-	"getCountry": function() {
+	"getCountry": function(waiter) {
 		// If countryAPI is set, then lookup by IP.
 		var countryapi = this.parent.Utils.options.get('countryAPI', false);
-		var that = this,
-			waiter;
+		var that = this;
 		
-
+		console.log('country api : ' + countryapi);
 		
 		if (countryapi) {
 			
@@ -822,52 +884,43 @@ DiscoJuice.Control = {
 			var geocachelat = parseFloat(this.parent.Utils.readCookie('GeoLat'));
 			var geocachelon = parseFloat(this.parent.Utils.readCookie('GeoLon'));
 		
-			if (countrycache && false) {
+			if (countrycache) {
 				
-				this.setCountry(countrycache);
+				this.setCountry(countrycache, false);
 				this.parent.Utils.log('DiscoJuice getCountry() : Found country in cache: ' + countrycache);
 				
 				if (geocachelat && geocachelon) {
-					this.setPosition(geocachelat, geocachelon);
+					this.setPosition(geocachelat, geocachelon, false);
 				}
 				
 			} else {
 				
-				waiter = DiscoJuice.Utils.waiter(function (my) {
-					
-					if (!my.data) return;
-					if (my.data.status == 'ok' && my.data.country) {
-						
-						that.parent.Utils.createCookie(my.data.country, 'Country2');
-						that.setCountry(my.data.country);
-						that.parent.Utils.log('DiscoJuice getCountry() : Country lookup succeeded: ' + my.data.country);
-
-						if (my.data.geo && my.data.geo.lat && my.data.geo.lon) {
-							that.setPosition(my.data.geo.lat, my.data.geo.lon);
-							that.parent.Utils.createCookie(my.data.geo.lat, 'GeoLat');
-							that.parent.Utils.createCookie(my.data.geo.lon, 'GeoLon');
-						} 
-
-					} else {
-						that.parent.Utils.log('DiscoJuice getCountry() : Country lookup failed: ' + (my.data.error || ''));
-						that.ui.error("Error looking up users localization by country: " + (my.data.error || ''));
-					}
-					
-				}, 1000);
-				
 				waiter.runAction( 	
 					function (notifyCompleted) {
 						$.getJSON(countryapi, function(data) {
-							waiter.data = data;
+							if (data && data.status == 'ok' && data.country) {
+
+								that.parent.Utils.createCookie(data.country, 'Country2');
+								that.setCountry(data.country, false);
+								that.parent.Utils.log('DiscoJuice getCountry() : Country lookup succeeded: ' + data.country);
+
+								if (data.geo && data.geo.lat && data.geo.lon) {
+									that.setPosition(data.geo.lat, data.geo.lon, false);
+									that.parent.Utils.createCookie(data.geo.lat, 'GeoLat');
+									that.parent.Utils.createCookie(data.geo.lon, 'GeoLon');
+								} 
+
+							} else if (data && data.error){
+								that.parent.Utils.log('DiscoJuice getCountry() : Country lookup failed: ' + (data.error || ''));
+								that.ui.error("Error looking up users localization by country: " + (data.error || ''));
+							} else {
+								that.parent.Utils.log('DiscoJuice getCountry() : Country lookup failed');
+								that.ui.error("Error looking up users localization by country.");
+							}
 							notifyCompleted();
 						});
-					},
-					function() {
-						that.ui.error("Error looking up country. Showing all countries. [1] Timeout.");
 					}
 				);
-				waiter.startTimer();
-
 
 			}
 		}
diff --git a/modules/discojuice/www/discojuice/discojuice.misc.js b/modules/discojuice/www/discojuice/discojuice.misc.js
index 7707b482e..55e430e0e 100644
--- a/modules/discojuice/www/discojuice/discojuice.misc.js
+++ b/modules/discojuice/www/discojuice/discojuice.misc.js
@@ -29,6 +29,7 @@ DiscoJuice.Constants = {
 		'HR': 'Croatia',
 		'IE': 'Ireland',
 		'IT': 'Italy',
+		'IS': 'Iceland',
 		'JP': 'Japan',
 		'HU': 'Hungary',
 		'LU': 'Luxembourg',
@@ -55,6 +56,7 @@ DiscoJuice.Constants = {
 		'HR': 'hr.png',
 		'IE': 'ie.png',
 		'IT': 'it.png',
+		'IS': 'is.png',
 		'JP': 'jp.png',
 		'HU': 'hu.png',
 		'LU': 'lu.png',
@@ -206,8 +208,13 @@ DiscoJuice.Utils = {
 					}
 				}
 				if (executed) {
-					console.log('All actions completed. Too late for executing...');
-					tooLate();
+					if (my.allowMultiple) {
+						console.log('Slow response; but executing anyway!!');
+						execute();
+					} else if (typeof tooLate === 'function') {
+						console.log('All actions completed. Too late for executing...');
+						tooLate();
+					}
 					return;
 				}
 				console.log('All actions completed. Executing!');
@@ -229,7 +236,8 @@ DiscoJuice.Utils = {
 			}, waitSeconds);
 			
 		}
-		
+
+		my.allowMultiple = false;
 
 		my.startTimer = startTimer;
 		my.runAction = runAction;
diff --git a/modules/discojuice/www/discojuice/discojuice.ui.js b/modules/discojuice/www/discojuice/discojuice.ui.js
index d8ca8cc8b..85ef385dc 100644
--- a/modules/discojuice/www/discojuice/discojuice.ui.js
+++ b/modules/discojuice/www/discojuice/discojuice.ui.js
@@ -43,11 +43,9 @@ DiscoJuice.UI = {
 		this.resulthtml = '';
 	},
 	
-	// addItem(item, description, {country, flag}, keywordmatch, distance)	 		
-	// addItem(current, current.descr || null, countrydef, search, current.distance);
-	"addItem": function(item, countrydef, search, distance, quickentry) {
+	"addItem": function(item, countrydef, search, distance, quickentry, enabled) {
 		var textLink = '';
-		var classes = '';
+		var classes = (enabled ? 'enabled' : 'disabled');
 //		if (item.weight < -50) classes += 'hothit';
 
 		var iconpath = this.parent.Utils.options.get('discoPath', '') + 'logos/';
@@ -58,7 +56,7 @@ DiscoJuice.UI = {
 		
 		
 		// Add icon element first
-		if (item.icon) {
+		if (item.icon && this.parent.Utils.options.get('showIcon', true)) {
 			textLink += '<img class="logo" src="' + iconpath + item.icon + '" />';
 			clear = true;
 		}
@@ -80,7 +78,10 @@ DiscoJuice.UI = {
 		
 		
 
-		if (countrydef || (distance != undefined)) {
+		if (
+				(countrydef || (distance != undefined))
+				&& this.parent.Utils.options.get('showLocationInfo', true)
+			) {
 				
 			textLink += '<span class="location">';
 			if (countrydef) {
@@ -140,6 +141,10 @@ DiscoJuice.UI = {
 			relID += '#' + item.subID;
 		}
 		
+		
+
+		
+		
 		// Wrap in A element
 		textLink = '<a href="" class="' + classes + '" rel="' + escape(relID) + '" title="' + escape(item.title) + '">' + 
 			textLink + '</a>';
@@ -147,6 +152,28 @@ DiscoJuice.UI = {
 
 		this.resulthtml += textLink;
 	},
+	
+	
+	"setScreen": function (content) {
+		$("div.discojuice_listContent").hide();
+		$("div#locatemediv").hide();
+		$("div#search").hide();
+		$("div.filters p.discojuice_filter_country").hide();
+		
+		$("div#discojuice_page div.discojuice_content").html(content);		
+		
+		$("div#discojuice_page").show();
+		$("div#discojuice_page_return").show();
+		
+		console.log($("div#discojuice_page"));
+		
+	},
+	
+	"returnToProviderList": function () {
+		$("div.discojuice_listContent").show();
+		$("div#discojuice_page").hide();
+		$("div#discojuice_page_return").hide();
+	},
 		
 	"refreshData": function(showmore, show, listcount) {
 		var that = this;
@@ -158,7 +185,8 @@ DiscoJuice.UI = {
 			var overthere = that;	// Overthere is a reference to the UI object
 			$(this).click(function(event) {
 				event.preventDefault();
-				overthere.hide();
+				event.stopPropagation();
+				//overthere.hide();
 							
 				// The "rel" attribute is containing: 'entityid#subid'
 				// THe following code, decodes that.
@@ -219,6 +247,17 @@ DiscoJuice.UI = {
 				'</div>' +
 				'<p class="discojuice_moreLinkContainer" style="margin: 0px; padding: 4px">&nbsp;</p>' +
 			'</div>' +
+			
+			'<div id="discojuice_page" style="display: none"  class="" >' +
+				'<div class="discojuice_content" style="">' + 
+				'</div>' +
+			'</div>' +
+			
+			'<div id="discojuice_page_return" style="display: none"  class="" >' +
+				'<div class="" style="">' + 
+				'<input id="discojuice_returntoproviderlist" type="submit" value="« Return to list of providers" />' +
+				'</div>' +
+			'</div>' +
 	
 			'<div id="search" class="" >' +
 				'<p><input type="search" class="discojuice_search" results=5 autosave="discojuice" name="searchfield" placeholder="' + textSearch + '" value="" /></p>' +
@@ -250,7 +289,9 @@ DiscoJuice.UI = {
 			'</div>' +
 			
 			'<div class="filters bottom">' +
+//				'<p style="margin 0px; color: #ccc; font-size: 75%; float: left">Settings</p>' +
 				'<p style="margin 0px; text-align: right; color: #ccc; font-size: 75%">DiscoJuice &copy; UNINETT</p>' +
+
 			'</div>' +
 	
 
@@ -281,6 +322,11 @@ DiscoJuice.UI = {
 			that.control.discojuiceextension();
 		});
 
+		this.popup.find("#discojuice_page_return input").click(function(e) {
+			e.preventDefault();
+			that.returnToProviderList();
+		});
+
 		// Add listeners to the close button.
 		this.popup.find(".discojuice_close").click(function() {
 			that.hide();
diff --git a/modules/discojuice/www/discojuice/discojuiceDiscoveryResponse.html b/modules/discojuice/www/discojuice/discojuiceDiscoveryResponse.html
index ff0cc03c6..af4d54162 100644
--- a/modules/discojuice/www/discojuice/discojuiceDiscoveryResponse.html
+++ b/modules/discojuice/www/discojuice/discojuiceDiscoveryResponse.html
@@ -15,8 +15,8 @@ function parseURL(url) {
 }
 
 function receive() {
-	
-	var urlParams = {};
+	var urlParams = {},
+		cid = null;
 	(function () {
 		var e,
 			a = /\+/g,  // Regex for replacing addition symbol with a space
@@ -28,14 +28,20 @@ function receive() {
 		   urlParams[d(e[1])] = d(e[2]);
 	})();
 	
+	if (urlParams.cid) cid = urlParams.cid;
+		
 	var sender = parseURL(document.referrer);
 	if (urlParams.entityID) {
 		window.parent.DiscoJuice.Utils.log('ResponseLocation: Response from discovery service [' + sender + ']: ' + urlParams.entityID + '   subID: ' + urlParams.subID);
-		window.parent.DiscoJuice.Control.discoResponse(sender, urlParams.entityID, urlParams.subID);
-	} else if urlParams.error) {
-		window.parent.DiscoJuice.Control.ui.error("Error from IdP Discovery Service: " + urlParams.error);
+		
+		window.parent.DiscoJuice.Control.discoResponse(sender, urlParams.entityID, urlParams.subID, cid);
+
+	} else if (urlParams['error']) {
+		window.parent.DiscoJuice.Control.discoResponseError(cid, 
+			"Error from IdP Discovery Service [" + sender + "]:  " + urlParams.error);			
 	} else {
-		window.parent.DiscoJuice.Utils.log('ResponseLocation: Response from discovery service [' + sender + ']: No valid response parameters');
+		window.parent.DiscoJuice.Control.discoResponseError(cid, 
+			"ResponseLocation: Response from discovery service [" + sender + "]: No valid response parameters");
 	}
 
 }
-- 
GitLab