[js-embedded-discovery] 03/04: EDS-73 Auto-follow cookie. Set the cookie
Rod Widdowson
rdw at steadingsoftware.com
Sat Mar 5 07:40:01 EST 2016
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository js-embedded-discovery.
commit 464484b6eda8d5b4f920d58673168d6272473afc
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Mar 5 12:14:28 2016 +0000
EDS-73 Auto-follow cookie. Set the cookie
https://issues.shibboleth.net/jira/browse/EDS-73
Add code to manage the "Auto Follow" cookie. On clicking one of the radio
buttons the "auto-follow" cookie is immediately set or cleared.
The number of buttons is configurable (but the config changes have to be reflected in the languages)
All text is Globalized and messages put in for US-EN.
New CSS for the selector.
---
src/javascript/idpselect.js | 81 ++++++++++++++++++++++++++++++++++-
src/javascript/idpselect_config.js | 1 +
src/javascript/idpselect_languages.js | 7 ++-
src/resources/idpselect.css | 8 ++++
4 files changed, 95 insertions(+), 2 deletions(-)
diff --git a/src/javascript/idpselect.js b/src/javascript/idpselect.js
index 670faff..db2f827 100644
--- a/src/javascript/idpselect.js
+++ b/src/javascript/idpselect.js
@@ -38,6 +38,9 @@ function IdPSelectUI() {
var noWriteCookie;
var ignoreURLParams;
+ var autoFollowCookie;
+ var autoFollowCookieTTLs;
+
//
// The cookie contents
//
@@ -82,7 +85,7 @@ function IdPSelectUI() {
//
// Quick test for auto-dispatch
//
- if ((null != parms.autoFollowCookie) && (null != getCookieCalled( parms.autoFollowCookie ))) {
+ if ((null != autoFollowCookie) && (null != getCookieCalled( autoFollowCookie ))) {
var prefs = retrieveUserSelectedIdPs();
if (prefs.length != 0) {
@@ -183,6 +186,9 @@ function IdPSelectUI() {
maxIdPCharsDropDown = paramsSupplied.maxIdPCharsDropDown;
maxIdPCharsAltTxt = paramsSupplied.maxIdPCharsAltTxt;
+ autoFollowCookie = paramsSupplied.autoFollowCookie;
+ autoFollowCookieTTLs = paramsSupplied.autoFollowCookieTTLs;
+
var lang;
if (typeof navigator == 'undefined') {
@@ -628,6 +634,7 @@ function IdPSelectUI() {
Builds the IdP selection UI.
Three divs. PreferredIdPTime, EntryTile and DropdownTile
+ Optional div AutoDispatchPane
@return {Element} IdP selector UI
*/
@@ -637,6 +644,9 @@ function IdPSelectUI() {
preferredTileExists = buildPreferredIdPTile(containerDiv);
buildIdPEntryTile(containerDiv, preferredTileExists);
buildIdPDropDownListTile(containerDiv, preferredTileExists);
+ if (null != autoFollowCookie) {
+ buildAutoDispatchPane(containerDiv);
+ }
return containerDiv;
};
@@ -963,6 +973,54 @@ function IdPSelectUI() {
parentDiv.appendChild(idpListDiv);
};
+ var buildAutoDispatchPane = function(parent) {
+ var inputName = 'IdPSelectAutoDisp'
+
+ autoDispatchTile = buildDiv(undefined, 'autoDispatchArea');
+
+ autoDispatchTile.appendChild(document.createTextNode(getLocalizedMessage('autoFollow.message')));
+ //
+ // The "clear" button
+ //
+ var but = document.createElement('input');
+ but.setAttribute('type', 'radio');
+ but.setAttribute('checked', '');
+ but.setAttribute('name', inputName);
+ but.onclick = function () {
+ setAutoDispatchCookie(0);
+ }
+
+ div = buildDiv(undefined, 'autoDispatchTile');
+ div.appendChild(but);
+ div.appendChild(document.createTextNode(getLocalizedMessage('autoFollow.never')));
+ autoDispatchTile.appendChild(div);
+
+ var i;
+ for (i = 0; i < autoFollowCookieTTLs.length; i++) {
+ //
+ // The timed buttons
+ //
+ but = document.createElement('input');
+ but.setAttribute('type', 'radio');
+ but.setAttribute('checked', '');
+ but.setAttribute('name', inputName);
+
+ but.life = autoFollowCookieTTLs[i];
+ but.onclick = function () {
+ var f = this.life;
+ setAutoDispatchCookie(f);
+ }
+
+ div = buildDiv(undefined, 'autoDispatchTile');
+ div.appendChild(but);
+ div.appendChild(document.createTextNode(
+ getLocalizedMessage('autoFollow.time'+i)));
+ autoDispatchTile.appendChild(div);
+ }
+
+ parent.appendChild(autoDispatchTile);
+ }
+
/**
Builds the 'continue' button used to submit the IdP selection.
@@ -1273,6 +1331,26 @@ function IdPSelectUI() {
return;
};
+ /*
+ Set the autoFollowCookie with a life of the specified number of days
+ or clear it.
+
+ @parm (integer) days The cookie lifetime if >0. If <=0 clear cookie
+
+ */
+
+ var setAutoDispatchCookie = function(days) {
+ var expireDate;
+ if(days > 0){
+ var now = new Date();
+ cookieTTL = days * 24 * 60 * 60 * 1000;
+ expireDate = new Date(now.getTime() + cookieTTL);
+ } else {
+ expireDate = new Date(0);
+ }
+ document.cookie=autoFollowCookie + '=1;path=/;expires=' + expireDate.toUTCString();
+ }
+
/**
Gets the value of the cookie with the provided name
@@ -1281,6 +1359,7 @@ function IdPSelectUI() {
*/
var getCookieCalled = function (name) {
+
var i, j;
var cookies;
diff --git a/src/javascript/idpselect_config.js b/src/javascript/idpselect_config.js
index faba043..90ac048 100644
--- a/src/javascript/idpselect_config.js
+++ b/src/javascript/idpselect_config.js
@@ -30,6 +30,7 @@ function IdPSelectUIParms(){
this.testGUI = false;
this.autoFollowCookie = null; // If you want auto-dispatch, set this to the cookie name to use
+ this.autoFollowCookieTTLs = [ 1, 60, 270 ]; // Cookie life (in days). Changing this requires changes to idp_select_languages
//
// Language support.
diff --git a/src/javascript/idpselect_languages.js b/src/javascript/idpselect_languages.js
index c27afd6..51360f0 100644
--- a/src/javascript/idpselect_languages.js
+++ b/src/javascript/idpselect_languages.js
@@ -25,7 +25,12 @@ function IdPSelectLanguages(){
'idpList.showSearch' : 'Allow me to specify the site',
'submitButton.label': 'Continue',
'helpText': 'Help',
- 'defaultLogoAlt' : 'DefaultLogo'
+ 'defaultLogoAlt' : 'DefaultLogo',
+ 'autoFollow.message' : 'Always follows this selection',
+ 'autoFollow.never' : 'Never',
+ 'autoFollow.time0' : 'One day',
+ 'autoFollow.time1' : '3 months',
+ 'autoFollow.time2' : '9 months'
},
'de': {
'fatal.divMissing': 'Das notwendige Div Element fehlt',
diff --git a/src/resources/idpselect.css b/src/resources/idpselect.css
index 91809fd..9b480b4 100644
--- a/src/resources/idpselect.css
+++ b/src/resources/idpselect.css
@@ -64,6 +64,14 @@ img.IdPSelectIdPImg {
width:auto;
}
+div.IdPSelectautoDispatchTile {
+ display: block;
+}
+
+div.IdPSelectautoDispatchArea {
+ margin-top: 30px ;
+}
+
div.IdPSelectPreferredIdPButton img
{
display: block; /* Block display to allow auto centring */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list