|
/**********************/ |
|
function removeMySiteLink(username) { |
|
var webAbsoluteUrl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl; |
|
var art = null; |
|
var migratedDate = ""; |
|
//IE |
|
if (window.ActiveXObject) { |
|
art = new ActiveXObject("Microsoft.XMLHTTP"); |
|
}//Mozilla, chrome, etc., |
|
else if (window.XMLHttpRequest) { |
|
art = new XMLHttpRequest(); |
|
} |
|
else { |
|
throw new Error("XMLHttpRequest not supported"); |
|
} |
|
|
|
if (art == null) return null; |
|
console.log(_spPageContextInfo.webAbsoluteUrl); |
|
art.open("POST", webAbsoluteUrl + "/_vti_bin/userprofileservice.asmx", false); |
|
art.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); |
|
art.setRequestHeader("SOAPAction", "http://microsoft.com/webservices/SharePointPortalServer/UserProfileService/GetUserProfileByName"); |
|
var xsoap = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://schemas.microsoft.com/sharepoint/soap/\"><soap:Body><GetUserProfileByName xmlns=\"http://microsoft.com/webservices/SharePointPortalServer/UserProfileService\"><AccountName>"+username+"</AccountName></GetUserProfileByName></soap:Body></soap:Envelope>"; |
|
console.log('may need try catch'); |
|
|
|
|
|
try { |
|
art.send(xsoap); |
|
console.log('may need try catch...'); |
|
|
|
var xmlDoc = art.responseXML; |
|
|
|
var elmValue = xmlDoc.getElementsByTagName("Value"); |
|
for (i = 0; i < elmValue.length; i++) { |
|
|
|
if (elmValue[i].parentNode.parentNode.parentNode.childNodes[2].textContent == 'uob-migrated') { |
|
migratedDate = elmValue[i].childNodes[0].nodeValue; |
|
} |
|
} |
|
|
|
console.log(migratedDate); |
|
} catch(ex) { |
|
migratedDate = null; |
|
} |
|
|
|
|
|
//ID_MySiteMenu |
|
if (migratedDate.length > 0) { |
|
var numDaysToRetain = 30; |
|
var dateMigratedmillisecs = new Date(migratedDate).getTime() + (numDaysToRetain * 24 * 60 * 60 * 1000); |
|
var timestamp = new Date().getTime(); |
|
if (timestamp > dateMigratedmillisecs) { |
|
|
|
//these are relevant for mysite.brighton.ac.uk |
|
$('#zz7_MySiteTopNavigationMenu div ul li.static:nth-child(1)').remove(); |
|
$('#ID_MySiteMenu').remove(); |
|
$('.ms-globalnavicon').remove(); |
|
|
|
//this applies to staff and mydepartment as we as mysite |
|
jQuery('#ID_MySiteMenu').remove(); |
|
} |
|
else { |
|
console.log('keep mysite for now'); |
|
} |
|
|
|
} |
|
} |
|
console.log('in custom UoB Javascript'); |
|
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js"); |
|
|
|
var context = null; |
|
var web = null; |
|
var currentUser = null; |
|
function getWebUserData() { |
|
context = new SP.ClientContext.get_current(); |
|
web = context.get_web(); |
|
currentUser = web.get_currentUser(); |
|
currentUser.retrieve(); |
|
context.load(web); |
|
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod)); |
|
} |
|
function onSuccessMethod(sender, args) { |
|
var userObject = web.get_currentUser(); |
|
console.log('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName()); |
|
//no we dont actually need to escape the slasshes userObject.get_loginName().replace('\', '\\'); |
|
//unecessary escapedLoginName = userObject.get_loginName().replace(/\\/g, "\\\\") |
|
//console.log('escapedLoginName:' + escapedLoginName); |
|
//removeMySiteLink(escapedLoginName); |
|
|
|
//this works |
|
removeMySiteLink(userObject.get_loginName()); |
|
} |
|
function onFailureMethod(sender, args) { |
|
console.log('request failed ' + args.get_message() + '\n' + args.get_stackTrace()); |
|
} |
|
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "sp.js"); |