Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
inc-md-js/info/js/all-entity-categories.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
231 lines (200 sloc)
7.39 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* InCommon Federation Service Categories. | |
* | |
* Displays an alphabetized list of SPs belonging to one or more | |
* categories, along with the IdPs that support these categories. | |
* Each entity link in the list requests an entity info page. | |
*/ | |
// helps prevent a "flash of unstyled content" | |
$('html').addClass('js'); | |
$(document).ready(function () { | |
"use strict"; | |
$('#page-content').hide().ajaxStop( | |
function () { $(this).show(); } | |
); | |
$("#loading").ajaxStart(function () { | |
// the image is 31x31 pixels | |
var x = Math.round((document.body.clientWidth - 31) / 2); | |
$(this).css('left', x); | |
$(this).show(); | |
}).ajaxStop(function () { $(this).hide(); }); | |
// initialize tabs | |
var tabIndexIdP = 0, tabIndexSP = 1; | |
var myTabs = $('#tabs').tabs(); | |
// set the hash in the address bar every time a tab is selected | |
myTabs.bind('tabsselect', function (event, ui) { | |
window.location.hash = "#" + ui.panel.id; | |
}); | |
// determine initial state of tabbed interface | |
var showIdPsTab, showSPsTab; | |
var hash = window.location.hash; | |
if (hash != null) { | |
if ( /^#IdPs/.test(hash) ) { | |
showIdPsTab = true; showSPsTab = false; | |
} else if ( /^#SPs/.test(hash) ) { | |
showIdPsTab = false; showSPsTab = true; | |
} else { | |
showIdPsTab = true; showSPsTab = false; | |
//window.location.hash = "#IdPs"; | |
} | |
} else { | |
showIdPsTab = true; showSPsTab = false; | |
//window.location.hash = "#IdPs"; | |
} | |
// compute a unique id selector based on the category value URI | |
// and an optional color value | |
// Note: the hex_color parameter is unused | |
var getIDSelector = function (category_val, hex_color) { | |
if (typeof hex_color === 'undefined') { | |
return '_' + Crypto.MD5(category_val); | |
} else { | |
return '_' + Crypto.MD5(category_val + hex_color); | |
} | |
} | |
// add a row to the category summary table | |
// Note: the bg_color parameter is unused | |
var insertNewSummaryRow = function (category_val, bg_color) { | |
// the tail of the category value URI | |
var category_val_tail = utils.getBasenameFromURL(category_val); | |
// an id selector for this row | |
var id_selector = getIDSelector(category_val, bg_color); | |
var table_cell = $('<td/>') | |
.html( | |
$('<span/>') | |
.append( | |
$('<a/>').attr({ | |
'href': category_val | |
}).text(category_val_tail) | |
).addClass('space-right') | |
) | |
// This is a hack. This code sets a background color of the | |
// second column for certain entity category values, namely, | |
// the R&S entity attribute values. A better way to do this | |
// is to use styles but I can't get it to work. | |
// | |
// Even worse, this hack is replicated in entity-list-builder.js | |
if (category_val === 'http://refeds.org/category/research-and-scholarship') { | |
//table_cell.css('background-color', '#90EE90'); // LightGreen | |
table_cell.css('background-color', '#98FB98'); // PaleGreen | |
} else if (category_val === 'http://id.incommon.org/category/research-and-scholarship') { | |
//table_cell.css('background-color', '#FFB6C1'); // LightPink | |
table_cell.css('background-color', '#FFF0F5'); // LavenderBlush | |
} | |
$('<tr/>') | |
.attr('id', id_selector) | |
.append(table_cell) | |
.append( | |
$('<td/>') | |
.attr('id', id_selector + '-sps') | |
.css('text-align', 'center') | |
.text('0') | |
).append( | |
$('<td/>') | |
.attr('id', id_selector + '-idps') | |
.css('text-align', 'center') | |
.text('0') | |
).appendTo('#list-of-categories'); | |
if (typeof bg_color !== 'undefined') { | |
table_cell.css('background-color', bg_color) | |
} | |
}; | |
var attr_name_ec = "http://macedir.org/entity-category"; | |
var attr_name_ec_support = "http://macedir.org/entity-category-support"; | |
// init list of IdPs that either belong to a category or support a category of SPs | |
(function (showThisTab) { | |
// handle successful ajax call for all IdP metadata | |
var handleDone = function (entities) { | |
var id_selector = '#list-of-idps'; | |
var num_idps, category_val, row_id_selector; | |
// insert a list of IdPs that belong to at least one category into the DOM | |
num_idps = $.insertEntitiesIntoDOM(entities, id_selector, attr_name_ec); | |
// update the summary table with the # of IdPs that belong to each category | |
for (category_val in num_idps) { | |
// the id selector for this row | |
row_id_selector = getIDSelector(category_val); | |
// if there is no corresponding row in the table, add one | |
if ( $('#' + row_id_selector).length == 0 ) { | |
// insert a new row into the summary table | |
insertNewSummaryRow(category_val); | |
} | |
// update the corresponding row in the summary table | |
$('#' + row_id_selector + '-idps').text(num_idps[category_val]) | |
} | |
// insert a list of IdPs that support at least one category into the DOM | |
num_idps = $.insertEntitiesIntoDOM(entities, id_selector, attr_name_ec_support); | |
// update the summary table with the # of IdPs that support each category | |
for (category_val in num_idps) { | |
// the id selector for this row | |
row_id_selector = getIDSelector(category_val); | |
// if there is no corresponding row in the table, add one | |
if ( $('#' + row_id_selector).length == 0 ) { | |
// insert a new row into the summary table | |
insertNewSummaryRow(category_val); | |
} | |
// update the corresponding row in the summary table | |
$('#' + row_id_selector + '-idps').text(num_idps[category_val]) | |
} | |
// initialize column sorting | |
$(id_selector).tablesorter({ | |
// initial sort on the first column, order ascending | |
sortList: [ [0, 0] ], | |
// disable sorting on the second column (since only one category) | |
//headers: { | |
// 1: { sorter: false } | |
//} | |
}); | |
if (showThisTab) { | |
myTabs.tabs('select', tabIndexIdP); | |
$('#page-content').show(); | |
} | |
}; | |
// handle failed ajax call for all IdP metadata | |
var handleFail = function () { | |
$.displayErrorMsg("Unable to retrieve IdP metadata"); | |
}; | |
$.getJSONMetadata4AllIdPs(handleDone, handleFail); | |
}(showIdPsTab)); | |
// init list of SPs that belong to at least one category | |
(function (showThisTab) { | |
// handle successful ajax call for all SP metadata | |
var handleDone = function (entities) { | |
var id_selector = '#list-of-sps'; | |
var num_sps, category_val, row_id_selector; | |
// insert a list of categorized SPs into the DOM | |
num_sps = $.insertEntitiesIntoDOM(entities, id_selector, attr_name_ec); | |
// update the summary table with the # of SPs that belong to each category | |
for (category_val in num_sps) { | |
// the id selector for this row | |
row_id_selector = getIDSelector(category_val); | |
// if there is no corresponding row in the table, add one | |
if ( $('#' + row_id_selector).length == 0 ) { | |
// insert a new row into the summary table | |
insertNewSummaryRow(category_val); | |
} | |
// update the corresponding row in the summary table | |
$('#' + row_id_selector + '-sps').text(num_sps[category_val]) | |
} | |
// initialize column sorting | |
$(id_selector).tablesorter({ | |
// initial sort on the first column, order ascending | |
sortList: [ [0, 0] ], | |
// disable sorting on the second column (since only one category) | |
//headers: { | |
// 1: { sorter: false } | |
//} | |
}); | |
if (showThisTab) { | |
myTabs.tabs('select', tabIndexSP); | |
$('#page-content').show(); | |
} | |
}; | |
// handle failed ajax call for all SP metadata | |
var handleFail = function () { | |
$.displayErrorMsg("Unable to retrieve SP metadata"); | |
}; | |
$.getJSONMetadata4AllSPs(handleDone, handleFail); | |
}(showSPsTab)); | |
// handle clicked entity links | |
var dialogOptions = null; // unused | |
myTabs.handleClickedEntityLinks(dialogOptions); | |
}); |