Last active
April 6, 2016 13:13
-
-
Save beckettkev/392e35f0dd1cfb4f9f138fe4cceb7efe to your computer and use it in GitHub Desktop.
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
(function (userProfiles, $) { | |
userProfiles.Constants = { | |
EndPoint: '/_api/SP.UserProfiles.PeopleManager/GetMyProperties', | |
Cache: { | |
Key: 'ProfileProperties' | |
} | |
}; | |
//You've seen this already, move on... | |
userProfiles.Current = { | |
... | |
}; | |
//Helper function fetches the profile properties and stores them in the local storage cache (callback is invoked after this process) | |
userProfiles.GetCurrent = function (callback) { | |
MyCompany.StorageCache.GetLocalStorageItemCacheForKey( | |
userProfiles.Constants.Cache.Key, | |
_spPageContextInfo.webAbsoluteUrl + userProfiles.Constants.EndPoint, | |
false | |
).then( | |
function (properties) { | |
if (typeof properties.error === 'undefined') { | |
var collection = typeof properties.results === 'undefined' ? properties.d : properties.results; | |
[ | |
{ Name: 'Account', Property: 'AccountName' }, | |
{ Name: 'FullName', Property: 'PreferredName' }, | |
{ Name: 'OfficeLocation', Property: 'OfficeLocation' }, | |
{ Name: 'Region', Property: 'Region' }, | |
{ Name: 'Country', Property: 'Country' }, | |
{ Name: 'Global', Property: 'Global' }, | |
{ Name: 'Campaign', Property: 'Campaign' }, | |
{ Name: 'Group', Property: 'Group' }, | |
{ Name: 'Business', Property: 'Business' }, | |
{ Name: 'Country', Property: 'CountryName' } | |
].map(function(item, i) { | |
updateProperty(item.Name, getPropertyByKey(collection, item.Property, 'Key', '')); | |
}); | |
callback(); | |
} else { | |
//Hold head in hands | |
} | |
}); | |
}; | |
})(MyCompany.UserProfiles = MyCompany.UserProfiles || {}, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment