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-entities-mdq-beta.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
376 lines (323 sloc)
11.6 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
/** | |
* Displays an alphabetized list of global entity display names. | |
* Each display name is linked to the metadata for that entity. | |
*/ | |
// helps prevent a "flash of unstyled content" | |
$('html').addClass('js'); | |
$(document).ready(function () { | |
"use strict"; | |
// there has to be a better way to get the base_url | |
var base_url = 'http://mdq-beta.incommon.org/global'; | |
var my_prompt = "(enter entityID above)"; | |
$("#mdq-request-url").text(my_prompt); | |
// the base_url is outside the scope of this function | |
$('#any-entityid').bind('textchange', function (event, previousText) { | |
// it's probably not a good idea to embed the base_url in the page text | |
var idp_entityid = $('#any-entityid').val(); | |
if (idp_entityid == "") { | |
$("#mdq-request-url").text(my_prompt); | |
} else { | |
var url = base_url; | |
url += '/entities/'; | |
url += encodeURIComponent(idp_entityid); | |
$("#mdq-request-url").html( | |
$('<a/>').attr('href', url).text(url) | |
); | |
} | |
}); | |
$('#any-entityid-reset').bind('click', function () { | |
$('#any-entityid').val(''); | |
$("#mdq-request-url").text(my_prompt); | |
}); | |
$('#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"; | |
} | |
// initial state of search form | |
$('#form-container').hide(); | |
$('#search-link').text("show search"); | |
// an onclick handler for the search link | |
$('#search-link').unbind('click'); | |
$('#search-link').bind('click', function () { | |
if ($('#search-link').text() == "hide search") { | |
$('#search-link').text("show search"); | |
$('#form-container').hide(); | |
} else { | |
$('#search-link').text("hide search"); | |
$('#form-container').show(); | |
} | |
// prevent the browser from following the link | |
return false; | |
}); | |
// an associative array of registrars indexed by registrarID | |
// registrars[registrarID].num_entities | |
// registrars[registrarID].num_idp_roles | |
// registrars[registrarID].num_sp_roles | |
// registrars[registrarID].num_other_roles | |
// registrars[registrarID].registrar_class | |
var registrars = new Object; // singular? | |
// an onclick handler for the checkboxes | |
var registrar_id_selector = '#list-of-registrars'; | |
var refresh_entity_lists = function () { | |
// grand totals | |
var total_num_idp_roles = 0; | |
var total_num_sp_roles = 0; | |
var total_num_other_roles = 0; | |
$('table.list-of-entities').hide(); | |
// iterate over the checkboxes | |
$(registrar_id_selector).find('input.registrar-checkbox[type=checkbox]').each(function () { | |
var registrarID, registrar_class; | |
// the value of this checkbox is the registrar ID | |
registrarID = this.value; | |
// get the class for this registrar | |
registrar_class = registrars[registrarID].registrar_class; | |
if (this.checked) { | |
$('tr.' + registrar_class).show(); | |
// update the grand totals | |
total_num_idp_roles += registrars[registrarID].num_idp_roles; | |
total_num_sp_roles += registrars[registrarID].num_sp_roles; | |
total_num_other_roles += registrars[registrarID].num_other_roles; | |
} else { | |
$('tr.' + registrar_class).hide(); | |
} | |
}); | |
// set the text in each tab | |
$('li#idps-tab > a').text('IdPs (' + total_num_idp_roles + ')'); | |
$('li#sps-tab > a').text('SPs (' + total_num_sp_roles + ')'); | |
$('li#other-tab > a').text('Other (' + total_num_other_roles + ')'); | |
$('table.list-of-entities').show(); | |
} | |
// handle successful ajax call for all global entity metadata | |
var handleDone = function (entities) { | |
var i; | |
var entity, entityID, registrarID, registrar_class; | |
// grand totals | |
var total_num_entities = 0; | |
var total_num_idp_roles = 0; | |
var total_num_sp_roles = 0; | |
var total_num_other_roles = 0; | |
var add_entity_to_list; | |
var hasOtherRole; | |
// selectors | |
var idp_id_selector = '#list-of-idps'; | |
var sp_id_selector = '#list-of-sps'; | |
var other_id_selector = '#list-of-other-entities'; | |
var total_entities_id_selector = '#total-num-entities'; | |
var total_idps_id_selector = '#total-num-idp-roles'; | |
var total_sps_id_selector = '#total-num-sp-roles'; | |
var total_other_id_selector = '#total-num-other-roles'; | |
var master_checkbox_id_selector = '#master-checkbox'; | |
// dynamically build various entity lists, and at the same time, | |
// track information about each registrar | |
for (i = 0; i < entities.length; i += 1) { | |
entity = new ProtocolEntity(entities[i]); | |
// the required fields of each entity | |
entityID = entity.getEntityID(); | |
registrarID = entity.getRegistrarID(); | |
// create a new registrar object if necessary | |
if (typeof registrars[registrarID] === 'undefined') { | |
registrars[registrarID] = new Object; | |
registrars[registrarID].num_entities = 0; | |
registrars[registrarID].num_idp_roles = 0; | |
registrars[registrarID].num_sp_roles = 0; | |
registrars[registrarID].num_other_roles = 0; | |
registrars[registrarID].registrar_class = '_' + Crypto.MD5(registrarID); | |
} | |
registrars[registrarID].num_entities += 1; | |
registrar_class = registrars[registrarID].registrar_class; | |
// the entityID, registrarID, and registrar_class are outside the scope of this function | |
add_entity_to_list = function (displayName, selector) { | |
var first_col, second_col; | |
// compute the link according to Metadata Query Protocol | |
// (the base_url is outside the scope of this function) | |
first_col = $('<span/>').html( | |
$('<a/>').attr({ | |
'href': base_url + '/entities/' + encodeURIComponent(entityID) | |
}).text(displayName) | |
).addClass('space-right'); | |
// compute the registrar ID | |
second_col = $('<span/>').text( | |
registrarID | |
).addClass('space-right'); | |
// add a new row to the desired element, either a table or a tbody | |
$('<tr/>') | |
.append($('<td/>').html(first_col)) | |
.append($('<td/>').html(second_col)) | |
.addClass(registrar_class) | |
.appendTo(selector); | |
} | |
// If the entity is an IdP, add the entity to the list of IdPs | |
// registered by this registrar. Likewise, if the entity is an SP, | |
// add the entity to the list of SPs registered by this registrar. | |
// If neither of these conditions is true, add the entity to the | |
// list of "Other" entities registered by this registrar. | |
// | |
// Note that a given entity may appear on both the IdP list and the SP | |
// list. Also note that every entity appears on at least one list. | |
// | |
hasOtherRole = true; // assume entity is neither IdP nor SP | |
if (entity.isIdP()) { | |
hasOtherRole = false; | |
registrars[registrarID].num_idp_roles += 1; | |
// add this entity to the list of entities with an IdP role | |
add_entity_to_list(entity.getIdPDisplayName(), idp_id_selector); | |
} | |
if (entity.isSP()) { | |
hasOtherRole = false; | |
registrars[registrarID].num_sp_roles += 1; | |
// add this entity to the list of entities with an SP role | |
add_entity_to_list(entity.getSPDisplayName(), sp_id_selector); | |
} | |
if (hasOtherRole) { | |
registrars[registrarID].num_other_roles += 1; | |
// add this entity to the list of entities with an "other" role | |
add_entity_to_list(entityID, other_id_selector); | |
} | |
} | |
// build the registrar table | |
for (registrarID in registrars) { | |
// add a new row to the registrar summary table | |
$('<tr/>') | |
.append( | |
$('<td/>').html( | |
$('<input/>') | |
.addClass('registrar-checkbox') | |
.attr({ | |
'type': 'checkbox', | |
'name': 'registrar', | |
'value': registrarID | |
}) | |
) | |
) | |
.append( | |
$('<td/>').html( | |
$('<span/>').text(registrarID) | |
) | |
) | |
.append( | |
$('<td/>').text( | |
registrars[registrarID].num_entities | |
).addClass('number-body') | |
) | |
.append( | |
$('<td/>').text( | |
registrars[registrarID].num_idp_roles | |
).addClass('number-body') | |
) | |
.append( | |
$('<td/>').text( | |
registrars[registrarID].num_sp_roles | |
).addClass('number-body') | |
) | |
.append( | |
$('<td/>').text( | |
registrars[registrarID].num_other_roles | |
).addClass('number-body') | |
) | |
.appendTo(registrar_id_selector); | |
// update the grand totals | |
total_num_entities += registrars[registrarID].num_entities; | |
total_num_idp_roles += registrars[registrarID].num_idp_roles; | |
total_num_sp_roles += registrars[registrarID].num_sp_roles; | |
total_num_other_roles += registrars[registrarID].num_other_roles; | |
} | |
// set the footer content in the registrars table | |
$(total_entities_id_selector).text(total_num_entities); | |
$(total_idps_id_selector).text(total_num_idp_roles); | |
$(total_sps_id_selector).text(total_num_sp_roles); | |
$(total_other_id_selector).text(total_num_other_roles); | |
// initialize the table of registrars | |
$(registrar_id_selector).tablesorter({ | |
// initial sort on the third column, order descending | |
sortList: [ [1, 0] ], | |
headers: { | |
0: { sorter: false, parser: false } | |
} | |
}); | |
// initially check all the checkboxes | |
$(registrar_id_selector).find('input[type=checkbox]').each(function () { | |
this.checked = true; | |
}); | |
// checkbox event handlers must be bound AFTER tablesorter is initialized | |
$(master_checkbox_id_selector).on('click', function () { | |
$(this).closest('fieldset').find(':checkbox').prop('checked', this.checked); | |
refresh_entity_lists(); | |
}); | |
$('.registrar-checkbox').on('click', function () { | |
refresh_entity_lists(); | |
if ($('.registrar-checkbox:checked').length === 0) { | |
$(master_checkbox_id_selector). | |
prop("indeterminate", false). | |
prop('checked', false); | |
} else if ($('.registrar-checkbox:not(:checked)').length === 0) { | |
$(master_checkbox_id_selector). | |
prop("indeterminate", false). | |
prop('checked', true); | |
} else { | |
$(master_checkbox_id_selector). | |
prop("indeterminate", true); | |
} | |
}); | |
// initialize tabs | |
$('li#idps-tab > a').text('IdPs (' + total_num_idp_roles + ')'); | |
$('li#sps-tab > a').text('SPs (' + total_num_sp_roles + ')'); | |
$('li#other-tab > a').text('Other (' + total_num_other_roles + ')'); | |
// initialize the table of IdPs | |
$(idp_id_selector).tablesorter({ | |
// initial sort on the first column, order ascending | |
sortList: [ [1, 0], [0, 0] ], | |
sortStable: true | |
}); | |
// initialize the table of SPs | |
$(sp_id_selector).tablesorter({ | |
// initial sort on the first column, order ascending | |
sortList: [ [1, 0], [0, 0] ], | |
sortStable: true | |
}); | |
// initialize the table of other entities | |
$(other_id_selector).tablesorter({ | |
// initial sort on the first column, order ascending | |
sortList: [ [1, 0], [0, 0] ], | |
sortStable: true | |
}); | |
if (showIdPsTab) { | |
myTabs.tabs('select', tabIndexIdP); | |
} else if (showSPsTab) { | |
myTabs.tabs('select', tabIndexSP); | |
} | |
$('#page-content').show(); | |
}; | |
// handle failed ajax call for all global entity metadata | |
var handleFail = function () { | |
$.displayErrorMsg("Unable to retrieve all global entity metadata"); | |
}; | |
$.getJSONMetadata4AllGlobalEntities(handleDone, handleFail); | |
}); |